Files
protocol/lib/generated-artifacts/FullMigration.json
T
Michael Zhu dd132c611c gitpkg
2021-03-16 10:53:37 -07:00

634 lines
774 KiB
JSON

{
"schemaVersion": "2.0.0",
"contractName": "FullMigration",
"compilerOutput": {
"abi": [
{
"inputs": [
{
"internalType": "address payable",
"name": "initializeCaller_",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "ethRecipient",
"type": "address"
}
],
"name": "die",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getBootstrapper",
"outputs": [
{
"internalType": "address",
"name": "bootstrapper",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "initializeCaller",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "owner",
"type": "address"
},
{
"internalType": "contract ZeroEx",
"name": "zeroEx",
"type": "address"
},
{
"components": [
{
"internalType": "contract SimpleFunctionRegistryFeature",
"name": "registry",
"type": "address"
},
{
"internalType": "contract OwnableFeature",
"name": "ownable",
"type": "address"
},
{
"internalType": "contract TokenSpenderFeature",
"name": "tokenSpender",
"type": "address"
},
{
"internalType": "contract TransformERC20Feature",
"name": "transformERC20",
"type": "address"
},
{
"internalType": "contract MetaTransactionsFeature",
"name": "metaTransactions",
"type": "address"
},
{
"internalType": "contract NativeOrdersFeature",
"name": "nativeOrders",
"type": "address"
}
],
"internalType": "struct FullMigration.Features",
"name": "features",
"type": "tuple"
},
{
"components": [
{
"internalType": "address",
"name": "transformerDeployer",
"type": "address"
}
],
"internalType": "struct FullMigration.MigrateOpts",
"name": "migrateOpts",
"type": "tuple"
}
],
"name": "migrateZeroEx",
"outputs": [
{
"internalType": "contract ZeroEx",
"name": "_zeroEx",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"devdoc": {
"details": "A contract for deploying and configuring the full ZeroEx contract.",
"kind": "dev",
"methods": {
"constructor": {
"details": "Instantiate this contract and set the allowed caller of `initializeZeroEx()` to `initializeCaller`.",
"params": {
"initializeCaller_": "The allowed caller of `initializeZeroEx()`."
}
},
"die(address)": {
"details": "Destroy this contract. Only callable from ourselves (from `initializeZeroEx()`).",
"params": {
"ethRecipient": "Receiver of any ETH in this contract."
}
},
"getBootstrapper()": {
"details": "Retrieve the bootstrapper address to use when constructing `ZeroEx`.",
"returns": {
"bootstrapper": "The bootstrapper address."
}
},
"migrateZeroEx(address,address,(address,address,address,address,address,address),(address))": {
"details": "Initialize the `ZeroEx` contract with the full feature set, transfer ownership to `owner`, then self-destruct.",
"params": {
"features": "Features to add to the proxy.",
"migrateOpts": "Parameters needed to initialize features.",
"owner": "The owner of the contract.",
"zeroEx": "The instance of the ZeroEx contract. ZeroEx should been constructed with this contract as the bootstrapper."
},
"returns": {
"_zeroEx": "The configured ZeroEx contract. Same as the `zeroEx` parameter."
}
}
},
"stateVariables": {
"_initialMigration": {
"details": "The initial migration contract."
},
"initializeCaller": {
"details": "The allowed caller of `initializeZeroEx()`."
}
},
"version": 1
},
"evm": {
"bytecode": {
"linkReferences": {},
"object": "0x60a060405234801561001057600080fd5b5060405161251a38038061251a83398101604081905261002f916100a9565b6001600160601b0319606082901b16608052604051309061004f9061009c565b61005991906100d7565b604051809103906000f080158015610075573d6000803e3d6000fd5b50600080546001600160a01b0319166001600160a01b0392909216919091179055506100eb565b610afa80611a2083390190565b6000602082840312156100ba578081fd5b81516001600160a01b03811681146100d0578182fd5b9392505050565b6001600160a01b0391909116815260200190565b60805160601c61191461010c6000398060b952806102ea52506119146000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063329798a4146100515780635f136a4a1461007a578063b3d3173514610082578063c9353cb51461008a575b600080fd5b61006461005f366004610906565b61009f565b6040516100719190610a14565b60405180910390f35b6100646102e8565b61006461030c565b61009d6100983660046108e3565b610328565b005b60003373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610119576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161011090610b0d565b60405180910390fd5b600054604080518082018252855173ffffffffffffffffffffffffffffffffffffffff908116825260208088015182169083015291517fa23ce6ce000000000000000000000000000000000000000000000000000000008152919092169163a23ce6ce9161018e913091899190600401610a35565b602060405180830381600087803b1580156101a857600080fd5b505af11580156101bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e091906109f8565b506101ed8486858561037a565b6040517ff2fde38b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063f2fde38b9061023f908890600401610a14565b600060405180830381600087803b15801561025957600080fd5b505af115801561026d573d6000803e3d6000fd5b50506040517fc9353cb500000000000000000000000000000000000000000000000000000000815230925063c9353cb591506102ad908890600401610a14565b600060405180830381600087803b1580156102c757600080fd5b505af11580156102db573d6000803e3d6000fd5b5095979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b333014610361576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161011090610b0d565b8073ffffffffffffffffffffffffffffffffffffffff16ff5b604051849060009061038b90610895565b604051809103906000f0801580156103a7573d6000803e3d6000fd5b506040517f42f1181e00000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff8216906342f1181e906103fd908990600401610a14565b600060405180830381600087803b15801561041757600080fd5b505af115801561042b573d6000803e3d6000fd5b50506040517ff2fde38b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416925063f2fde38b9150610481908890600401610a14565b600060405180830381600087803b15801561049b57600080fd5b505af11580156104af573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663261fe679856040015163ce5494bb60e01b846040516024016104ed9190610a14565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009485161790525160e085901b909216825261058092913090600401610a74565b600060405180830381600087803b15801561059a57600080fd5b505af11580156105ae573d6000803e3d6000fd5b5050506060850151845160405173ffffffffffffffffffffffffffffffffffffffff8616945063261fe67993507fce5494bb000000000000000000000000000000000000000000000000000000009161060991602401610a14565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009485161790525160e085901b909216825261069c92913090600401610a74565b600060405180830381600087803b1580156106b657600080fd5b505af11580156106ca573d6000803e3d6000fd5b50505060808401516040805160048082526024820183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f8fd3ab800000000000000000000000000000000000000000000000000000000017905291517f261fe67900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616945063261fe6799361077c93909291309101610a74565b600060405180830381600087803b15801561079657600080fd5b505af11580156107aa573d6000803e3d6000fd5b50505060a08401516040805160048082526024820183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f8fd3ab800000000000000000000000000000000000000000000000000000000017905291517f261fe67900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616945063261fe6799361085c93909291309101610a74565b600060405180830381600087803b15801561087657600080fd5b505af115801561088a573d6000803e3d6000fd5b505050505050505050565b610d4e80610b9183390190565b80356108ad81610b6b565b92915050565b6000602082840312156108c4578081fd5b6108ce6020610b44565b905081356108db81610b6b565b815292915050565b6000602082840312156108f4578081fd5b81356108ff81610b6b565b9392505050565b60008060008084860361012081121561091d578384fd5b853561092881610b6b565b9450602086013561093881610b6b565b935060c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082011215610969578283fd5b5061097460c0610b44565b61098187604088016108a2565b815261099087606088016108a2565b60208201526109a287608088016108a2565b60408201526109b48760a088016108a2565b60608201526109c68760c088016108a2565b60808201526109d88760e088016108a2565b60a082015291506109ed8661010087016108b3565b905092959194509250565b600060208284031215610a09578081fd5b81516108ff81610b6b565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff93841681529183166020808401919091528151841660408401520151909116606082015260800190565b600073ffffffffffffffffffffffffffffffffffffffff808616835260206060818501528551806060860152835b81811015610abe57878101830151868201608001528201610aa2565b81811115610acf5784608083880101525b509490911660408401525050601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160160800192915050565b6020808252601c908201527f46756c6c4d6967726174696f6e2f494e56414c49445f53454e44455200000000604082015260600190565b60405181810167ffffffffffffffff81118282101715610b6357600080fd5b604052919050565b73ffffffffffffffffffffffffffffffffffffffff81168114610b8d57600080fd5b5056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610d1c806100326000396000f3fe608060405234801561001057600080fd5b50600436106100a35760003560e01c80639ad2674411610076578063bca8c7b51161005b578063bca8c7b514610134578063d39de6e914610154578063f2fde38b14610169576100a3565b80639ad2674414610101578063b918161114610114576100a3565b806342f1181e146100a8578063494503d4146100bd57806370712939146100e65780638da5cb5b146100f9575b600080fd5b6100bb6100b6366004610aa2565b61017c565b005b6100d06100cb366004610b70565b610190565b6040516100dd9190610b98565b60405180910390f35b6100bb6100f4366004610aa2565b6101c4565b6100d061027e565b6100bb61010f366004610b45565b61029a565b610127610122366004610aa2565b6102ac565b6040516100dd9190610c3a565b610147610142366004610ac5565b6102c1565b6040516100dd9190610c45565b61015c610351565b6040516100dd9190610be0565b6100bb610177366004610aa2565b6103c0565b610184610463565b61018d816104ac565b50565b6002818154811061019d57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b6101cc610463565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1661020a5761020a610205826105dd565b61067c565b60005b60025481101561027a578173ffffffffffffffffffffffffffffffffffffffff166002828154811061023b57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614156102725761026d8282610684565b61027a565b60010161020d565b5050565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b6102a2610463565b61027a8282610684565b60016020526000908152604090205460ff1681565b60606102cb6108ff565b60008473ffffffffffffffffffffffffffffffffffffffff1684846040516102f4929190610b88565b6000604051808303816000865af19150503d8060008114610331576040519150601f19603f3d011682016040523d82523d6000602084013e610336565b606091505b509250905080610349576103498261067c565b509392505050565b606060028054806020026020016040519081016040528092919081815260200182805480156103b657602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff16815260019091019060200180831161038b575b5050505050905090565b6103c8610463565b73ffffffffffffffffffffffffffffffffffffffff81166103f3576103ee610205610922565b61018d565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b60005473ffffffffffffffffffffffffffffffffffffffff1633146104aa576000546104aa9061020590339073ffffffffffffffffffffffffffffffffffffffff16610959565b565b73ffffffffffffffffffffffffffffffffffffffff81166104d2576104d26102056109fb565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff161561050c5761050c61020582610a32565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b606063eb5108a260e01b826040516024016105f89190610b98565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b805160208201fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff166106bd576106bd610205836105dd565b60025481106106d8576106d861020582600280549050610a4d565b8173ffffffffffffffffffffffffffffffffffffffff16600282815481106106fc57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161461075e5761075e6102056002838154811061073657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1684610a6a565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081106107d957fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff909216918390811061080c57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600280548061085f57fe5b60008281526020812082017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90810180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055909101909155604051339173ffffffffffffffffffffffffffffffffffffffff8516917f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b09190a35050565b3360009081526001602052604090205460ff166104aa576104aa61020533610a87565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b6060631de45ad160e01b8383604051602401610976929190610bb9565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b60408051808201909152600481527f57654fe400000000000000000000000000000000000000000000000000000000602082015290565b606063de16f1a060e01b826040516024016105f89190610b98565b606063e9f8377160e01b8383604051602401610976929190610cb6565b606063140a84db60e01b8383604051602401610976929190610bb9565b606063b65a25b960e01b826040516024016105f89190610b98565b600060208284031215610ab3578081fd5b8135610abe81610cc4565b9392505050565b600080600060408486031215610ad9578182fd5b8335610ae481610cc4565b9250602084013567ffffffffffffffff80821115610b00578384fd5b818601915086601f830112610b13578384fd5b813581811115610b21578485fd5b876020828501011115610b32578485fd5b6020830194508093505050509250925092565b60008060408385031215610b57578182fd5b8235610b6281610cc4565b946020939093013593505050565b600060208284031215610b81578081fd5b5035919050565b6000828483379101908152919050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b6020808252825182820181905260009190848201906040850190845b81811015610c2e57835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101610bfc565b50909695505050505050565b901515815260200190565b6000602080835283518082850152825b81811015610c7157858101830151858201604001528201610c55565b81811115610c825783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b918252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff8116811461018d57600080fdfea2646970667358221220c65c269172307c3233f41d02063dd36016fa933e6b4e9ff0e9ffda27b61fa40764736f6c634300060c0033a2646970667358221220f9dc6d46f6aa9a201db4e1e18a137c2c97b0d7b410f290806e865db52083e17664736f6c634300060c003360c060405234801561001057600080fd5b50604051610afa380380610afa83398101604081905261002f9161004c565b6001600160601b0319606091821b1660805230901b60a05261007a565b60006020828403121561005d578081fd5b81516001600160a01b0381168114610073578182fd5b9392505050565b60805160601c60a05160601c610a526100a8600039806104cf5250806102aa52806102e65250610a526000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806308cf7934146100515780635f136a4a1461007a578063a23ce6ce1461008f578063c9353cb5146100a2575b600080fd5b61006461005f3660046107c6565b6100b7565b604051610071919061091f565b60405180910390f35b6100826102a8565b6040516100719190610857565b61008261009d36600461077f565b6102cc565b6100b56100b036600461075c565b6104b7565b005b80516040805160048152602481019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167ffb969b0a0000000000000000000000000000000000000000000000000000000017905260009161011c9161053f565b60208083015160408051600481526024810190915291820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167ffb969b0a000000000000000000000000000000000000000000000000000000001790526101819161053f565b6040517f9db64a400000000000000000000000000000000000000000000000000000000081523090639db64a40906101e0907f0ee8be1b000000000000000000000000000000000000000000000000000000009060009060040161094c565b600060405180830381600087803b1580156101fa57600080fd5b505af115801561020e573d6000803e3d6000fd5b50506040517ff2fde38b00000000000000000000000000000000000000000000000000000000815230925063f2fde38b915061024e908690600401610857565b600060405180830381600087803b15801561026857600080fd5b505af115801561027c573d6000803e3d6000fd5b507fd150751b000000000000000000000000000000000000000000000000000000009695505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60003373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610346576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033d90610994565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166373f208d5306308cf793460e01b878660405160240161037e929190610878565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009485161790525160e085901b909216825261040f92916004016108b1565b600060405180830381600087803b15801561042957600080fd5b505af115801561043d573d6000803e3d6000fd5b50506040517fc9353cb500000000000000000000000000000000000000000000000000000000815230925063c9353cb5915061047d908790600401610857565b600060405180830381600087803b15801561049757600080fd5b505af11580156104ab573d6000803e3d6000fd5b50949695505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610526576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033d90610994565b8073ffffffffffffffffffffffffffffffffffffffff16ff5b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051610568919061083b565b600060405180830381855af49150503d80600081146105a3576040519150601f19603f3d011682016040523d82523d6000602084013e6105a8565b606091505b50915091508115806105bc57508051602014155b8061061e575080517fd150751b00000000000000000000000000000000000000000000000000000000906105f990830160209081019084016107fb565b7fffffffff000000000000000000000000000000000000000000000000000000001614155b1561063557610635610630858361063b565b6106f6565b50505050565b60607fd19d65df6830e3cb0da1e12b8e9738e2dc473f830d8af813bcc031eb5a1675d183836040516024016106719291906108b1565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b805160208201fd5b60006040828403121561070f578081fd5b6040516040810181811067ffffffffffffffff8211171561072e578283fd5b604052905080823561073f816109f7565b8152602083013561074f816109f7565b6020919091015292915050565b60006020828403121561076d578081fd5b8135610778816109f7565b9392505050565b600080600060808486031215610793578182fd5b833561079e816109f7565b925060208401356107ae816109f7565b91506107bd85604086016106fe565b90509250925092565b600080606083850312156107d8578182fd5b82356107e3816109f7565b91506107f284602085016106fe565b90509250929050565b60006020828403121561080c578081fd5b81517fffffffff0000000000000000000000000000000000000000000000000000000081168114610778578182fd5b6000825161084d8184602087016109cb565b9190910192915050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681528151831660208083019190915290910151909116604082015260600190565b600073ffffffffffffffffffffffffffffffffffffffff841682526040602083015282518060408401526108ec8160608501602087016109cb565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016060019392505050565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b7fffffffff0000000000000000000000000000000000000000000000000000000092909216825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b6020808252601f908201527f496e697469616c4d6967726174696f6e2f494e56414c49445f53454e44455200604082015260600190565b60005b838110156109e65781810151838201526020016109ce565b838111156106355750506000910152565b73ffffffffffffffffffffffffffffffffffffffff81168114610a1957600080fd5b5056fea2646970667358221220a16f740e3543e464fb7b9ec07ebb663ade6c4e8e73c8add2a24ea1b0d4d96f6664736f6c634300060c0033",
"opcodes": "PUSH1 0xA0 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x40 MLOAD PUSH2 0x251A CODESIZE SUB DUP1 PUSH2 0x251A DUP4 CODECOPY DUP2 ADD PUSH1 0x40 DUP2 SWAP1 MSTORE PUSH2 0x2F SWAP2 PUSH2 0xA9 JUMP JUMPDEST PUSH1 0x1 PUSH1 0x1 PUSH1 0x60 SHL SUB NOT PUSH1 0x60 DUP3 SWAP1 SHL AND PUSH1 0x80 MSTORE PUSH1 0x40 MLOAD ADDRESS SWAP1 PUSH2 0x4F SWAP1 PUSH2 0x9C JUMP JUMPDEST PUSH2 0x59 SWAP2 SWAP1 PUSH2 0xD7 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 PUSH1 0x0 CREATE DUP1 ISZERO DUP1 ISZERO PUSH2 0x75 JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP PUSH1 0x0 DUP1 SLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB NOT AND PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB SWAP3 SWAP1 SWAP3 AND SWAP2 SWAP1 SWAP2 OR SWAP1 SSTORE POP PUSH2 0xEB JUMP JUMPDEST PUSH2 0xAFA DUP1 PUSH2 0x1A20 DUP4 CODECOPY ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xBA JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 MLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB DUP2 AND DUP2 EQ PUSH2 0xD0 JUMPI DUP2 DUP3 REVERT JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH1 0x80 MLOAD PUSH1 0x60 SHR PUSH2 0x1914 PUSH2 0x10C PUSH1 0x0 CODECOPY DUP1 PUSH1 0xB9 MSTORE DUP1 PUSH2 0x2EA MSTORE POP PUSH2 0x1914 PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x4C JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x329798A4 EQ PUSH2 0x51 JUMPI DUP1 PUSH4 0x5F136A4A EQ PUSH2 0x7A JUMPI DUP1 PUSH4 0xB3D31735 EQ PUSH2 0x82 JUMPI DUP1 PUSH4 0xC9353CB5 EQ PUSH2 0x8A JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x64 PUSH2 0x5F CALLDATASIZE PUSH1 0x4 PUSH2 0x906 JUMP JUMPDEST PUSH2 0x9F JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x71 SWAP2 SWAP1 PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x64 PUSH2 0x2E8 JUMP JUMPDEST PUSH2 0x64 PUSH2 0x30C JUMP JUMPDEST PUSH2 0x9D PUSH2 0x98 CALLDATASIZE PUSH1 0x4 PUSH2 0x8E3 JUMP JUMPDEST PUSH2 0x328 JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH32 0x0 AND EQ PUSH2 0x119 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x110 SWAP1 PUSH2 0xB0D JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 REVERT JUMPDEST PUSH1 0x0 SLOAD PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD DUP3 MSTORE DUP6 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 DUP2 AND DUP3 MSTORE PUSH1 0x20 DUP1 DUP9 ADD MLOAD DUP3 AND SWAP1 DUP4 ADD MSTORE SWAP2 MLOAD PUSH32 0xA23CE6CE00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE SWAP2 SWAP1 SWAP3 AND SWAP2 PUSH4 0xA23CE6CE SWAP2 PUSH2 0x18E SWAP2 ADDRESS SWAP2 DUP10 SWAP2 SWAP1 PUSH1 0x4 ADD PUSH2 0xA35 JUMP JUMPDEST PUSH1 0x20 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x1A8 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x1BC JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP PUSH1 0x40 MLOAD RETURNDATASIZE PUSH1 0x1F NOT PUSH1 0x1F DUP3 ADD AND DUP3 ADD DUP1 PUSH1 0x40 MSTORE POP DUP2 ADD SWAP1 PUSH2 0x1E0 SWAP2 SWAP1 PUSH2 0x9F8 JUMP JUMPDEST POP PUSH2 0x1ED DUP5 DUP7 DUP6 DUP6 PUSH2 0x37A JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH32 0xF2FDE38B00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP6 AND SWAP1 PUSH4 0xF2FDE38B SWAP1 PUSH2 0x23F SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x259 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x26D JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xC9353CB500000000000000000000000000000000000000000000000000000000 DUP2 MSTORE ADDRESS SWAP3 POP PUSH4 0xC9353CB5 SWAP2 POP PUSH2 0x2AD SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x2C7 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x2DB JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP SWAP6 SWAP8 SWAP7 POP POP POP POP POP POP POP JUMP JUMPDEST PUSH32 0x0 DUP2 JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 JUMP JUMPDEST CALLER ADDRESS EQ PUSH2 0x361 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x110 SWAP1 PUSH2 0xB0D JUMP JUMPDEST DUP1 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SELFDESTRUCT JUMPDEST PUSH1 0x40 MLOAD DUP5 SWAP1 PUSH1 0x0 SWAP1 PUSH2 0x38B SWAP1 PUSH2 0x895 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 PUSH1 0x0 CREATE DUP1 ISZERO DUP1 ISZERO PUSH2 0x3A7 JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP PUSH1 0x40 MLOAD PUSH32 0x42F1181E00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE SWAP1 SWAP2 POP PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND SWAP1 PUSH4 0x42F1181E SWAP1 PUSH2 0x3FD SWAP1 DUP10 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x417 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x42B JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xF2FDE38B00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP5 AND SWAP3 POP PUSH4 0xF2FDE38B SWAP2 POP PUSH2 0x481 SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x49B JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x4AF JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH4 0x261FE679 DUP6 PUSH1 0x40 ADD MLOAD PUSH4 0xCE5494BB PUSH1 0xE0 SHL DUP5 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x4ED SWAP2 SWAP1 PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 DUP2 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP5 DUP6 AND OR SWAP1 MSTORE MLOAD PUSH1 0xE0 DUP6 SWAP1 SHL SWAP1 SWAP3 AND DUP3 MSTORE PUSH2 0x580 SWAP3 SWAP2 ADDRESS SWAP1 PUSH1 0x4 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x59A JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x5AE JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0x60 DUP6 ADD MLOAD DUP5 MLOAD PUSH1 0x40 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 POP PUSH32 0xCE5494BB00000000000000000000000000000000000000000000000000000000 SWAP2 PUSH2 0x609 SWAP2 PUSH1 0x24 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 DUP2 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP5 DUP6 AND OR SWAP1 MSTORE MLOAD PUSH1 0xE0 DUP6 SWAP1 SHL SWAP1 SWAP3 AND DUP3 MSTORE PUSH2 0x69C SWAP3 SWAP2 ADDRESS SWAP1 PUSH1 0x4 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x6B6 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x6CA JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0x80 DUP5 ADD MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP1 DUP3 MSTORE PUSH1 0x24 DUP3 ADD DUP4 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0x8FD3AB8000000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE SWAP2 MLOAD PUSH32 0x261FE67900000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 PUSH2 0x77C SWAP4 SWAP1 SWAP3 SWAP2 ADDRESS SWAP2 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x796 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x7AA JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0xA0 DUP5 ADD MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP1 DUP3 MSTORE PUSH1 0x24 DUP3 ADD DUP4 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0x8FD3AB8000000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE SWAP2 MLOAD PUSH32 0x261FE67900000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 PUSH2 0x85C SWAP4 SWAP1 SWAP3 SWAP2 ADDRESS SWAP2 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x876 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x88A JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP POP POP POP POP POP JUMP JUMPDEST PUSH2 0xD4E DUP1 PUSH2 0xB91 DUP4 CODECOPY ADD SWAP1 JUMP JUMPDEST DUP1 CALLDATALOAD PUSH2 0x8AD DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x8C4 JUMPI DUP1 DUP2 REVERT JUMPDEST PUSH2 0x8CE PUSH1 0x20 PUSH2 0xB44 JUMP JUMPDEST SWAP1 POP DUP2 CALLDATALOAD PUSH2 0x8DB DUP2 PUSH2 0xB6B JUMP JUMPDEST DUP2 MSTORE SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x8F4 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 CALLDATALOAD PUSH2 0x8FF DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 DUP1 DUP5 DUP7 SUB PUSH2 0x120 DUP2 SLT ISZERO PUSH2 0x91D JUMPI DUP4 DUP5 REVERT JUMPDEST DUP6 CALLDATALOAD PUSH2 0x928 DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP5 POP PUSH1 0x20 DUP7 ADD CALLDATALOAD PUSH2 0x938 DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP4 POP PUSH1 0xC0 PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 DUP3 ADD SLT ISZERO PUSH2 0x969 JUMPI DUP3 DUP4 REVERT JUMPDEST POP PUSH2 0x974 PUSH1 0xC0 PUSH2 0xB44 JUMP JUMPDEST PUSH2 0x981 DUP8 PUSH1 0x40 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST DUP2 MSTORE PUSH2 0x990 DUP8 PUSH1 0x60 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x20 DUP3 ADD MSTORE PUSH2 0x9A2 DUP8 PUSH1 0x80 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x40 DUP3 ADD MSTORE PUSH2 0x9B4 DUP8 PUSH1 0xA0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x60 DUP3 ADD MSTORE PUSH2 0x9C6 DUP8 PUSH1 0xC0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x80 DUP3 ADD MSTORE PUSH2 0x9D8 DUP8 PUSH1 0xE0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0xA0 DUP3 ADD MSTORE SWAP2 POP PUSH2 0x9ED DUP7 PUSH2 0x100 DUP8 ADD PUSH2 0x8B3 JUMP JUMPDEST SWAP1 POP SWAP3 SWAP6 SWAP2 SWAP5 POP SWAP3 POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xA09 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 MLOAD PUSH2 0x8FF DUP2 PUSH2 0xB6B JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP4 DUP5 AND DUP2 MSTORE SWAP2 DUP4 AND PUSH1 0x20 DUP1 DUP5 ADD SWAP2 SWAP1 SWAP2 MSTORE DUP2 MLOAD DUP5 AND PUSH1 0x40 DUP5 ADD MSTORE ADD MLOAD SWAP1 SWAP2 AND PUSH1 0x60 DUP3 ADD MSTORE PUSH1 0x80 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP1 DUP7 AND DUP4 MSTORE PUSH1 0x20 PUSH1 0x60 DUP2 DUP6 ADD MSTORE DUP6 MLOAD DUP1 PUSH1 0x60 DUP7 ADD MSTORE DUP4 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xABE JUMPI DUP8 DUP2 ADD DUP4 ADD MLOAD DUP7 DUP3 ADD PUSH1 0x80 ADD MSTORE DUP3 ADD PUSH2 0xAA2 JUMP JUMPDEST DUP2 DUP2 GT ISZERO PUSH2 0xACF JUMPI DUP5 PUSH1 0x80 DUP4 DUP9 ADD ADD MSTORE JUMPDEST POP SWAP5 SWAP1 SWAP2 AND PUSH1 0x40 DUP5 ADD MSTORE POP POP PUSH1 0x1F SWAP2 SWAP1 SWAP2 ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 AND ADD PUSH1 0x80 ADD SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x20 DUP1 DUP3 MSTORE PUSH1 0x1C SWAP1 DUP3 ADD MSTORE PUSH32 0x46756C6C4D6967726174696F6E2F494E56414C49445F53454E44455200000000 PUSH1 0x40 DUP3 ADD MSTORE PUSH1 0x60 ADD SWAP1 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP2 DUP2 ADD PUSH8 0xFFFFFFFFFFFFFFFF DUP2 GT DUP3 DUP3 LT OR ISZERO PUSH2 0xB63 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x40 MSTORE SWAP2 SWAP1 POP JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND DUP2 EQ PUSH2 0xB8D JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x0 DUP1 SLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB NOT AND CALLER OR SWAP1 SSTORE PUSH2 0xD1C DUP1 PUSH2 0x32 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0xA3 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x9AD26744 GT PUSH2 0x76 JUMPI DUP1 PUSH4 0xBCA8C7B5 GT PUSH2 0x5B JUMPI DUP1 PUSH4 0xBCA8C7B5 EQ PUSH2 0x134 JUMPI DUP1 PUSH4 0xD39DE6E9 EQ PUSH2 0x154 JUMPI DUP1 PUSH4 0xF2FDE38B EQ PUSH2 0x169 JUMPI PUSH2 0xA3 JUMP JUMPDEST DUP1 PUSH4 0x9AD26744 EQ PUSH2 0x101 JUMPI DUP1 PUSH4 0xB9181611 EQ PUSH2 0x114 JUMPI PUSH2 0xA3 JUMP JUMPDEST DUP1 PUSH4 0x42F1181E EQ PUSH2 0xA8 JUMPI DUP1 PUSH4 0x494503D4 EQ PUSH2 0xBD JUMPI DUP1 PUSH4 0x70712939 EQ PUSH2 0xE6 JUMPI DUP1 PUSH4 0x8DA5CB5B EQ PUSH2 0xF9 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0xBB PUSH2 0xB6 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x17C JUMP JUMPDEST STOP JUMPDEST PUSH2 0xD0 PUSH2 0xCB CALLDATASIZE PUSH1 0x4 PUSH2 0xB70 JUMP JUMPDEST PUSH2 0x190 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0xBB PUSH2 0xF4 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x1C4 JUMP JUMPDEST PUSH2 0xD0 PUSH2 0x27E JUMP JUMPDEST PUSH2 0xBB PUSH2 0x10F CALLDATASIZE PUSH1 0x4 PUSH2 0xB45 JUMP JUMPDEST PUSH2 0x29A JUMP JUMPDEST PUSH2 0x127 PUSH2 0x122 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x2AC JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xC3A JUMP JUMPDEST PUSH2 0x147 PUSH2 0x142 CALLDATASIZE PUSH1 0x4 PUSH2 0xAC5 JUMP JUMPDEST PUSH2 0x2C1 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xC45 JUMP JUMPDEST PUSH2 0x15C PUSH2 0x351 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xBE0 JUMP JUMPDEST PUSH2 0xBB PUSH2 0x177 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x3C0 JUMP JUMPDEST PUSH2 0x184 PUSH2 0x463 JUMP JUMPDEST PUSH2 0x18D DUP2 PUSH2 0x4AC JUMP JUMPDEST POP JUMP JUMPDEST PUSH1 0x2 DUP2 DUP2 SLOAD DUP2 LT PUSH2 0x19D JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 POP DUP2 JUMP JUMPDEST PUSH2 0x1CC PUSH2 0x463 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x20A JUMPI PUSH2 0x20A PUSH2 0x205 DUP3 PUSH2 0x5DD JUMP JUMPDEST PUSH2 0x67C JUMP JUMPDEST PUSH1 0x0 JUMPDEST PUSH1 0x2 SLOAD DUP2 LT ISZERO PUSH2 0x27A JUMPI DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x2 DUP3 DUP2 SLOAD DUP2 LT PUSH2 0x23B JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ ISZERO PUSH2 0x272 JUMPI PUSH2 0x26D DUP3 DUP3 PUSH2 0x684 JUMP JUMPDEST PUSH2 0x27A JUMP JUMPDEST PUSH1 0x1 ADD PUSH2 0x20D JUMP JUMPDEST POP POP JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 JUMP JUMPDEST PUSH2 0x2A2 PUSH2 0x463 JUMP JUMPDEST PUSH2 0x27A DUP3 DUP3 PUSH2 0x684 JUMP JUMPDEST PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND DUP2 JUMP JUMPDEST PUSH1 0x60 PUSH2 0x2CB PUSH2 0x8FF JUMP JUMPDEST PUSH1 0x0 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP5 DUP5 PUSH1 0x40 MLOAD PUSH2 0x2F4 SWAP3 SWAP2 SWAP1 PUSH2 0xB88 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP7 GAS CALL SWAP2 POP POP RETURNDATASIZE DUP1 PUSH1 0x0 DUP2 EQ PUSH2 0x331 JUMPI PUSH1 0x40 MLOAD SWAP2 POP PUSH1 0x1F NOT PUSH1 0x3F RETURNDATASIZE ADD AND DUP3 ADD PUSH1 0x40 MSTORE RETURNDATASIZE DUP3 MSTORE RETURNDATASIZE PUSH1 0x0 PUSH1 0x20 DUP5 ADD RETURNDATACOPY PUSH2 0x336 JUMP JUMPDEST PUSH1 0x60 SWAP2 POP JUMPDEST POP SWAP3 POP SWAP1 POP DUP1 PUSH2 0x349 JUMPI PUSH2 0x349 DUP3 PUSH2 0x67C JUMP JUMPDEST POP SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x60 PUSH1 0x2 DUP1 SLOAD DUP1 PUSH1 0x20 MUL PUSH1 0x20 ADD PUSH1 0x40 MLOAD SWAP1 DUP2 ADD PUSH1 0x40 MSTORE DUP1 SWAP3 SWAP2 SWAP1 DUP2 DUP2 MSTORE PUSH1 0x20 ADD DUP3 DUP1 SLOAD DUP1 ISZERO PUSH2 0x3B6 JUMPI PUSH1 0x20 MUL DUP3 ADD SWAP2 SWAP1 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 KECCAK256 SWAP1 JUMPDEST DUP2 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x1 SWAP1 SWAP2 ADD SWAP1 PUSH1 0x20 ADD DUP1 DUP4 GT PUSH2 0x38B JUMPI JUMPDEST POP POP POP POP POP SWAP1 POP SWAP1 JUMP JUMPDEST PUSH2 0x3C8 PUSH2 0x463 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH2 0x3F3 JUMPI PUSH2 0x3EE PUSH2 0x205 PUSH2 0x922 JUMP JUMPDEST PUSH2 0x18D JUMP JUMPDEST PUSH1 0x0 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP4 AND SWAP1 DUP2 OR DUP3 SSTORE PUSH1 0x40 MLOAD SWAP1 SWAP2 CALLER SWAP2 PUSH32 0x8BE0079C531659141344CD1FD0A4F28419497F9722A3DAAFE3B4186F6B6457E0 SWAP2 SWAP1 LOG3 POP JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND CALLER EQ PUSH2 0x4AA JUMPI PUSH1 0x0 SLOAD PUSH2 0x4AA SWAP1 PUSH2 0x205 SWAP1 CALLER SWAP1 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH2 0x959 JUMP JUMPDEST JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH2 0x4D2 JUMPI PUSH2 0x4D2 PUSH2 0x205 PUSH2 0x9FB JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND ISZERO PUSH2 0x50C JUMPI PUSH2 0x50C PUSH2 0x205 DUP3 PUSH2 0xA32 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 DUP2 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 DUP2 SWAP1 MSTORE PUSH1 0x40 DUP1 DUP4 KECCAK256 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 AND DUP4 OR SWAP1 SSTORE PUSH1 0x2 DUP1 SLOAD SWAP3 DUP4 ADD DUP2 SSTORE DUP4 MSTORE PUSH32 0x405787FA12A823E0F2B7631CC41B3BA8828B3321CA811111FA75CD3AA3BB5ACE SWAP1 SWAP2 ADD DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND DUP5 OR SWAP1 SSTORE MLOAD CALLER SWAP3 SWAP2 PUSH32 0x3147867C59D17E8FA9D522465651D44AAE0A9E38F902F3475B97E58072F0ED4C SWAP2 LOG3 POP JUMP JUMPDEST PUSH1 0x60 PUSH4 0xEB5108A2 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 SWAP1 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP4 AND SWAP3 SWAP1 SWAP3 OR SWAP1 SWAP2 MSTORE SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST DUP1 MLOAD PUSH1 0x20 DUP3 ADD REVERT JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x6BD JUMPI PUSH2 0x6BD PUSH2 0x205 DUP4 PUSH2 0x5DD JUMP JUMPDEST PUSH1 0x2 SLOAD DUP2 LT PUSH2 0x6D8 JUMPI PUSH2 0x6D8 PUSH2 0x205 DUP3 PUSH1 0x2 DUP1 SLOAD SWAP1 POP PUSH2 0xA4D JUMP JUMPDEST DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x2 DUP3 DUP2 SLOAD DUP2 LT PUSH2 0x6FC JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ PUSH2 0x75E JUMPI PUSH2 0x75E PUSH2 0x205 PUSH1 0x2 DUP4 DUP2 SLOAD DUP2 LT PUSH2 0x736 JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP5 PUSH2 0xA6A JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 AND SWAP1 SSTORE PUSH1 0x2 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 ADD SWAP1 DUP2 LT PUSH2 0x7D9 JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH1 0x2 DUP1 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 SWAP3 AND SWAP2 DUP4 SWAP1 DUP2 LT PUSH2 0x80C JUMPI INVALID JUMPDEST SWAP1 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 KECCAK256 ADD PUSH1 0x0 PUSH2 0x100 EXP DUP2 SLOAD DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF MUL NOT AND SWAP1 DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND MUL OR SWAP1 SSTORE POP PUSH1 0x2 DUP1 SLOAD DUP1 PUSH2 0x85F JUMPI INVALID JUMPDEST PUSH1 0x0 DUP3 DUP2 MSTORE PUSH1 0x20 DUP2 KECCAK256 DUP3 ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 DUP2 ADD DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND SWAP1 SSTORE SWAP1 SWAP2 ADD SWAP1 SWAP2 SSTORE PUSH1 0x40 MLOAD CALLER SWAP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP6 AND SWAP2 PUSH32 0x1F32C1B084E2DE0713B8FB16BD46BB9DF710A3DBEAE2F3CA93AF46E016DCC6B0 SWAP2 SWAP1 LOG3 POP POP JUMP JUMPDEST CALLER PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x4AA JUMPI PUSH2 0x4AA PUSH2 0x205 CALLER PUSH2 0xA87 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD SWAP1 SWAP2 MSTORE PUSH1 0x4 DUP2 MSTORE PUSH32 0xE69EDC3E00000000000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 JUMP JUMPDEST PUSH1 0x60 PUSH4 0x1DE45AD1 PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xBB9 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 SWAP1 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP4 AND SWAP3 SWAP1 SWAP3 OR SWAP1 SWAP2 MSTORE SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD SWAP1 SWAP2 MSTORE PUSH1 0x4 DUP2 MSTORE PUSH32 0x57654FE400000000000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xDE16F1A0 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xE9F83771 PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xCB6 JUMP JUMPDEST PUSH1 0x60 PUSH4 0x140A84DB PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xBB9 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xB65A25B9 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xAB3 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 CALLDATALOAD PUSH2 0xABE DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 PUSH1 0x40 DUP5 DUP7 SUB SLT ISZERO PUSH2 0xAD9 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP4 CALLDATALOAD PUSH2 0xAE4 DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP3 POP PUSH1 0x20 DUP5 ADD CALLDATALOAD PUSH8 0xFFFFFFFFFFFFFFFF DUP1 DUP3 GT ISZERO PUSH2 0xB00 JUMPI DUP4 DUP5 REVERT JUMPDEST DUP2 DUP7 ADD SWAP2 POP DUP7 PUSH1 0x1F DUP4 ADD SLT PUSH2 0xB13 JUMPI DUP4 DUP5 REVERT JUMPDEST DUP2 CALLDATALOAD DUP2 DUP2 GT ISZERO PUSH2 0xB21 JUMPI DUP5 DUP6 REVERT JUMPDEST DUP8 PUSH1 0x20 DUP3 DUP6 ADD ADD GT ISZERO PUSH2 0xB32 JUMPI DUP5 DUP6 REVERT JUMPDEST PUSH1 0x20 DUP4 ADD SWAP5 POP DUP1 SWAP4 POP POP POP POP SWAP3 POP SWAP3 POP SWAP3 JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x40 DUP4 DUP6 SUB SLT ISZERO PUSH2 0xB57 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP3 CALLDATALOAD PUSH2 0xB62 DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP5 PUSH1 0x20 SWAP4 SWAP1 SWAP4 ADD CALLDATALOAD SWAP4 POP POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xB81 JUMPI DUP1 DUP2 REVERT JUMPDEST POP CALLDATALOAD SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP3 DUP5 DUP4 CALLDATACOPY SWAP2 ADD SWAP1 DUP2 MSTORE SWAP2 SWAP1 POP JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP3 DUP4 AND DUP2 MSTORE SWAP2 AND PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x40 ADD SWAP1 JUMP JUMPDEST PUSH1 0x20 DUP1 DUP3 MSTORE DUP3 MLOAD DUP3 DUP3 ADD DUP2 SWAP1 MSTORE PUSH1 0x0 SWAP2 SWAP1 DUP5 DUP3 ADD SWAP1 PUSH1 0x40 DUP6 ADD SWAP1 DUP5 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xC2E JUMPI DUP4 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP4 MSTORE SWAP3 DUP5 ADD SWAP3 SWAP2 DUP5 ADD SWAP2 PUSH1 0x1 ADD PUSH2 0xBFC JUMP JUMPDEST POP SWAP1 SWAP7 SWAP6 POP POP POP POP POP POP JUMP JUMPDEST SWAP1 ISZERO ISZERO DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP1 DUP4 MSTORE DUP4 MLOAD DUP1 DUP3 DUP6 ADD MSTORE DUP3 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xC71 JUMPI DUP6 DUP2 ADD DUP4 ADD MLOAD DUP6 DUP3 ADD PUSH1 0x40 ADD MSTORE DUP3 ADD PUSH2 0xC55 JUMP JUMPDEST DUP2 DUP2 GT ISZERO PUSH2 0xC82 JUMPI DUP4 PUSH1 0x40 DUP4 DUP8 ADD ADD MSTORE JUMPDEST POP PUSH1 0x1F ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 AND SWAP3 SWAP1 SWAP3 ADD PUSH1 0x40 ADD SWAP4 SWAP3 POP POP POP JUMP JUMPDEST SWAP2 DUP3 MSTORE PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x40 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND DUP2 EQ PUSH2 0x18D JUMPI PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xC6 0x5C 0x26 SWAP2 PUSH19 0x307C3233F41D02063DD36016FA933E6B4E9FF0 0xE9 SELFDESTRUCT 0xDA 0x27 0xB6 0x1F LOG4 SMOD PUSH5 0x736F6C6343 STOP MOD 0xC STOP CALLER LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xF9 0xDC PUSH14 0x46F6AA9A201DB4E1E18A137C2C97 0xB0 0xD7 0xB4 LT CALLCODE SWAP1 DUP1 PUSH15 0x865DB52083E17664736F6C63430006 0xC STOP CALLER PUSH1 0xC0 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x40 MLOAD PUSH2 0xAFA CODESIZE SUB DUP1 PUSH2 0xAFA DUP4 CODECOPY DUP2 ADD PUSH1 0x40 DUP2 SWAP1 MSTORE PUSH2 0x2F SWAP2 PUSH2 0x4C JUMP JUMPDEST PUSH1 0x1 PUSH1 0x1 PUSH1 0x60 SHL SUB NOT PUSH1 0x60 SWAP2 DUP3 SHL AND PUSH1 0x80 MSTORE ADDRESS SWAP1 SHL PUSH1 0xA0 MSTORE PUSH2 0x7A JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x5D JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 MLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB DUP2 AND DUP2 EQ PUSH2 0x73 JUMPI DUP2 DUP3 REVERT JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x80 MLOAD PUSH1 0x60 SHR PUSH1 0xA0 MLOAD PUSH1 0x60 SHR PUSH2 0xA52 PUSH2 0xA8 PUSH1 0x0 CODECOPY DUP1 PUSH2 0x4CF MSTORE POP DUP1 PUSH2 0x2AA MSTORE DUP1 PUSH2 0x2E6 MSTORE POP PUSH2 0xA52 PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x4C JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x8CF7934 EQ PUSH2 0x51 JUMPI DUP1 PUSH4 0x5F136A4A EQ PUSH2 0x7A JUMPI DUP1 PUSH4 0xA23CE6CE EQ PUSH2 0x8F JUMPI DUP1 PUSH4 0xC9353CB5 EQ PUSH2 0xA2 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x64 PUSH2 0x5F CALLDATASIZE PUSH1 0x4 PUSH2 0x7C6 JUMP JUMPDEST PUSH2 0xB7 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x71 SWAP2 SWAP1 PUSH2 0x91F JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x82 PUSH2 0x2A8 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x71 SWAP2 SWAP1 PUSH2 0x857 JUMP JUMPDEST PUSH2 0x82 PUSH2 0x9D CALLDATASIZE PUSH1 0x4 PUSH2 0x77F JUMP JUMPDEST PUSH2 0x2CC JUMP JUMPDEST PUSH2 0xB5 PUSH2 0xB0 CALLDATASIZE PUSH1 0x4 PUSH2 0x75C JUMP JUMPDEST PUSH2 0x4B7 JUMP JUMPDEST STOP JUMPDEST DUP1 MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP2 MSTORE PUSH1 0x24 DUP2 ADD SWAP1 SWAP2 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFB969B0A00000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE PUSH1 0x0 SWAP2 PUSH2 0x11C SWAP2 PUSH2 0x53F JUMP JUMPDEST PUSH1 0x20 DUP1 DUP4 ADD MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP2 MSTORE PUSH1 0x24 DUP2 ADD SWAP1 SWAP2 MSTORE SWAP2 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFB969B0A00000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE PUSH2 0x181 SWAP2 PUSH2 0x53F JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH32 0x9DB64A4000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE ADDRESS SWAP1 PUSH4 0x9DB64A40 SWAP1 PUSH2 0x1E0 SWAP1 PUSH32 0xEE8BE1B00000000000000000000000000000000000000000000000000000000 SWAP1 PUSH1 0x0 SWAP1 PUSH1 0x4 ADD PUSH2 0x94C JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x1FA JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x20E JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xF2FDE38B00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE ADDRESS SWAP3 POP PUSH4 0xF2FDE38B SWAP2 POP PUSH2 0x24E SWAP1 DUP7 SWAP1 PUSH1 0x4 ADD PUSH2 0x857 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x268 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x27C JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP PUSH32 0xD150751B00000000000000000000000000000000000000000000000000000000 SWAP7 SWAP6 POP POP POP POP POP POP JUMP JUMPDEST PUSH32 0x0 DUP2 JUMP JUMPDEST PUSH1 0x0 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH32 0x0 AND EQ PUSH2 0x346 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x33D SWAP1 PUSH2 0x994 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 REVERT JUMPDEST DUP3 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH4 0x73F208D5 ADDRESS PUSH4 0x8CF7934 PUSH1 0xE0 SHL DUP8 DUP7 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x37E SWAP3 SWAP2 SWAP1 PUSH2 0x878 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 DUP2 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP5 DUP6 AND OR SWAP1 MSTORE MLOAD PUSH1 0xE0 DUP6 SWAP1 SHL SWAP1 SWAP3 AND DUP3 MSTORE PUSH2 0x40F SWAP3 SWAP2 PUSH1 0x4 ADD PUSH2 0x8B1 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x429 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x43D JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xC9353CB500000000000000000000000000000000000000000000000000000000 DUP2 MSTORE ADDRESS SWAP3 POP PUSH4 0xC9353CB5 SWAP2 POP PUSH2 0x47D SWAP1 DUP8 SWAP1 PUSH1 0x4 ADD PUSH2 0x857 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x497 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x4AB JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP SWAP5 SWAP7 SWAP6 POP POP POP POP POP POP JUMP JUMPDEST CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH32 0x0 AND EQ PUSH2 0x526 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x33D SWAP1 PUSH2 0x994 JUMP JUMPDEST DUP1 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SELFDESTRUCT JUMPDEST PUSH1 0x0 PUSH1 0x60 DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP4 PUSH1 0x40 MLOAD PUSH2 0x568 SWAP2 SWAP1 PUSH2 0x83B JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 DUP6 GAS DELEGATECALL SWAP2 POP POP RETURNDATASIZE DUP1 PUSH1 0x0 DUP2 EQ PUSH2 0x5A3 JUMPI PUSH1 0x40 MLOAD SWAP2 POP PUSH1 0x1F NOT PUSH1 0x3F RETURNDATASIZE ADD AND DUP3 ADD PUSH1 0x40 MSTORE RETURNDATASIZE DUP3 MSTORE RETURNDATASIZE PUSH1 0x0 PUSH1 0x20 DUP5 ADD RETURNDATACOPY PUSH2 0x5A8 JUMP JUMPDEST PUSH1 0x60 SWAP2 POP JUMPDEST POP SWAP2 POP SWAP2 POP DUP2 ISZERO DUP1 PUSH2 0x5BC JUMPI POP DUP1 MLOAD PUSH1 0x20 EQ ISZERO JUMPDEST DUP1 PUSH2 0x61E JUMPI POP DUP1 MLOAD PUSH32 0xD150751B00000000000000000000000000000000000000000000000000000000 SWAP1 PUSH2 0x5F9 SWAP1 DUP4 ADD PUSH1 0x20 SWAP1 DUP2 ADD SWAP1 DUP5 ADD PUSH2 0x7FB JUMP JUMPDEST PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 AND EQ ISZERO JUMPDEST ISZERO PUSH2 0x635 JUMPI PUSH2 0x635 PUSH2 0x630 DUP6 DUP4 PUSH2 0x63B JUMP JUMPDEST PUSH2 0x6F6 JUMP JUMPDEST POP POP POP POP JUMP JUMPDEST PUSH1 0x60 PUSH32 0xD19D65DF6830E3CB0DA1E12B8E9738E2DC473F830D8AF813BCC031EB5A1675D1 DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x671 SWAP3 SWAP2 SWAP1 PUSH2 0x8B1 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 SWAP1 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP4 AND SWAP3 SWAP1 SWAP3 OR SWAP1 SWAP2 MSTORE SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST DUP1 MLOAD PUSH1 0x20 DUP3 ADD REVERT JUMPDEST PUSH1 0x0 PUSH1 0x40 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x70F JUMPI DUP1 DUP2 REVERT JUMPDEST PUSH1 0x40 MLOAD PUSH1 0x40 DUP2 ADD DUP2 DUP2 LT PUSH8 0xFFFFFFFFFFFFFFFF DUP3 GT OR ISZERO PUSH2 0x72E JUMPI DUP3 DUP4 REVERT JUMPDEST PUSH1 0x40 MSTORE SWAP1 POP DUP1 DUP3 CALLDATALOAD PUSH2 0x73F DUP2 PUSH2 0x9F7 JUMP JUMPDEST DUP2 MSTORE PUSH1 0x20 DUP4 ADD CALLDATALOAD PUSH2 0x74F DUP2 PUSH2 0x9F7 JUMP JUMPDEST PUSH1 0x20 SWAP2 SWAP1 SWAP2 ADD MSTORE SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x76D JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 CALLDATALOAD PUSH2 0x778 DUP2 PUSH2 0x9F7 JUMP JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 PUSH1 0x80 DUP5 DUP7 SUB SLT ISZERO PUSH2 0x793 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP4 CALLDATALOAD PUSH2 0x79E DUP2 PUSH2 0x9F7 JUMP JUMPDEST SWAP3 POP PUSH1 0x20 DUP5 ADD CALLDATALOAD PUSH2 0x7AE DUP2 PUSH2 0x9F7 JUMP JUMPDEST SWAP2 POP PUSH2 0x7BD DUP6 PUSH1 0x40 DUP7 ADD PUSH2 0x6FE JUMP JUMPDEST SWAP1 POP SWAP3 POP SWAP3 POP SWAP3 JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x60 DUP4 DUP6 SUB SLT ISZERO PUSH2 0x7D8 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP3 CALLDATALOAD PUSH2 0x7E3 DUP2 PUSH2 0x9F7 JUMP JUMPDEST SWAP2 POP PUSH2 0x7F2 DUP5 PUSH1 0x20 DUP6 ADD PUSH2 0x6FE JUMP JUMPDEST SWAP1 POP SWAP3 POP SWAP3 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x80C JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 MLOAD PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 DUP2 AND DUP2 EQ PUSH2 0x778 JUMPI DUP2 DUP3 REVERT JUMPDEST PUSH1 0x0 DUP3 MLOAD PUSH2 0x84D DUP2 DUP5 PUSH1 0x20 DUP8 ADD PUSH2 0x9CB JUMP JUMPDEST SWAP2 SWAP1 SWAP2 ADD SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP3 DUP4 AND DUP2 MSTORE DUP2 MLOAD DUP4 AND PUSH1 0x20 DUP1 DUP4 ADD SWAP2 SWAP1 SWAP2 MSTORE SWAP1 SWAP2 ADD MLOAD SWAP1 SWAP2 AND PUSH1 0x40 DUP3 ADD MSTORE PUSH1 0x60 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP5 AND DUP3 MSTORE PUSH1 0x40 PUSH1 0x20 DUP4 ADD MSTORE DUP3 MLOAD DUP1 PUSH1 0x40 DUP5 ADD MSTORE PUSH2 0x8EC DUP2 PUSH1 0x60 DUP6 ADD PUSH1 0x20 DUP8 ADD PUSH2 0x9CB JUMP JUMPDEST PUSH1 0x1F ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 AND SWAP2 SWAP1 SWAP2 ADD PUSH1 0x60 ADD SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP3 SWAP1 SWAP3 AND DUP3 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x40 ADD SWAP1 JUMP JUMPDEST PUSH1 0x20 DUP1 DUP3 MSTORE PUSH1 0x1F SWAP1 DUP3 ADD MSTORE PUSH32 0x496E697469616C4D6967726174696F6E2F494E56414C49445F53454E44455200 PUSH1 0x40 DUP3 ADD MSTORE PUSH1 0x60 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 JUMPDEST DUP4 DUP2 LT ISZERO PUSH2 0x9E6 JUMPI DUP2 DUP2 ADD MLOAD DUP4 DUP3 ADD MSTORE PUSH1 0x20 ADD PUSH2 0x9CE JUMP JUMPDEST DUP4 DUP2 GT ISZERO PUSH2 0x635 JUMPI POP POP PUSH1 0x0 SWAP2 ADD MSTORE JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND DUP2 EQ PUSH2 0xA19 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 LOG1 PUSH16 0x740E3543E464FB7B9EC07EBB663ADE6C 0x4E DUP15 PUSH20 0xC8ADD2A24EA1B0D4D96F6664736F6C634300060C STOP CALLER ",
"sourceMap": "1098:5841:45:-:0;;;2042:301;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;;2118:36:45;;;;;;;2301:35;;2330:4;;2301:35;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2281:17:45;:55;;-1:-1:-1;;;;;;2281:55:45;-1:-1:-1;;;;;2281:55:45;;;;;;;;;;-1:-1:-1;1098:5841:45;;;;;;;;;;:::o;162:279:-1:-;;285:2;273:9;264:7;260:23;256:32;253:2;;;-1:-1;;291:12;253:2;91:13;;-1:-1;;;;;1063:54;;1196:43;;1186:2;;-1:-1;;1243:12;1186:2;343:82;247:194;-1:-1;;;247:194::o;568:222::-;-1:-1;;;;;1063:54;;;;519:37;;695:2;680:18;;666:124::o;:::-;1098:5841:45;;;;;;;;;;;"
},
"deployedBytecode": {
"immutableReferences": {
"8650": [
{
"length": 32,
"start": 185
},
{
"length": 32,
"start": 746
}
]
},
"linkReferences": {},
"object": "0x608060405234801561001057600080fd5b506004361061004c5760003560e01c8063329798a4146100515780635f136a4a1461007a578063b3d3173514610082578063c9353cb51461008a575b600080fd5b61006461005f366004610906565b61009f565b6040516100719190610a14565b60405180910390f35b6100646102e8565b61006461030c565b61009d6100983660046108e3565b610328565b005b60003373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610119576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161011090610b0d565b60405180910390fd5b600054604080518082018252855173ffffffffffffffffffffffffffffffffffffffff908116825260208088015182169083015291517fa23ce6ce000000000000000000000000000000000000000000000000000000008152919092169163a23ce6ce9161018e913091899190600401610a35565b602060405180830381600087803b1580156101a857600080fd5b505af11580156101bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e091906109f8565b506101ed8486858561037a565b6040517ff2fde38b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063f2fde38b9061023f908890600401610a14565b600060405180830381600087803b15801561025957600080fd5b505af115801561026d573d6000803e3d6000fd5b50506040517fc9353cb500000000000000000000000000000000000000000000000000000000815230925063c9353cb591506102ad908890600401610a14565b600060405180830381600087803b1580156102c757600080fd5b505af11580156102db573d6000803e3d6000fd5b5095979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b333014610361576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161011090610b0d565b8073ffffffffffffffffffffffffffffffffffffffff16ff5b604051849060009061038b90610895565b604051809103906000f0801580156103a7573d6000803e3d6000fd5b506040517f42f1181e00000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff8216906342f1181e906103fd908990600401610a14565b600060405180830381600087803b15801561041757600080fd5b505af115801561042b573d6000803e3d6000fd5b50506040517ff2fde38b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416925063f2fde38b9150610481908890600401610a14565b600060405180830381600087803b15801561049b57600080fd5b505af11580156104af573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff1663261fe679856040015163ce5494bb60e01b846040516024016104ed9190610a14565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009485161790525160e085901b909216825261058092913090600401610a74565b600060405180830381600087803b15801561059a57600080fd5b505af11580156105ae573d6000803e3d6000fd5b5050506060850151845160405173ffffffffffffffffffffffffffffffffffffffff8616945063261fe67993507fce5494bb000000000000000000000000000000000000000000000000000000009161060991602401610a14565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009485161790525160e085901b909216825261069c92913090600401610a74565b600060405180830381600087803b1580156106b657600080fd5b505af11580156106ca573d6000803e3d6000fd5b50505060808401516040805160048082526024820183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f8fd3ab800000000000000000000000000000000000000000000000000000000017905291517f261fe67900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616945063261fe6799361077c93909291309101610a74565b600060405180830381600087803b15801561079657600080fd5b505af11580156107aa573d6000803e3d6000fd5b50505060a08401516040805160048082526024820183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f8fd3ab800000000000000000000000000000000000000000000000000000000017905291517f261fe67900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616945063261fe6799361085c93909291309101610a74565b600060405180830381600087803b15801561087657600080fd5b505af115801561088a573d6000803e3d6000fd5b505050505050505050565b610d4e80610b9183390190565b80356108ad81610b6b565b92915050565b6000602082840312156108c4578081fd5b6108ce6020610b44565b905081356108db81610b6b565b815292915050565b6000602082840312156108f4578081fd5b81356108ff81610b6b565b9392505050565b60008060008084860361012081121561091d578384fd5b853561092881610b6b565b9450602086013561093881610b6b565b935060c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082011215610969578283fd5b5061097460c0610b44565b61098187604088016108a2565b815261099087606088016108a2565b60208201526109a287608088016108a2565b60408201526109b48760a088016108a2565b60608201526109c68760c088016108a2565b60808201526109d88760e088016108a2565b60a082015291506109ed8661010087016108b3565b905092959194509250565b600060208284031215610a09578081fd5b81516108ff81610b6b565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff93841681529183166020808401919091528151841660408401520151909116606082015260800190565b600073ffffffffffffffffffffffffffffffffffffffff808616835260206060818501528551806060860152835b81811015610abe57878101830151868201608001528201610aa2565b81811115610acf5784608083880101525b509490911660408401525050601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160160800192915050565b6020808252601c908201527f46756c6c4d6967726174696f6e2f494e56414c49445f53454e44455200000000604082015260600190565b60405181810167ffffffffffffffff81118282101715610b6357600080fd5b604052919050565b73ffffffffffffffffffffffffffffffffffffffff81168114610b8d57600080fd5b5056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610d1c806100326000396000f3fe608060405234801561001057600080fd5b50600436106100a35760003560e01c80639ad2674411610076578063bca8c7b51161005b578063bca8c7b514610134578063d39de6e914610154578063f2fde38b14610169576100a3565b80639ad2674414610101578063b918161114610114576100a3565b806342f1181e146100a8578063494503d4146100bd57806370712939146100e65780638da5cb5b146100f9575b600080fd5b6100bb6100b6366004610aa2565b61017c565b005b6100d06100cb366004610b70565b610190565b6040516100dd9190610b98565b60405180910390f35b6100bb6100f4366004610aa2565b6101c4565b6100d061027e565b6100bb61010f366004610b45565b61029a565b610127610122366004610aa2565b6102ac565b6040516100dd9190610c3a565b610147610142366004610ac5565b6102c1565b6040516100dd9190610c45565b61015c610351565b6040516100dd9190610be0565b6100bb610177366004610aa2565b6103c0565b610184610463565b61018d816104ac565b50565b6002818154811061019d57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b6101cc610463565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1661020a5761020a610205826105dd565b61067c565b60005b60025481101561027a578173ffffffffffffffffffffffffffffffffffffffff166002828154811061023b57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614156102725761026d8282610684565b61027a565b60010161020d565b5050565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b6102a2610463565b61027a8282610684565b60016020526000908152604090205460ff1681565b60606102cb6108ff565b60008473ffffffffffffffffffffffffffffffffffffffff1684846040516102f4929190610b88565b6000604051808303816000865af19150503d8060008114610331576040519150601f19603f3d011682016040523d82523d6000602084013e610336565b606091505b509250905080610349576103498261067c565b509392505050565b606060028054806020026020016040519081016040528092919081815260200182805480156103b657602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff16815260019091019060200180831161038b575b5050505050905090565b6103c8610463565b73ffffffffffffffffffffffffffffffffffffffff81166103f3576103ee610205610922565b61018d565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b60005473ffffffffffffffffffffffffffffffffffffffff1633146104aa576000546104aa9061020590339073ffffffffffffffffffffffffffffffffffffffff16610959565b565b73ffffffffffffffffffffffffffffffffffffffff81166104d2576104d26102056109fb565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff161561050c5761050c61020582610a32565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b606063eb5108a260e01b826040516024016105f89190610b98565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b805160208201fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff166106bd576106bd610205836105dd565b60025481106106d8576106d861020582600280549050610a4d565b8173ffffffffffffffffffffffffffffffffffffffff16600282815481106106fc57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161461075e5761075e6102056002838154811061073657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1684610a6a565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081106107d957fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff909216918390811061080c57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600280548061085f57fe5b60008281526020812082017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90810180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055909101909155604051339173ffffffffffffffffffffffffffffffffffffffff8516917f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b09190a35050565b3360009081526001602052604090205460ff166104aa576104aa61020533610a87565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b6060631de45ad160e01b8383604051602401610976929190610bb9565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b60408051808201909152600481527f57654fe400000000000000000000000000000000000000000000000000000000602082015290565b606063de16f1a060e01b826040516024016105f89190610b98565b606063e9f8377160e01b8383604051602401610976929190610cb6565b606063140a84db60e01b8383604051602401610976929190610bb9565b606063b65a25b960e01b826040516024016105f89190610b98565b600060208284031215610ab3578081fd5b8135610abe81610cc4565b9392505050565b600080600060408486031215610ad9578182fd5b8335610ae481610cc4565b9250602084013567ffffffffffffffff80821115610b00578384fd5b818601915086601f830112610b13578384fd5b813581811115610b21578485fd5b876020828501011115610b32578485fd5b6020830194508093505050509250925092565b60008060408385031215610b57578182fd5b8235610b6281610cc4565b946020939093013593505050565b600060208284031215610b81578081fd5b5035919050565b6000828483379101908152919050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b6020808252825182820181905260009190848201906040850190845b81811015610c2e57835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101610bfc565b50909695505050505050565b901515815260200190565b6000602080835283518082850152825b81811015610c7157858101830151858201604001528201610c55565b81811115610c825783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b918252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff8116811461018d57600080fdfea2646970667358221220c65c269172307c3233f41d02063dd36016fa933e6b4e9ff0e9ffda27b61fa40764736f6c634300060c0033a2646970667358221220f9dc6d46f6aa9a201db4e1e18a137c2c97b0d7b410f290806e865db52083e17664736f6c634300060c0033",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x4C JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x329798A4 EQ PUSH2 0x51 JUMPI DUP1 PUSH4 0x5F136A4A EQ PUSH2 0x7A JUMPI DUP1 PUSH4 0xB3D31735 EQ PUSH2 0x82 JUMPI DUP1 PUSH4 0xC9353CB5 EQ PUSH2 0x8A JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x64 PUSH2 0x5F CALLDATASIZE PUSH1 0x4 PUSH2 0x906 JUMP JUMPDEST PUSH2 0x9F JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x71 SWAP2 SWAP1 PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x64 PUSH2 0x2E8 JUMP JUMPDEST PUSH2 0x64 PUSH2 0x30C JUMP JUMPDEST PUSH2 0x9D PUSH2 0x98 CALLDATASIZE PUSH1 0x4 PUSH2 0x8E3 JUMP JUMPDEST PUSH2 0x328 JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PUSH32 0x0 AND EQ PUSH2 0x119 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x110 SWAP1 PUSH2 0xB0D JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 REVERT JUMPDEST PUSH1 0x0 SLOAD PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD DUP3 MSTORE DUP6 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 DUP2 AND DUP3 MSTORE PUSH1 0x20 DUP1 DUP9 ADD MLOAD DUP3 AND SWAP1 DUP4 ADD MSTORE SWAP2 MLOAD PUSH32 0xA23CE6CE00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE SWAP2 SWAP1 SWAP3 AND SWAP2 PUSH4 0xA23CE6CE SWAP2 PUSH2 0x18E SWAP2 ADDRESS SWAP2 DUP10 SWAP2 SWAP1 PUSH1 0x4 ADD PUSH2 0xA35 JUMP JUMPDEST PUSH1 0x20 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x1A8 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x1BC JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP PUSH1 0x40 MLOAD RETURNDATASIZE PUSH1 0x1F NOT PUSH1 0x1F DUP3 ADD AND DUP3 ADD DUP1 PUSH1 0x40 MSTORE POP DUP2 ADD SWAP1 PUSH2 0x1E0 SWAP2 SWAP1 PUSH2 0x9F8 JUMP JUMPDEST POP PUSH2 0x1ED DUP5 DUP7 DUP6 DUP6 PUSH2 0x37A JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH32 0xF2FDE38B00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP6 AND SWAP1 PUSH4 0xF2FDE38B SWAP1 PUSH2 0x23F SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x259 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x26D JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xC9353CB500000000000000000000000000000000000000000000000000000000 DUP2 MSTORE ADDRESS SWAP3 POP PUSH4 0xC9353CB5 SWAP2 POP PUSH2 0x2AD SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x2C7 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x2DB JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP SWAP6 SWAP8 SWAP7 POP POP POP POP POP POP POP JUMP JUMPDEST PUSH32 0x0 DUP2 JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 JUMP JUMPDEST CALLER ADDRESS EQ PUSH2 0x361 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD PUSH2 0x110 SWAP1 PUSH2 0xB0D JUMP JUMPDEST DUP1 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SELFDESTRUCT JUMPDEST PUSH1 0x40 MLOAD DUP5 SWAP1 PUSH1 0x0 SWAP1 PUSH2 0x38B SWAP1 PUSH2 0x895 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 PUSH1 0x0 CREATE DUP1 ISZERO DUP1 ISZERO PUSH2 0x3A7 JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP PUSH1 0x40 MLOAD PUSH32 0x42F1181E00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE SWAP1 SWAP2 POP PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND SWAP1 PUSH4 0x42F1181E SWAP1 PUSH2 0x3FD SWAP1 DUP10 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x417 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x42B JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH32 0xF2FDE38B00000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP5 AND SWAP3 POP PUSH4 0xF2FDE38B SWAP2 POP PUSH2 0x481 SWAP1 DUP9 SWAP1 PUSH1 0x4 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x49B JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x4AF JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH4 0x261FE679 DUP6 PUSH1 0x40 ADD MLOAD PUSH4 0xCE5494BB PUSH1 0xE0 SHL DUP5 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x4ED SWAP2 SWAP1 PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 DUP2 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP5 DUP6 AND OR SWAP1 MSTORE MLOAD PUSH1 0xE0 DUP6 SWAP1 SHL SWAP1 SWAP3 AND DUP3 MSTORE PUSH2 0x580 SWAP3 SWAP2 ADDRESS SWAP1 PUSH1 0x4 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x59A JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x5AE JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0x60 DUP6 ADD MLOAD DUP5 MLOAD PUSH1 0x40 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 POP PUSH32 0xCE5494BB00000000000000000000000000000000000000000000000000000000 SWAP2 PUSH2 0x609 SWAP2 PUSH1 0x24 ADD PUSH2 0xA14 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 DUP2 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP5 DUP6 AND OR SWAP1 MSTORE MLOAD PUSH1 0xE0 DUP6 SWAP1 SHL SWAP1 SWAP3 AND DUP3 MSTORE PUSH2 0x69C SWAP3 SWAP2 ADDRESS SWAP1 PUSH1 0x4 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x6B6 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x6CA JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0x80 DUP5 ADD MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP1 DUP3 MSTORE PUSH1 0x24 DUP3 ADD DUP4 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0x8FD3AB8000000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE SWAP2 MLOAD PUSH32 0x261FE67900000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 PUSH2 0x77C SWAP4 SWAP1 SWAP3 SWAP2 ADDRESS SWAP2 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x796 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x7AA JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP PUSH1 0xA0 DUP5 ADD MLOAD PUSH1 0x40 DUP1 MLOAD PUSH1 0x4 DUP1 DUP3 MSTORE PUSH1 0x24 DUP3 ADD DUP4 MSTORE PUSH1 0x20 DUP3 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0x8FD3AB8000000000000000000000000000000000000000000000000000000000 OR SWAP1 MSTORE SWAP2 MLOAD PUSH32 0x261FE67900000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP7 AND SWAP5 POP PUSH4 0x261FE679 SWAP4 PUSH2 0x85C SWAP4 SWAP1 SWAP3 SWAP2 ADDRESS SWAP2 ADD PUSH2 0xA74 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP8 DUP1 EXTCODESIZE ISZERO DUP1 ISZERO PUSH2 0x876 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP GAS CALL ISZERO DUP1 ISZERO PUSH2 0x88A JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP POP POP POP POP POP POP POP JUMP JUMPDEST PUSH2 0xD4E DUP1 PUSH2 0xB91 DUP4 CODECOPY ADD SWAP1 JUMP JUMPDEST DUP1 CALLDATALOAD PUSH2 0x8AD DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x8C4 JUMPI DUP1 DUP2 REVERT JUMPDEST PUSH2 0x8CE PUSH1 0x20 PUSH2 0xB44 JUMP JUMPDEST SWAP1 POP DUP2 CALLDATALOAD PUSH2 0x8DB DUP2 PUSH2 0xB6B JUMP JUMPDEST DUP2 MSTORE SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0x8F4 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 CALLDATALOAD PUSH2 0x8FF DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 DUP1 DUP5 DUP7 SUB PUSH2 0x120 DUP2 SLT ISZERO PUSH2 0x91D JUMPI DUP4 DUP5 REVERT JUMPDEST DUP6 CALLDATALOAD PUSH2 0x928 DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP5 POP PUSH1 0x20 DUP7 ADD CALLDATALOAD PUSH2 0x938 DUP2 PUSH2 0xB6B JUMP JUMPDEST SWAP4 POP PUSH1 0xC0 PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 DUP3 ADD SLT ISZERO PUSH2 0x969 JUMPI DUP3 DUP4 REVERT JUMPDEST POP PUSH2 0x974 PUSH1 0xC0 PUSH2 0xB44 JUMP JUMPDEST PUSH2 0x981 DUP8 PUSH1 0x40 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST DUP2 MSTORE PUSH2 0x990 DUP8 PUSH1 0x60 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x20 DUP3 ADD MSTORE PUSH2 0x9A2 DUP8 PUSH1 0x80 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x40 DUP3 ADD MSTORE PUSH2 0x9B4 DUP8 PUSH1 0xA0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x60 DUP3 ADD MSTORE PUSH2 0x9C6 DUP8 PUSH1 0xC0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0x80 DUP3 ADD MSTORE PUSH2 0x9D8 DUP8 PUSH1 0xE0 DUP9 ADD PUSH2 0x8A2 JUMP JUMPDEST PUSH1 0xA0 DUP3 ADD MSTORE SWAP2 POP PUSH2 0x9ED DUP7 PUSH2 0x100 DUP8 ADD PUSH2 0x8B3 JUMP JUMPDEST SWAP1 POP SWAP3 SWAP6 SWAP2 SWAP5 POP SWAP3 POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xA09 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 MLOAD PUSH2 0x8FF DUP2 PUSH2 0xB6B JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP4 DUP5 AND DUP2 MSTORE SWAP2 DUP4 AND PUSH1 0x20 DUP1 DUP5 ADD SWAP2 SWAP1 SWAP2 MSTORE DUP2 MLOAD DUP5 AND PUSH1 0x40 DUP5 ADD MSTORE ADD MLOAD SWAP1 SWAP2 AND PUSH1 0x60 DUP3 ADD MSTORE PUSH1 0x80 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP1 DUP7 AND DUP4 MSTORE PUSH1 0x20 PUSH1 0x60 DUP2 DUP6 ADD MSTORE DUP6 MLOAD DUP1 PUSH1 0x60 DUP7 ADD MSTORE DUP4 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xABE JUMPI DUP8 DUP2 ADD DUP4 ADD MLOAD DUP7 DUP3 ADD PUSH1 0x80 ADD MSTORE DUP3 ADD PUSH2 0xAA2 JUMP JUMPDEST DUP2 DUP2 GT ISZERO PUSH2 0xACF JUMPI DUP5 PUSH1 0x80 DUP4 DUP9 ADD ADD MSTORE JUMPDEST POP SWAP5 SWAP1 SWAP2 AND PUSH1 0x40 DUP5 ADD MSTORE POP POP PUSH1 0x1F SWAP2 SWAP1 SWAP2 ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 AND ADD PUSH1 0x80 ADD SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x20 DUP1 DUP3 MSTORE PUSH1 0x1C SWAP1 DUP3 ADD MSTORE PUSH32 0x46756C6C4D6967726174696F6E2F494E56414C49445F53454E44455200000000 PUSH1 0x40 DUP3 ADD MSTORE PUSH1 0x60 ADD SWAP1 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP2 DUP2 ADD PUSH8 0xFFFFFFFFFFFFFFFF DUP2 GT DUP3 DUP3 LT OR ISZERO PUSH2 0xB63 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x40 MSTORE SWAP2 SWAP1 POP JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND DUP2 EQ PUSH2 0xB8D JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x0 DUP1 SLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB NOT AND CALLER OR SWAP1 SSTORE PUSH2 0xD1C DUP1 PUSH2 0x32 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0xA3 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x9AD26744 GT PUSH2 0x76 JUMPI DUP1 PUSH4 0xBCA8C7B5 GT PUSH2 0x5B JUMPI DUP1 PUSH4 0xBCA8C7B5 EQ PUSH2 0x134 JUMPI DUP1 PUSH4 0xD39DE6E9 EQ PUSH2 0x154 JUMPI DUP1 PUSH4 0xF2FDE38B EQ PUSH2 0x169 JUMPI PUSH2 0xA3 JUMP JUMPDEST DUP1 PUSH4 0x9AD26744 EQ PUSH2 0x101 JUMPI DUP1 PUSH4 0xB9181611 EQ PUSH2 0x114 JUMPI PUSH2 0xA3 JUMP JUMPDEST DUP1 PUSH4 0x42F1181E EQ PUSH2 0xA8 JUMPI DUP1 PUSH4 0x494503D4 EQ PUSH2 0xBD JUMPI DUP1 PUSH4 0x70712939 EQ PUSH2 0xE6 JUMPI DUP1 PUSH4 0x8DA5CB5B EQ PUSH2 0xF9 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0xBB PUSH2 0xB6 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x17C JUMP JUMPDEST STOP JUMPDEST PUSH2 0xD0 PUSH2 0xCB CALLDATASIZE PUSH1 0x4 PUSH2 0xB70 JUMP JUMPDEST PUSH2 0x190 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0xBB PUSH2 0xF4 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x1C4 JUMP JUMPDEST PUSH2 0xD0 PUSH2 0x27E JUMP JUMPDEST PUSH2 0xBB PUSH2 0x10F CALLDATASIZE PUSH1 0x4 PUSH2 0xB45 JUMP JUMPDEST PUSH2 0x29A JUMP JUMPDEST PUSH2 0x127 PUSH2 0x122 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x2AC JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xC3A JUMP JUMPDEST PUSH2 0x147 PUSH2 0x142 CALLDATASIZE PUSH1 0x4 PUSH2 0xAC5 JUMP JUMPDEST PUSH2 0x2C1 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xC45 JUMP JUMPDEST PUSH2 0x15C PUSH2 0x351 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0xDD SWAP2 SWAP1 PUSH2 0xBE0 JUMP JUMPDEST PUSH2 0xBB PUSH2 0x177 CALLDATASIZE PUSH1 0x4 PUSH2 0xAA2 JUMP JUMPDEST PUSH2 0x3C0 JUMP JUMPDEST PUSH2 0x184 PUSH2 0x463 JUMP JUMPDEST PUSH2 0x18D DUP2 PUSH2 0x4AC JUMP JUMPDEST POP JUMP JUMPDEST PUSH1 0x2 DUP2 DUP2 SLOAD DUP2 LT PUSH2 0x19D JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 POP DUP2 JUMP JUMPDEST PUSH2 0x1CC PUSH2 0x463 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x20A JUMPI PUSH2 0x20A PUSH2 0x205 DUP3 PUSH2 0x5DD JUMP JUMPDEST PUSH2 0x67C JUMP JUMPDEST PUSH1 0x0 JUMPDEST PUSH1 0x2 SLOAD DUP2 LT ISZERO PUSH2 0x27A JUMPI DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x2 DUP3 DUP2 SLOAD DUP2 LT PUSH2 0x23B JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ ISZERO PUSH2 0x272 JUMPI PUSH2 0x26D DUP3 DUP3 PUSH2 0x684 JUMP JUMPDEST PUSH2 0x27A JUMP JUMPDEST PUSH1 0x1 ADD PUSH2 0x20D JUMP JUMPDEST POP POP JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 JUMP JUMPDEST PUSH2 0x2A2 PUSH2 0x463 JUMP JUMPDEST PUSH2 0x27A DUP3 DUP3 PUSH2 0x684 JUMP JUMPDEST PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND DUP2 JUMP JUMPDEST PUSH1 0x60 PUSH2 0x2CB PUSH2 0x8FF JUMP JUMPDEST PUSH1 0x0 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP5 DUP5 PUSH1 0x40 MLOAD PUSH2 0x2F4 SWAP3 SWAP2 SWAP1 PUSH2 0xB88 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x40 MLOAD DUP1 DUP4 SUB DUP2 PUSH1 0x0 DUP7 GAS CALL SWAP2 POP POP RETURNDATASIZE DUP1 PUSH1 0x0 DUP2 EQ PUSH2 0x331 JUMPI PUSH1 0x40 MLOAD SWAP2 POP PUSH1 0x1F NOT PUSH1 0x3F RETURNDATASIZE ADD AND DUP3 ADD PUSH1 0x40 MSTORE RETURNDATASIZE DUP3 MSTORE RETURNDATASIZE PUSH1 0x0 PUSH1 0x20 DUP5 ADD RETURNDATACOPY PUSH2 0x336 JUMP JUMPDEST PUSH1 0x60 SWAP2 POP JUMPDEST POP SWAP3 POP SWAP1 POP DUP1 PUSH2 0x349 JUMPI PUSH2 0x349 DUP3 PUSH2 0x67C JUMP JUMPDEST POP SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x60 PUSH1 0x2 DUP1 SLOAD DUP1 PUSH1 0x20 MUL PUSH1 0x20 ADD PUSH1 0x40 MLOAD SWAP1 DUP2 ADD PUSH1 0x40 MSTORE DUP1 SWAP3 SWAP2 SWAP1 DUP2 DUP2 MSTORE PUSH1 0x20 ADD DUP3 DUP1 SLOAD DUP1 ISZERO PUSH2 0x3B6 JUMPI PUSH1 0x20 MUL DUP3 ADD SWAP2 SWAP1 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 KECCAK256 SWAP1 JUMPDEST DUP2 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x1 SWAP1 SWAP2 ADD SWAP1 PUSH1 0x20 ADD DUP1 DUP4 GT PUSH2 0x38B JUMPI JUMPDEST POP POP POP POP POP SWAP1 POP SWAP1 JUMP JUMPDEST PUSH2 0x3C8 PUSH2 0x463 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH2 0x3F3 JUMPI PUSH2 0x3EE PUSH2 0x205 PUSH2 0x922 JUMP JUMPDEST PUSH2 0x18D JUMP JUMPDEST PUSH1 0x0 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP4 AND SWAP1 DUP2 OR DUP3 SSTORE PUSH1 0x40 MLOAD SWAP1 SWAP2 CALLER SWAP2 PUSH32 0x8BE0079C531659141344CD1FD0A4F28419497F9722A3DAAFE3B4186F6B6457E0 SWAP2 SWAP1 LOG3 POP JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND CALLER EQ PUSH2 0x4AA JUMPI PUSH1 0x0 SLOAD PUSH2 0x4AA SWAP1 PUSH2 0x205 SWAP1 CALLER SWAP1 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH2 0x959 JUMP JUMPDEST JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH2 0x4D2 JUMPI PUSH2 0x4D2 PUSH2 0x205 PUSH2 0x9FB JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND ISZERO PUSH2 0x50C JUMPI PUSH2 0x50C PUSH2 0x205 DUP3 PUSH2 0xA32 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND PUSH1 0x0 DUP2 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 DUP2 SWAP1 MSTORE PUSH1 0x40 DUP1 DUP4 KECCAK256 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 AND DUP4 OR SWAP1 SSTORE PUSH1 0x2 DUP1 SLOAD SWAP3 DUP4 ADD DUP2 SSTORE DUP4 MSTORE PUSH32 0x405787FA12A823E0F2B7631CC41B3BA8828B3321CA811111FA75CD3AA3BB5ACE SWAP1 SWAP2 ADD DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND DUP5 OR SWAP1 SSTORE MLOAD CALLER SWAP3 SWAP2 PUSH32 0x3147867C59D17E8FA9D522465651D44AAE0A9E38F902F3475B97E58072F0ED4C SWAP2 LOG3 POP JUMP JUMPDEST PUSH1 0x60 PUSH4 0xEB5108A2 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 SWAP1 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP4 AND SWAP3 SWAP1 SWAP3 OR SWAP1 SWAP2 MSTORE SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST DUP1 MLOAD PUSH1 0x20 DUP3 ADD REVERT JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x6BD JUMPI PUSH2 0x6BD PUSH2 0x205 DUP4 PUSH2 0x5DD JUMP JUMPDEST PUSH1 0x2 SLOAD DUP2 LT PUSH2 0x6D8 JUMPI PUSH2 0x6D8 PUSH2 0x205 DUP3 PUSH1 0x2 DUP1 SLOAD SWAP1 POP PUSH2 0xA4D JUMP JUMPDEST DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH1 0x2 DUP3 DUP2 SLOAD DUP2 LT PUSH2 0x6FC JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ PUSH2 0x75E JUMPI PUSH2 0x75E PUSH2 0x205 PUSH1 0x2 DUP4 DUP2 SLOAD DUP2 LT PUSH2 0x736 JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP5 PUSH2 0xA6A JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP3 AND PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 AND SWAP1 SSTORE PUSH1 0x2 DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 ADD SWAP1 DUP2 LT PUSH2 0x7D9 JUMPI INVALID JUMPDEST PUSH1 0x0 SWAP2 DUP3 MSTORE PUSH1 0x20 SWAP1 SWAP2 KECCAK256 ADD SLOAD PUSH1 0x2 DUP1 SLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 SWAP3 AND SWAP2 DUP4 SWAP1 DUP2 LT PUSH2 0x80C JUMPI INVALID JUMPDEST SWAP1 PUSH1 0x0 MSTORE PUSH1 0x20 PUSH1 0x0 KECCAK256 ADD PUSH1 0x0 PUSH2 0x100 EXP DUP2 SLOAD DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF MUL NOT AND SWAP1 DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND MUL OR SWAP1 SSTORE POP PUSH1 0x2 DUP1 SLOAD DUP1 PUSH2 0x85F JUMPI INVALID JUMPDEST PUSH1 0x0 DUP3 DUP2 MSTORE PUSH1 0x20 DUP2 KECCAK256 DUP3 ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP1 DUP2 ADD DUP1 SLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000000000000000000000000000 AND SWAP1 SSTORE SWAP1 SWAP2 ADD SWAP1 SWAP2 SSTORE PUSH1 0x40 MLOAD CALLER SWAP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP6 AND SWAP2 PUSH32 0x1F32C1B084E2DE0713B8FB16BD46BB9DF710A3DBEAE2F3CA93AF46E016DCC6B0 SWAP2 SWAP1 LOG3 POP POP JUMP JUMPDEST CALLER PUSH1 0x0 SWAP1 DUP2 MSTORE PUSH1 0x1 PUSH1 0x20 MSTORE PUSH1 0x40 SWAP1 KECCAK256 SLOAD PUSH1 0xFF AND PUSH2 0x4AA JUMPI PUSH2 0x4AA PUSH2 0x205 CALLER PUSH2 0xA87 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD SWAP1 SWAP2 MSTORE PUSH1 0x4 DUP2 MSTORE PUSH32 0xE69EDC3E00000000000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 JUMP JUMPDEST PUSH1 0x60 PUSH4 0x1DE45AD1 PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xBB9 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 DUP2 DUP5 SUB ADD DUP2 MSTORE SWAP2 SWAP1 MSTORE PUSH1 0x20 DUP2 ADD DUP1 MLOAD PUSH28 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH32 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 SWAP1 SWAP4 AND SWAP3 SWAP1 SWAP3 OR SWAP1 SWAP2 MSTORE SWAP1 POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD DUP1 DUP3 ADD SWAP1 SWAP2 MSTORE PUSH1 0x4 DUP2 MSTORE PUSH32 0x57654FE400000000000000000000000000000000000000000000000000000000 PUSH1 0x20 DUP3 ADD MSTORE SWAP1 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xDE16F1A0 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xE9F83771 PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xCB6 JUMP JUMPDEST PUSH1 0x60 PUSH4 0x140A84DB PUSH1 0xE0 SHL DUP4 DUP4 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x976 SWAP3 SWAP2 SWAP1 PUSH2 0xBB9 JUMP JUMPDEST PUSH1 0x60 PUSH4 0xB65A25B9 PUSH1 0xE0 SHL DUP3 PUSH1 0x40 MLOAD PUSH1 0x24 ADD PUSH2 0x5F8 SWAP2 SWAP1 PUSH2 0xB98 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xAB3 JUMPI DUP1 DUP2 REVERT JUMPDEST DUP2 CALLDATALOAD PUSH2 0xABE DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP4 SWAP3 POP POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 PUSH1 0x40 DUP5 DUP7 SUB SLT ISZERO PUSH2 0xAD9 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP4 CALLDATALOAD PUSH2 0xAE4 DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP3 POP PUSH1 0x20 DUP5 ADD CALLDATALOAD PUSH8 0xFFFFFFFFFFFFFFFF DUP1 DUP3 GT ISZERO PUSH2 0xB00 JUMPI DUP4 DUP5 REVERT JUMPDEST DUP2 DUP7 ADD SWAP2 POP DUP7 PUSH1 0x1F DUP4 ADD SLT PUSH2 0xB13 JUMPI DUP4 DUP5 REVERT JUMPDEST DUP2 CALLDATALOAD DUP2 DUP2 GT ISZERO PUSH2 0xB21 JUMPI DUP5 DUP6 REVERT JUMPDEST DUP8 PUSH1 0x20 DUP3 DUP6 ADD ADD GT ISZERO PUSH2 0xB32 JUMPI DUP5 DUP6 REVERT JUMPDEST PUSH1 0x20 DUP4 ADD SWAP5 POP DUP1 SWAP4 POP POP POP POP SWAP3 POP SWAP3 POP SWAP3 JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x40 DUP4 DUP6 SUB SLT ISZERO PUSH2 0xB57 JUMPI DUP2 DUP3 REVERT JUMPDEST DUP3 CALLDATALOAD PUSH2 0xB62 DUP2 PUSH2 0xCC4 JUMP JUMPDEST SWAP5 PUSH1 0x20 SWAP4 SWAP1 SWAP4 ADD CALLDATALOAD SWAP4 POP POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xB81 JUMPI DUP1 DUP2 REVERT JUMPDEST POP CALLDATALOAD SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP3 DUP5 DUP4 CALLDATACOPY SWAP2 ADD SWAP1 DUP2 MSTORE SWAP2 SWAP1 POP JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP2 SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF SWAP3 DUP4 AND DUP2 MSTORE SWAP2 AND PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x40 ADD SWAP1 JUMP JUMPDEST PUSH1 0x20 DUP1 DUP3 MSTORE DUP3 MLOAD DUP3 DUP3 ADD DUP2 SWAP1 MSTORE PUSH1 0x0 SWAP2 SWAP1 DUP5 DUP3 ADD SWAP1 PUSH1 0x40 DUP6 ADD SWAP1 DUP5 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xC2E JUMPI DUP4 MLOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP4 MSTORE SWAP3 DUP5 ADD SWAP3 SWAP2 DUP5 ADD SWAP2 PUSH1 0x1 ADD PUSH2 0xBFC JUMP JUMPDEST POP SWAP1 SWAP7 SWAP6 POP POP POP POP POP POP JUMP JUMPDEST SWAP1 ISZERO ISZERO DUP2 MSTORE PUSH1 0x20 ADD SWAP1 JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP1 DUP4 MSTORE DUP4 MLOAD DUP1 DUP3 DUP6 ADD MSTORE DUP3 JUMPDEST DUP2 DUP2 LT ISZERO PUSH2 0xC71 JUMPI DUP6 DUP2 ADD DUP4 ADD MLOAD DUP6 DUP3 ADD PUSH1 0x40 ADD MSTORE DUP3 ADD PUSH2 0xC55 JUMP JUMPDEST DUP2 DUP2 GT ISZERO PUSH2 0xC82 JUMPI DUP4 PUSH1 0x40 DUP4 DUP8 ADD ADD MSTORE JUMPDEST POP PUSH1 0x1F ADD PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 AND SWAP3 SWAP1 SWAP3 ADD PUSH1 0x40 ADD SWAP4 SWAP3 POP POP POP JUMP JUMPDEST SWAP2 DUP3 MSTORE PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x40 ADD SWAP1 JUMP JUMPDEST PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF DUP2 AND DUP2 EQ PUSH2 0x18D JUMPI PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xC6 0x5C 0x26 SWAP2 PUSH19 0x307C3233F41D02063DD36016FA933E6B4E9FF0 0xE9 SELFDESTRUCT 0xDA 0x27 0xB6 0x1F LOG4 SMOD PUSH5 0x736F6C6343 STOP MOD 0xC STOP CALLER LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xF9 0xDC PUSH14 0x46F6AA9A201DB4E1E18A137C2C97 0xB0 0xD7 0xB4 LT CALLCODE SWAP1 DUP1 PUSH15 0x865DB52083E17664736F6C63430006 0xC STOP CALLER ",
"sourceMap": "1098:5841:45:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3183:926;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;1698:41;;;:::i;2486:150::-;;;:::i;4275:314::-;;;;;;:::i;:::-;;:::i;:::-;;3183:926;3372:14;3410:10;:30;3424:16;3410:30;;3402:71;;;;;;;;;;;;:::i;:::-;;;;;;;;;3562:17;;3675:138;;;;;;;;3738:17;;3562;3675:138;;;;;;3782:16;;;;3675:138;;;;;;3562:261;;;;;:17;;;;;:34;;:261;;3634:4;;3655:6;;3675:138;3562:261;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;3859:50;3872:6;3880:5;3887:8;3897:11;3859:12;:50::i;:::-;3969:57;;;;;:50;;;;;;:57;;4020:5;;3969:57;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;4063:15:45;;;;;:4;;-1:-1:-1;4063:8:45;;-1:-1:-1;4063:15:45;;4072:5;;4063:15;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;4096:6:45;;3183:926;-1:-1:-1;;;;;;;3183:926:45:o;1698:41::-;;;:::o;2486:150::-;2560:20;2611:17;;;2486:150;:::o;4275:314::-;4373:10;4395:4;4373:27;4365:68;;;;;;;;;;;;:::i;:::-;4569:12;4556:26;;;4904:2033;5273:21;;5132:6;;5082:23;;5273:21;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;5373:53:45;;;;;5239:55;;-1:-1:-1;5373:36:45;;;;;;:53;;5418:6;;5373:53;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;5519:40:45;;;;;:33;;;;-1:-1:-1;5519:33:45;;-1:-1:-1;5519:40:45;;5553:5;;5519:40;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5610:7;:15;;;5651:8;:21;;;5735:36;;;5793:15;5691:135;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;5610:261;;;;;;;;;;;;;5852:4;;5610:261;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;6016:23:45;;;;6162:31;;6058:153;;5975:15;;;;-1:-1:-1;5975:15:45;;-1:-1:-1;6102:38:45;;6058:153;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;5975:281;;;;;;;;;;;;;6237:4;;5975:281;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;6403:25:45;;;;6447:102;;;;;;;;;;;;;;;;;;;6491:40;6447:102;;;6362:232;;;;;:15;;;;-1:-1:-1;6362:15:45;;:232;;6403:25;;6447:102;6575:4;;6362:232;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;6737:21:45;;;;6777:98;;;;;;;;;;;;;;;;;;;6821:36;6777:98;;;6696:224;;;;;:15;;;;-1:-1:-1;6696:15:45;;:224;;6737:21;;6777:98;6901:4;;6696:224;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4904:2033;;;;;:::o;-1:-1:-1:-;;;;;;;;:::o;295:194::-;394:20;;419:65;394:20;419:65;:::i;:::-;379:110;;;;:::o;3161:342::-;;3279:4;3267:9;3262:3;3258:19;3254:30;3251:2;;;-1:-1;;3287:12;3251:2;3315:20;3279:4;3315:20;:::i;:::-;3306:29;;85:6;72:20;97:33;124:5;97:33;:::i;:::-;3407:75;;3414:16;3245:258;-1:-1;;3245:258::o;3510:257::-;;3622:2;3610:9;3601:7;3597:23;3593:32;3590:2;;;-1:-1;;3628:12;3590:2;230:6;217:20;242:41;277:5;242:41;:::i;:::-;3680:71;3584:183;-1:-1;;;3584:183::o;3774:772::-;;;;;3994:9;3985:7;3981:23;4006:3;3981:23;3977:33;3974:2;;;-1:-1;;4013:12;3974:2;230:6;217:20;242:41;277:5;242:41;:::i;:::-;4065:71;-1:-1;4173:2;4226:22;;1556:20;1581:47;1556:20;1581:47;:::i;:::-;4181:77;-1:-1;1960:4;1939:19;;;1935:30;1932:2;;;-1:-1;;1968:12;1932:2;;1996:20;1960:4;1996:20;:::i;:::-;2102:87;2185:3;4295:2;4364:9;4360:22;2102:87;:::i;:::-;2084:16;2077:113;2287:72;2355:3;2331:22;4364:9;2331:22;2287:72;:::i;:::-;4173:2;2273:5;2269:16;2262:98;2462:77;2535:3;2511:22;4364:9;2511:22;2462:77;:::i;:::-;4295:2;2448:5;2444:16;2437:103;2644:79;2719:3;2695:22;4364:9;2695:22;2644:79;:::i;:::-;2331:22;2630:5;2626:16;2619:105;2831:81;2908:3;1960:4;4364:9;2884:22;2831:81;:::i;:::-;2511:22;2817:5;2813:16;2806:107;3016:77;3089:3;3065:22;4364:9;3065:22;3016:77;:::i;:::-;2695:22;2998:16;;2991:103;3002:5;-1:-1;4448:82;4522:7;4429:3;4498:22;;4448:82;:::i;:::-;4438:92;;3968:578;;;;;;;:::o;4553:291::-;;4682:2;4670:9;4661:7;4657:23;4653:32;4650:2;;;-1:-1;;4688:12;4650:2;1738:6;1732:13;1750:47;1791:5;1750:47;:::i;7341:222::-;12150:42;12139:54;;;;5087:45;;7468:2;7453:18;;7439:124::o;8076:661::-;12150:42;12139:54;;;5087:45;;12139:54;;;8570:2;8555:18;;;5709:74;;;;7003:23;;12139:54;;8723:2;8708:18;;5709:74;7204:16;7198:23;12139:54;;;7298:14;;;5709:74;8367:3;8352:19;;8338:399::o;8744:528::-;;12150:42;;5125:5;12139:54;5094:3;5087:45;9063:2;8945;9063;9052:9;9048:18;9041:48;5406:5;10602:12;10758:6;8945:2;8934:9;8930:18;10746:19;-1:-1;13934:101;13948:6;13945:1;13942:13;13934:101;;;14015:11;;;;;14009:18;13996:11;;;10786:14;13996:11;13989:39;13963:10;;13934:101;;;14050:6;14047:1;14044:13;14041:2;;;-1:-1;10786:14;14106:6;8934:9;14097:16;;14090:27;14041:2;-1:-1;12139:54;;;;9258:2;9243:18;;5087:45;-1:-1;;14226:2;14206:14;;;;14222:7;14202:28;5563:39;10786:14;5563:39;;8916:356;-1:-1;;8916:356::o;9829:416::-;10029:2;10043:47;;;6565:2;10014:18;;;10746:19;6601:30;10786:14;;;6581:51;6651:12;;;10000:245::o;10252:256::-;10314:2;10308:9;10340:17;;;10415:18;10400:34;;10436:22;;;10397:62;10394:2;;;10472:1;;10462:12;10394:2;10314;10481:22;10292:216;;-1:-1;10292:216::o;14243:117::-;12150:42;14330:5;12139:54;14305:5;14302:35;14292:2;;14351:1;;14341:12;14292:2;14286:74;:::o"
},
"methodIdentifiers": {
"die(address)": "c9353cb5",
"getBootstrapper()": "b3d31735",
"initializeCaller()": "5f136a4a",
"migrateZeroEx(address,address,(address,address,address,address,address,address),(address))": "329798a4"
}
}
},
"sourceTreeHashHex": "0x20c40ffa59b6bf2db196611d783ac1d7ff9d2932e9210de09eae2d799e5ab6ad",
"sources": {
"./FullMigration.sol": {
"id": 45,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../ZeroEx.sol\";\nimport \"../features/interfaces/IOwnableFeature.sol\";\nimport \"../features/TokenSpenderFeature.sol\";\nimport \"../features/TransformERC20Feature.sol\";\nimport \"../features/MetaTransactionsFeature.sol\";\nimport \"../features/NativeOrdersFeature.sol\";\nimport \"../external/AllowanceTarget.sol\";\nimport \"./InitialMigration.sol\";\n\n\n/// @dev A contract for deploying and configuring the full ZeroEx contract.\ncontract FullMigration {\n\n // solhint-disable no-empty-blocks,indent\n\n /// @dev Features to add the the proxy contract.\n struct Features {\n SimpleFunctionRegistryFeature registry;\n OwnableFeature ownable;\n TokenSpenderFeature tokenSpender;\n TransformERC20Feature transformERC20;\n MetaTransactionsFeature metaTransactions;\n NativeOrdersFeature nativeOrders;\n }\n\n /// @dev Parameters needed to initialize features.\n struct MigrateOpts {\n address transformerDeployer;\n }\n\n /// @dev The allowed caller of `initializeZeroEx()`.\n address public immutable initializeCaller;\n /// @dev The initial migration contract.\n InitialMigration private _initialMigration;\n\n /// @dev Instantiate this contract and set the allowed caller of `initializeZeroEx()`\n /// to `initializeCaller`.\n /// @param initializeCaller_ The allowed caller of `initializeZeroEx()`.\n constructor(address payable initializeCaller_)\n public\n {\n initializeCaller = initializeCaller_;\n // Create an initial migration contract with this contract set to the\n // allowed `initializeCaller`.\n _initialMigration = new InitialMigration(address(this));\n }\n\n /// @dev Retrieve the bootstrapper address to use when constructing `ZeroEx`.\n /// @return bootstrapper The bootstrapper address.\n function getBootstrapper()\n external\n view\n returns (address bootstrapper)\n {\n return address(_initialMigration);\n }\n\n /// @dev Initialize the `ZeroEx` contract with the full feature set,\n /// transfer ownership to `owner`, then self-destruct.\n /// @param owner The owner of the contract.\n /// @param zeroEx The instance of the ZeroEx contract. ZeroEx should\n /// been constructed with this contract as the bootstrapper.\n /// @param features Features to add to the proxy.\n /// @return _zeroEx The configured ZeroEx contract. Same as the `zeroEx` parameter.\n /// @param migrateOpts Parameters needed to initialize features.\n function migrateZeroEx(\n address payable owner,\n ZeroEx zeroEx,\n Features memory features,\n MigrateOpts memory migrateOpts\n )\n public\n returns (ZeroEx _zeroEx)\n {\n require(msg.sender == initializeCaller, \"FullMigration/INVALID_SENDER\");\n\n // Perform the initial migration with the owner set to this contract.\n _initialMigration.initializeZeroEx(\n address(uint160(address(this))),\n zeroEx,\n InitialMigration.BootstrapFeatures({\n registry: features.registry,\n ownable: features.ownable\n })\n );\n\n // Add features.\n _addFeatures(zeroEx, owner, features, migrateOpts);\n\n // Transfer ownership to the real owner.\n IOwnableFeature(address(zeroEx)).transferOwnership(owner);\n\n // Self-destruct.\n this.die(owner);\n\n return zeroEx;\n }\n\n /// @dev Destroy this contract. Only callable from ourselves (from `initializeZeroEx()`).\n /// @param ethRecipient Receiver of any ETH in this contract.\n function die(address payable ethRecipient)\n external\n virtual\n {\n require(msg.sender == address(this), \"FullMigration/INVALID_SENDER\");\n // This contract should not hold any funds but we send\n // them to the ethRecipient just in case.\n selfdestruct(ethRecipient);\n }\n\n /// @dev Deploy and register features to the ZeroEx contract.\n /// @param zeroEx The bootstrapped ZeroEx contract.\n /// @param owner The ultimate owner of the ZeroEx contract.\n /// @param features Features to add to the proxy.\n /// @param migrateOpts Parameters needed to initialize features.\n function _addFeatures(\n ZeroEx zeroEx,\n address owner,\n Features memory features,\n MigrateOpts memory migrateOpts\n )\n private\n {\n IOwnableFeature ownable = IOwnableFeature(address(zeroEx));\n // TokenSpenderFeature\n {\n // Create the allowance target.\n AllowanceTarget allowanceTarget = new AllowanceTarget();\n // Let the ZeroEx contract use the allowance target.\n allowanceTarget.addAuthorizedAddress(address(zeroEx));\n // Transfer ownership of the allowance target to the (real) owner.\n allowanceTarget.transferOwnership(owner);\n // Register the feature.\n ownable.migrate(\n address(features.tokenSpender),\n abi.encodeWithSelector(\n TokenSpenderFeature.migrate.selector,\n allowanceTarget\n ),\n address(this)\n );\n }\n // TransformERC20Feature\n {\n // Register the feature.\n ownable.migrate(\n address(features.transformERC20),\n abi.encodeWithSelector(\n TransformERC20Feature.migrate.selector,\n migrateOpts.transformerDeployer\n ),\n address(this)\n );\n }\n // MetaTransactionsFeature\n {\n // Register the feature.\n ownable.migrate(\n address(features.metaTransactions),\n abi.encodeWithSelector(\n MetaTransactionsFeature.migrate.selector\n ),\n address(this)\n );\n }\n // NativeOrdersFeature\n {\n // Register the feature.\n ownable.migrate(\n address(features.nativeOrders),\n abi.encodeWithSelector(\n NativeOrdersFeature.migrate.selector\n ),\n address(this)\n );\n }\n }\n}\n"
},
"../ZeroEx.sol": {
"id": 0,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"./migrations/LibBootstrap.sol\";\nimport \"./features/BootstrapFeature.sol\";\nimport \"./storage/LibProxyStorage.sol\";\nimport \"./errors/LibProxyRichErrors.sol\";\n\n\n/// @dev An extensible proxy contract that serves as a universal entry point for\n/// interacting with the 0x protocol.\ncontract ZeroEx {\n // solhint-disable separate-by-one-line-in-contract,indent,var-name-mixedcase\n using LibBytesV06 for bytes;\n\n /// @dev Construct this contract and register the `BootstrapFeature` feature.\n /// After constructing this contract, `bootstrap()` should be called\n /// by `bootstrap()` to seed the initial feature set.\n /// @param bootstrapper Who can call `bootstrap()`.\n constructor(address bootstrapper) public {\n // Temporarily create and register the bootstrap feature.\n // It will deregister itself after `bootstrap()` has been called.\n BootstrapFeature bootstrap = new BootstrapFeature(bootstrapper);\n LibProxyStorage.getStorage().impls[bootstrap.bootstrap.selector] =\n address(bootstrap);\n }\n\n // solhint-disable state-visibility\n\n /// @dev Forwards calls to the appropriate implementation contract.\n fallback() external payable {\n bytes4 selector = msg.data.readBytes4(0);\n address impl = getFunctionImplementation(selector);\n if (impl == address(0)) {\n _revertWithData(LibProxyRichErrors.NotImplementedError(selector));\n }\n\n (bool success, bytes memory resultData) = impl.delegatecall(msg.data);\n if (!success) {\n _revertWithData(resultData);\n }\n _returnWithData(resultData);\n }\n\n /// @dev Fallback for just receiving ether.\n receive() external payable {}\n\n // solhint-enable state-visibility\n\n /// @dev Get the implementation contract of a registered function.\n /// @param selector The function selector.\n /// @return impl The implementation contract address.\n function getFunctionImplementation(bytes4 selector)\n public\n view\n returns (address impl)\n {\n return LibProxyStorage.getStorage().impls[selector];\n }\n\n /// @dev Revert with arbitrary bytes.\n /// @param data Revert data.\n function _revertWithData(bytes memory data) private pure {\n assembly { revert(add(data, 32), mload(data)) }\n }\n\n /// @dev Return with arbitrary bytes.\n /// @param data Return data.\n function _returnWithData(bytes memory data) private pure {\n assembly { return(add(data, 32), mload(data)) }\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol": {
"id": 65,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./errors/LibBytesRichErrorsV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\n\n\nlibrary LibBytesV06 {\n\n using LibBytesV06 for bytes;\n\n /// @dev Gets the memory address for a byte array.\n /// @param input Byte array to lookup.\n /// @return memoryAddress Memory address of byte array. This\n /// points to the header of the byte array which contains\n /// the length.\n function rawAddress(bytes memory input)\n internal\n pure\n returns (uint256 memoryAddress)\n {\n assembly {\n memoryAddress := input\n }\n return memoryAddress;\n }\n\n /// @dev Gets the memory address for the contents of a byte array.\n /// @param input Byte array to lookup.\n /// @return memoryAddress Memory address of the contents of the byte array.\n function contentAddress(bytes memory input)\n internal\n pure\n returns (uint256 memoryAddress)\n {\n assembly {\n memoryAddress := add(input, 32)\n }\n return memoryAddress;\n }\n\n /// @dev Copies `length` bytes from memory location `source` to `dest`.\n /// @param dest memory address to copy bytes to.\n /// @param source memory address to copy bytes from.\n /// @param length number of bytes to copy.\n function memCopy(\n uint256 dest,\n uint256 source,\n uint256 length\n )\n internal\n pure\n {\n if (length < 32) {\n // Handle a partial word by reading destination and masking\n // off the bits we are interested in.\n // This correctly handles overlap, zero lengths and source == dest\n assembly {\n let mask := sub(exp(256, sub(32, length)), 1)\n let s := and(mload(source), not(mask))\n let d := and(mload(dest), mask)\n mstore(dest, or(s, d))\n }\n } else {\n // Skip the O(length) loop when source == dest.\n if (source == dest) {\n return;\n }\n\n // For large copies we copy whole words at a time. The final\n // word is aligned to the end of the range (instead of after the\n // previous) to handle partial words. So a copy will look like this:\n //\n // ####\n // ####\n // ####\n // ####\n //\n // We handle overlap in the source and destination range by\n // changing the copying direction. This prevents us from\n // overwriting parts of source that we still need to copy.\n //\n // This correctly handles source == dest\n //\n if (source > dest) {\n assembly {\n // We subtract 32 from `sEnd` and `dEnd` because it\n // is easier to compare with in the loop, and these\n // are also the addresses we need for copying the\n // last bytes.\n length := sub(length, 32)\n let sEnd := add(source, length)\n let dEnd := add(dest, length)\n\n // Remember the last 32 bytes of source\n // This needs to be done here and not after the loop\n // because we may have overwritten the last bytes in\n // source already due to overlap.\n let last := mload(sEnd)\n\n // Copy whole words front to back\n // Note: the first check is always true,\n // this could have been a do-while loop.\n // solhint-disable-next-line no-empty-blocks\n for {} lt(source, sEnd) {} {\n mstore(dest, mload(source))\n source := add(source, 32)\n dest := add(dest, 32)\n }\n\n // Write the last 32 bytes\n mstore(dEnd, last)\n }\n } else {\n assembly {\n // We subtract 32 from `sEnd` and `dEnd` because those\n // are the starting points when copying a word at the end.\n length := sub(length, 32)\n let sEnd := add(source, length)\n let dEnd := add(dest, length)\n\n // Remember the first 32 bytes of source\n // This needs to be done here and not after the loop\n // because we may have overwritten the first bytes in\n // source already due to overlap.\n let first := mload(source)\n\n // Copy whole words back to front\n // We use a signed comparisson here to allow dEnd to become\n // negative (happens when source and dest < 32). Valid\n // addresses in local memory will never be larger than\n // 2**255, so they can be safely re-interpreted as signed.\n // Note: the first check is always true,\n // this could have been a do-while loop.\n // solhint-disable-next-line no-empty-blocks\n for {} slt(dest, dEnd) {} {\n mstore(dEnd, mload(sEnd))\n sEnd := sub(sEnd, 32)\n dEnd := sub(dEnd, 32)\n }\n\n // Write the first 32 bytes\n mstore(dest, first)\n }\n }\n }\n }\n\n /// @dev Returns a slices from a byte array.\n /// @param b The byte array to take a slice from.\n /// @param from The starting index for the slice (inclusive).\n /// @param to The final index for the slice (exclusive).\n /// @return result The slice containing bytes at indices [from, to)\n function slice(\n bytes memory b,\n uint256 from,\n uint256 to\n )\n internal\n pure\n returns (bytes memory result)\n {\n // Ensure that the from and to positions are valid positions for a slice within\n // the byte array that is being used.\n if (from > to) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,\n from,\n to\n ));\n }\n if (to > b.length) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,\n to,\n b.length\n ));\n }\n\n // Create a new bytes structure and copy contents\n result = new bytes(to - from);\n memCopy(\n result.contentAddress(),\n b.contentAddress() + from,\n result.length\n );\n return result;\n }\n\n /// @dev Returns a slice from a byte array without preserving the input.\n /// When `from == 0`, the original array will match the slice.\n /// In other cases its state will be corrupted.\n /// @param b The byte array to take a slice from. Will be destroyed in the process.\n /// @param from The starting index for the slice (inclusive).\n /// @param to The final index for the slice (exclusive).\n /// @return result The slice containing bytes at indices [from, to)\n function sliceDestructive(\n bytes memory b,\n uint256 from,\n uint256 to\n )\n internal\n pure\n returns (bytes memory result)\n {\n // Ensure that the from and to positions are valid positions for a slice within\n // the byte array that is being used.\n if (from > to) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,\n from,\n to\n ));\n }\n if (to > b.length) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,\n to,\n b.length\n ));\n }\n\n // Create a new bytes structure around [from, to) in-place.\n assembly {\n result := add(b, from)\n mstore(result, sub(to, from))\n }\n return result;\n }\n\n /// @dev Pops the last byte off of a byte array by modifying its length.\n /// @param b Byte array that will be modified.\n /// @return result The byte that was popped off.\n function popLastByte(bytes memory b)\n internal\n pure\n returns (bytes1 result)\n {\n if (b.length == 0) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired,\n b.length,\n 0\n ));\n }\n\n // Store last byte.\n result = b[b.length - 1];\n\n assembly {\n // Decrement length of byte array.\n let newLen := sub(mload(b), 1)\n mstore(b, newLen)\n }\n return result;\n }\n\n /// @dev Tests equality of two byte arrays.\n /// @param lhs First byte array to compare.\n /// @param rhs Second byte array to compare.\n /// @return equal True if arrays are the same. False otherwise.\n function equals(\n bytes memory lhs,\n bytes memory rhs\n )\n internal\n pure\n returns (bool equal)\n {\n // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare.\n // We early exit on unequal lengths, but keccak would also correctly\n // handle this.\n return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs);\n }\n\n /// @dev Reads an address from a position in a byte array.\n /// @param b Byte array containing an address.\n /// @param index Index in byte array of address.\n /// @return result address from byte array.\n function readAddress(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (address result)\n {\n if (b.length < index + 20) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,\n b.length,\n index + 20 // 20 is length of address\n ));\n }\n\n // Add offset to index:\n // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)\n // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)\n index += 20;\n\n // Read address from array memory\n assembly {\n // 1. Add index to address of bytes array\n // 2. Load 32-byte word from memory\n // 3. Apply 20-byte mask to obtain address\n result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff)\n }\n return result;\n }\n\n /// @dev Writes an address into a specific position in a byte array.\n /// @param b Byte array to insert address into.\n /// @param index Index in byte array of address.\n /// @param input Address to put into byte array.\n function writeAddress(\n bytes memory b,\n uint256 index,\n address input\n )\n internal\n pure\n {\n if (b.length < index + 20) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,\n b.length,\n index + 20 // 20 is length of address\n ));\n }\n\n // Add offset to index:\n // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)\n // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)\n index += 20;\n\n // Store address into array memory\n assembly {\n // The address occupies 20 bytes and mstore stores 32 bytes.\n // First fetch the 32-byte word where we'll be storing the address, then\n // apply a mask so we have only the bytes in the word that the address will not occupy.\n // Then combine these bytes with the address and store the 32 bytes back to memory with mstore.\n\n // 1. Add index to address of bytes array\n // 2. Load 32-byte word from memory\n // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address\n let neighbors := and(\n mload(add(b, index)),\n 0xffffffffffffffffffffffff0000000000000000000000000000000000000000\n )\n\n // Make sure input address is clean.\n // (Solidity does not guarantee this)\n input := and(input, 0xffffffffffffffffffffffffffffffffffffffff)\n\n // Store the neighbors and address into memory\n mstore(add(b, index), xor(input, neighbors))\n }\n }\n\n /// @dev Reads a bytes32 value from a position in a byte array.\n /// @param b Byte array containing a bytes32 value.\n /// @param index Index in byte array of bytes32 value.\n /// @return result bytes32 value from byte array.\n function readBytes32(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (bytes32 result)\n {\n if (b.length < index + 32) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,\n b.length,\n index + 32\n ));\n }\n\n // Arrays are prefixed by a 256 bit length parameter\n index += 32;\n\n // Read the bytes32 from array memory\n assembly {\n result := mload(add(b, index))\n }\n return result;\n }\n\n /// @dev Writes a bytes32 into a specific position in a byte array.\n /// @param b Byte array to insert <input> into.\n /// @param index Index in byte array of <input>.\n /// @param input bytes32 to put into byte array.\n function writeBytes32(\n bytes memory b,\n uint256 index,\n bytes32 input\n )\n internal\n pure\n {\n if (b.length < index + 32) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,\n b.length,\n index + 32\n ));\n }\n\n // Arrays are prefixed by a 256 bit length parameter\n index += 32;\n\n // Read the bytes32 from array memory\n assembly {\n mstore(add(b, index), input)\n }\n }\n\n /// @dev Reads a uint256 value from a position in a byte array.\n /// @param b Byte array containing a uint256 value.\n /// @param index Index in byte array of uint256 value.\n /// @return result uint256 value from byte array.\n function readUint256(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (uint256 result)\n {\n result = uint256(readBytes32(b, index));\n return result;\n }\n\n /// @dev Writes a uint256 into a specific position in a byte array.\n /// @param b Byte array to insert <input> into.\n /// @param index Index in byte array of <input>.\n /// @param input uint256 to put into byte array.\n function writeUint256(\n bytes memory b,\n uint256 index,\n uint256 input\n )\n internal\n pure\n {\n writeBytes32(b, index, bytes32(input));\n }\n\n /// @dev Reads an unpadded bytes4 value from a position in a byte array.\n /// @param b Byte array containing a bytes4 value.\n /// @param index Index in byte array of bytes4 value.\n /// @return result bytes4 value from byte array.\n function readBytes4(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (bytes4 result)\n {\n if (b.length < index + 4) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired,\n b.length,\n index + 4\n ));\n }\n\n // Arrays are prefixed by a 32 byte length field\n index += 32;\n\n // Read the bytes4 from array memory\n assembly {\n result := mload(add(b, index))\n // Solidity does not require us to clean the trailing bytes.\n // We do it anyway\n result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)\n }\n return result;\n }\n\n /// @dev Writes a new length to a byte array.\n /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array.\n /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array.\n /// @param b Bytes array to write new length to.\n /// @param length New length of byte array.\n function writeLength(bytes memory b, uint256 length)\n internal\n pure\n {\n assembly {\n mstore(b, length)\n }\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibBytesRichErrorsV06.sol": {
"id": 70,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibBytesRichErrorsV06 {\n\n enum InvalidByteOperationErrorCodes {\n FromLessThanOrEqualsToRequired,\n ToLessThanOrEqualsLengthRequired,\n LengthGreaterThanZeroRequired,\n LengthGreaterThanOrEqualsFourRequired,\n LengthGreaterThanOrEqualsTwentyRequired,\n LengthGreaterThanOrEqualsThirtyTwoRequired,\n LengthGreaterThanOrEqualsNestedBytesLengthRequired,\n DestinationLengthGreaterThanOrEqualSourceLengthRequired\n }\n\n // bytes4(keccak256(\"InvalidByteOperationError(uint8,uint256,uint256)\"))\n bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR =\n 0x28006595;\n\n // solhint-disable func-name-mixedcase\n function InvalidByteOperationError(\n InvalidByteOperationErrorCodes errorCode,\n uint256 offset,\n uint256 required\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n INVALID_BYTE_OPERATION_ERROR_SELECTOR,\n errorCode,\n offset,\n required\n );\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol": {
"id": 73,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibRichErrorsV06 {\n\n // bytes4(keccak256(\"Error(string)\"))\n bytes4 internal constant STANDARD_ERROR_SELECTOR = 0x08c379a0;\n\n // solhint-disable func-name-mixedcase\n /// @dev ABI encode a standard, string revert error payload.\n /// This is the same payload that would be included by a `revert(string)`\n /// solidity statement. It has the function signature `Error(string)`.\n /// @param message The error string.\n /// @return The ABI encoded error.\n function StandardError(string memory message)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n STANDARD_ERROR_SELECTOR,\n bytes(message)\n );\n }\n // solhint-enable func-name-mixedcase\n\n /// @dev Reverts an encoded rich revert reason `errorData`.\n /// @param errorData ABI encoded error data.\n function rrevert(bytes memory errorData)\n internal\n pure\n {\n assembly {\n revert(add(errorData, 0x20), mload(errorData))\n }\n }\n}\n"
},
"./LibBootstrap.sol": {
"id": 47,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibProxyRichErrors.sol\";\n\n\nlibrary LibBootstrap {\n\n /// @dev Magic bytes returned by the bootstrapper to indicate success.\n /// This is `keccack('BOOTSTRAP_SUCCESS')`.\n bytes4 internal constant BOOTSTRAP_SUCCESS = 0xd150751b;\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Perform a delegatecall and ensure it returns the magic bytes.\n /// @param target The call target.\n /// @param data The call data.\n function delegatecallBootstrapFunction(\n address target,\n bytes memory data\n )\n internal\n {\n (bool success, bytes memory resultData) = target.delegatecall(data);\n if (!success ||\n resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != BOOTSTRAP_SUCCESS)\n {\n LibProxyRichErrors.BootstrapCallFailedError(target, resultData).rrevert();\n }\n }\n}\n"
},
"../errors/LibProxyRichErrors.sol": {
"id": 5,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibProxyRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function NotImplementedError(bytes4 selector)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NotImplementedError(bytes4)\")),\n selector\n );\n }\n\n function InvalidBootstrapCallerError(address actual, address expected)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidBootstrapCallerError(address,address)\")),\n actual,\n expected\n );\n }\n\n function InvalidDieCallerError(address actual, address expected)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidDieCallerError(address,address)\")),\n actual,\n expected\n );\n }\n\n function BootstrapCallFailedError(address target, bytes memory resultData)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"BootstrapCallFailedError(address,bytes)\")),\n target,\n resultData\n );\n }\n}\n"
},
"../features/BootstrapFeature.sol": {
"id": 18,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"../storage/LibProxyStorage.sol\";\nimport \"./interfaces/IBootstrapFeature.sol\";\n\n\n/// @dev Detachable `bootstrap()` feature.\ncontract BootstrapFeature is\n IBootstrapFeature\n{\n // solhint-disable state-visibility,indent\n /// @dev The ZeroEx contract.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _deployer;\n /// @dev The implementation address of this contract.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _implementation;\n /// @dev The deployer.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _bootstrapCaller;\n // solhint-enable state-visibility,indent\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Construct this contract and set the bootstrap migration contract.\n /// After constructing this contract, `bootstrap()` should be called\n /// to seed the initial feature set.\n /// @param bootstrapCaller The allowed caller of `bootstrap()`.\n constructor(address bootstrapCaller) public {\n _deployer = msg.sender;\n _implementation = address(this);\n _bootstrapCaller = bootstrapCaller;\n }\n\n /// @dev Bootstrap the initial feature set of this contract by delegatecalling\n /// into `target`. Before exiting the `bootstrap()` function will\n /// deregister itself from the proxy to prevent being called again.\n /// @param target The bootstrapper contract address.\n /// @param callData The call data to execute on `target`.\n function bootstrap(address target, bytes calldata callData) external override {\n // Only the bootstrap caller can call this function.\n if (msg.sender != _bootstrapCaller) {\n LibProxyRichErrors.InvalidBootstrapCallerError(\n msg.sender,\n _bootstrapCaller\n ).rrevert();\n }\n // Deregister.\n LibProxyStorage.getStorage().impls[this.bootstrap.selector] = address(0);\n // Self-destruct.\n BootstrapFeature(_implementation).die();\n // Call the bootstrapper.\n LibBootstrap.delegatecallBootstrapFunction(target, callData);\n }\n\n /// @dev Self-destructs this contract.\n /// Can only be called by the deployer.\n function die() external {\n assert(address(this) == _implementation);\n if (msg.sender != _deployer) {\n LibProxyRichErrors.InvalidDieCallerError(msg.sender, _deployer).rrevert();\n }\n selfdestruct(msg.sender);\n }\n}\n"
},
"../storage/LibProxyStorage.sol": {
"id": 52,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the proxy contract.\nlibrary LibProxyStorage {\n\n /// @dev Storage bucket for proxy contract.\n struct Storage {\n // Mapping of function selector -> function implementation\n mapping(bytes4 => address) impls;\n // The owner of the proxy contract.\n address owner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.Proxy\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../storage/LibStorage.sol": {
"id": 55,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Common storage helpers\nlibrary LibStorage {\n\n /// @dev What to bit-shift a storage ID by to get its slot.\n /// This gives us a maximum of 2**128 inline fields in each bucket.\n uint256 private constant STORAGE_SLOT_EXP = 128;\n\n /// @dev Storage IDs for feature storage buckets.\n /// WARNING: APPEND-ONLY.\n enum StorageId {\n Proxy,\n SimpleFunctionRegistry,\n Ownable,\n TokenSpender,\n TransformERC20,\n MetaTransactions,\n ReentrancyGuard,\n NativeOrders\n }\n\n /// @dev Get the storage slot given a storage ID. We assign unique, well-spaced\n /// slots to storage bucket variables to ensure they do not overlap.\n /// See: https://solidity.readthedocs.io/en/v0.6.6/assembly.html#access-to-external-variables-functions-and-libraries\n /// @param storageId An entry in `StorageId`\n /// @return slot The storage slot.\n function getStorageSlot(StorageId storageId)\n internal\n pure\n returns (uint256 slot)\n {\n // This should never overflow with a reasonable `STORAGE_SLOT_EXP`\n // because Solidity will do a range check on `storageId` during the cast.\n return (uint256(storageId) + 1) << STORAGE_SLOT_EXP;\n }\n}\n"
},
"../features/interfaces/IBootstrapFeature.sol": {
"id": 25,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Detachable `bootstrap()` feature.\ninterface IBootstrapFeature {\n\n /// @dev Bootstrap the initial feature set of this contract by delegatecalling\n /// into `target`. Before exiting the `bootstrap()` function will\n /// deregister itself from the proxy to prevent being called again.\n /// @param target The bootstrapper contract address.\n /// @param callData The call data to execute on `target`.\n function bootstrap(address target, bytes calldata callData) external;\n}\n"
},
"../features/interfaces/IOwnableFeature.sol": {
"id": 30,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol\";\n\n\n// solhint-disable no-empty-blocks\n/// @dev Owner management and migration features.\ninterface IOwnableFeature is\n IOwnableV06\n{\n /// @dev Emitted when `migrate()` is called.\n /// @param caller The caller of `migrate()`.\n /// @param migrator The migration contract.\n /// @param newOwner The address of the new owner.\n event Migrated(address caller, address migrator, address newOwner);\n\n /// @dev Execute a migration function in the context of the ZeroEx contract.\n /// The result of the function being called should be the magic bytes\n /// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.\n /// The owner will be temporarily set to `address(this)` inside the call.\n /// Before returning, the owner will be set to `newOwner`.\n /// @param target The migrator contract address.\n /// @param newOwner The address of the new owner.\n /// @param data The call data.\n function migrate(address target, bytes calldata data, address newOwner) external;\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol": {
"id": 76,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\ninterface IOwnableV06 {\n\n /// @dev Emitted by Ownable when ownership is transferred.\n /// @param previousOwner The previous owner of the contract.\n /// @param newOwner The new owner of the contract.\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /// @dev Transfers ownership of the contract to a new address.\n /// @param newOwner The address that will become the owner.\n function transferOwnership(address newOwner) external;\n\n /// @dev The owner of this contract.\n /// @return ownerAddress The owner address.\n function owner() external view returns (address ownerAddress);\n}\n"
},
"../features/TokenSpenderFeature.sol": {
"id": 23,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../external/IAllowanceTarget.sol\";\nimport \"../storage/LibTokenSpenderStorage.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ITokenSpenderFeature.sol\";\n\n\n/// @dev Feature that allows spending token allowances.\ncontract TokenSpenderFeature is\n IFeature,\n ITokenSpenderFeature,\n FixinCommon\n{\n // solhint-disable\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"TokenSpender\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n // solhint-enable\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initialize and register this feature. Should be delegatecalled\n /// into during a `Migrate.migrate()`.\n /// @param allowanceTarget An `allowanceTarget` instance, configured to have\n /// the ZeroeEx contract as an authority.\n /// @return success `MIGRATE_SUCCESS` on success.\n function migrate(IAllowanceTarget allowanceTarget)\n external\n returns (bytes4 success)\n {\n LibTokenSpenderStorage.getStorage().allowanceTarget = allowanceTarget;\n _registerFeatureFunction(this.getAllowanceTarget.selector);\n _registerFeatureFunction(this._spendERC20Tokens.selector);\n _registerFeatureFunction(this.getSpendableERC20BalanceOf.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`. Only callable from within.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _spendERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n external\n override\n onlySelf\n {\n IAllowanceTarget spender = LibTokenSpenderStorage.getStorage().allowanceTarget;\n // Have the allowance target execute an ERC20 `transferFrom()`.\n (bool didSucceed, bytes memory resultData) = address(spender).call(\n abi.encodeWithSelector(\n IAllowanceTarget.executeCall.selector,\n address(token),\n abi.encodeWithSelector(\n IERC20TokenV06.transferFrom.selector,\n owner,\n to,\n amount\n )\n )\n );\n if (didSucceed) {\n resultData = abi.decode(resultData, (bytes));\n }\n if (!didSucceed || !LibERC20TokenV06.isSuccessfulResult(resultData)) {\n LibSpenderRichErrors.SpenderERC20TransferFromFailedError(\n address(token),\n owner,\n to,\n amount,\n resultData\n ).rrevert();\n }\n }\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner` by the token spender.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function getSpendableERC20BalanceOf(IERC20TokenV06 token, address owner)\n external\n override\n view\n returns (uint256 amount)\n {\n return LibSafeMathV06.min256(\n token.allowance(owner, address(LibTokenSpenderStorage.getStorage().allowanceTarget)),\n token.balanceOf(owner)\n );\n }\n\n /// @dev Get the address of the allowance target.\n /// @return target The target of token allowances.\n function getAllowanceTarget()\n external\n override\n view\n returns (address target)\n {\n return address(LibTokenSpenderStorage.getStorage().allowanceTarget);\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol": {
"id": 67,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibSafeMathRichErrorsV06.sol\";\n\n\nlibrary LibSafeMathV06 {\n\n function safeMul(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (a == 0) {\n return 0;\n }\n uint256 c = a * b;\n if (c / a != b) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function safeDiv(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (b == 0) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO,\n a,\n b\n ));\n }\n uint256 c = a / b;\n return c;\n }\n\n function safeSub(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (b > a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,\n a,\n b\n ));\n }\n return a - b;\n }\n\n function safeAdd(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n uint256 c = a + b;\n if (c < a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function max256(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n return a >= b ? a : b;\n }\n\n function min256(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n return a < b ? a : b;\n }\n\n function safeMul128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (a == 0) {\n return 0;\n }\n uint128 c = a * b;\n if (c / a != b) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function safeDiv128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (b == 0) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO,\n a,\n b\n ));\n }\n uint128 c = a / b;\n return c;\n }\n\n function safeSub128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (b > a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,\n a,\n b\n ));\n }\n return a - b;\n }\n\n function safeAdd128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n uint128 c = a + b;\n if (c < a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function max128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n return a >= b ? a : b;\n }\n\n function min128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n return a < b ? a : b;\n }\n\n function safeDowncastToUint128(uint256 a)\n internal\n pure\n returns (uint128)\n {\n if (a > type(uint128).max) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256DowncastError(\n LibSafeMathRichErrorsV06.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128,\n a\n ));\n }\n return uint128(a);\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibSafeMathRichErrorsV06.sol": {
"id": 74,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSafeMathRichErrorsV06 {\n\n // bytes4(keccak256(\"Uint256BinOpError(uint8,uint256,uint256)\"))\n bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR =\n 0xe946c1bb;\n\n // bytes4(keccak256(\"Uint256DowncastError(uint8,uint256)\"))\n bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR =\n 0xc996af7b;\n\n enum BinOpErrorCodes {\n ADDITION_OVERFLOW,\n MULTIPLICATION_OVERFLOW,\n SUBTRACTION_UNDERFLOW,\n DIVISION_BY_ZERO\n }\n\n enum DowncastErrorCodes {\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128\n }\n\n // solhint-disable func-name-mixedcase\n function Uint256BinOpError(\n BinOpErrorCodes errorCode,\n uint256 a,\n uint256 b\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n UINT256_BINOP_ERROR_SELECTOR,\n errorCode,\n a,\n b\n );\n }\n\n function Uint256DowncastError(\n DowncastErrorCodes errorCode,\n uint256 a\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n UINT256_DOWNCAST_ERROR_SELECTOR,\n errorCode,\n a\n );\n }\n}\n"
},
"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol": {
"id": 61,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\ninterface IERC20TokenV06 {\n\n // solhint-disable no-simple-event-func-name\n event Transfer(\n address indexed from,\n address indexed to,\n uint256 value\n );\n\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n\n /// @dev send `value` token to `to` from `msg.sender`\n /// @param to The address of the recipient\n /// @param value The amount of token to be transferred\n /// @return True if transfer was successful\n function transfer(address to, uint256 value)\n external\n returns (bool);\n\n /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`\n /// @param from The address of the sender\n /// @param to The address of the recipient\n /// @param value The amount of token to be transferred\n /// @return True if transfer was successful\n function transferFrom(\n address from,\n address to,\n uint256 value\n )\n external\n returns (bool);\n\n /// @dev `msg.sender` approves `spender` to spend `value` tokens\n /// @param spender The address of the account able to transfer the tokens\n /// @param value The amount of wei to be approved for transfer\n /// @return Always true if the call has enough gas to complete execution\n function approve(address spender, uint256 value)\n external\n returns (bool);\n\n /// @dev Query total supply of token\n /// @return Total supply of token\n function totalSupply()\n external\n view\n returns (uint256);\n\n /// @dev Get the balance of `owner`.\n /// @param owner The address from which the balance will be retrieved\n /// @return Balance of owner\n function balanceOf(address owner)\n external\n view\n returns (uint256);\n\n /// @dev Get the allowance for `spender` to spend from `owner`.\n /// @param owner The address of the account owning tokens\n /// @param spender The address of the account able to transfer the tokens\n /// @return Amount of remaining tokens allowed to spent\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /// @dev Get the number of decimals this token has.\n function decimals()\n external\n view\n returns (uint8);\n}\n"
},
"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol": {
"id": 63,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"./IERC20TokenV06.sol\";\n\n\nlibrary LibERC20TokenV06 {\n bytes constant private DECIMALS_CALL_DATA = hex\"313ce567\";\n\n /// @dev Calls `IERC20TokenV06(token).approve()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param spender The address that receives an allowance.\n /// @param allowance The allowance to set.\n function compatApprove(\n IERC20TokenV06 token,\n address spender,\n uint256 allowance\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.approve.selector,\n spender,\n allowance\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Calls `IERC20TokenV06(token).approve()` and sets the allowance to the\n /// maximum if the current approval is not already >= an amount.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param spender The address that receives an allowance.\n /// @param amount The minimum allowance needed.\n function approveIfBelow(\n IERC20TokenV06 token,\n address spender,\n uint256 amount\n )\n internal\n {\n if (token.allowance(address(this), spender) < amount) {\n compatApprove(token, spender, uint256(-1));\n }\n }\n\n /// @dev Calls `IERC20TokenV06(token).transfer()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param to The address that receives the tokens\n /// @param amount Number of tokens to transfer.\n function compatTransfer(\n IERC20TokenV06 token,\n address to,\n uint256 amount\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.transfer.selector,\n to,\n amount\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Calls `IERC20TokenV06(token).transferFrom()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param from The owner of the tokens.\n /// @param to The address that receives the tokens\n /// @param amount Number of tokens to transfer.\n function compatTransferFrom(\n IERC20TokenV06 token,\n address from,\n address to,\n uint256 amount\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.transferFrom.selector,\n from,\n to,\n amount\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Retrieves the number of decimals for a token.\n /// Returns `18` if the call reverts.\n /// @param token The address of the token contract.\n /// @return tokenDecimals The number of decimals places for the token.\n function compatDecimals(IERC20TokenV06 token)\n internal\n view\n returns (uint8 tokenDecimals)\n {\n tokenDecimals = 18;\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA);\n if (didSucceed && resultData.length >= 32) {\n tokenDecimals = uint8(LibBytesV06.readUint256(resultData, 0));\n }\n }\n\n /// @dev Retrieves the allowance for a token, owner, and spender.\n /// Returns `0` if the call reverts.\n /// @param token The address of the token contract.\n /// @param owner The owner of the tokens.\n /// @param spender The address the spender.\n /// @return allowance_ The allowance for a token, owner, and spender.\n function compatAllowance(IERC20TokenV06 token, address owner, address spender)\n internal\n view\n returns (uint256 allowance_)\n {\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(\n abi.encodeWithSelector(\n token.allowance.selector,\n owner,\n spender\n )\n );\n if (didSucceed && resultData.length >= 32) {\n allowance_ = LibBytesV06.readUint256(resultData, 0);\n }\n }\n\n /// @dev Retrieves the balance for a token owner.\n /// Returns `0` if the call reverts.\n /// @param token The address of the token contract.\n /// @param owner The owner of the tokens.\n /// @return balance The token balance of an owner.\n function compatBalanceOf(IERC20TokenV06 token, address owner)\n internal\n view\n returns (uint256 balance)\n {\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(\n abi.encodeWithSelector(\n token.balanceOf.selector,\n owner\n )\n );\n if (didSucceed && resultData.length >= 32) {\n balance = LibBytesV06.readUint256(resultData, 0);\n }\n }\n\n /// @dev Check if the data returned by a non-static call to an ERC20 token\n /// is a successful result. Supported functions are `transfer()`,\n /// `transferFrom()`, and `approve()`.\n /// @param resultData The raw data returned by a non-static call to the ERC20 token.\n /// @return isSuccessful Whether the result data indicates success.\n function isSuccessfulResult(bytes memory resultData)\n internal\n pure\n returns (bool isSuccessful)\n {\n if (resultData.length == 0) {\n return true;\n }\n if (resultData.length >= 32) {\n uint256 result = LibBytesV06.readUint256(resultData, 0);\n if (result == 1) {\n return true;\n }\n }\n }\n\n /// @dev Executes a call on address `target` with calldata `callData`\n /// and asserts that either nothing was returned or a single boolean\n /// was returned equal to `true`.\n /// @param target The call target.\n /// @param callData The abi-encoded call data.\n function _callWithOptionalBooleanResult(\n address target,\n bytes memory callData\n )\n private\n {\n (bool didSucceed, bytes memory resultData) = target.call(callData);\n if (didSucceed && isSuccessfulResult(resultData)) {\n return;\n }\n LibRichErrorsV06.rrevert(resultData);\n }\n}\n"
},
"../errors/LibSpenderRichErrors.sol": {
"id": 8,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSpenderRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function SpenderERC20TransferFromFailedError(\n address token,\n address owner,\n address to,\n uint256 amount,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SpenderERC20TransferFromFailedError(address,address,address,uint256,bytes)\")),\n token,\n owner,\n to,\n amount,\n errorData\n );\n }\n}\n"
},
"../fixins/FixinCommon.sol": {
"id": 40,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\nimport \"../features/interfaces/IOwnableFeature.sol\";\nimport \"../features/interfaces/ISimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Common feature utilities.\nabstract contract FixinCommon {\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev The implementation address of this feature.\n address internal immutable _implementation;\n\n /// @dev The caller must be this contract.\n modifier onlySelf() virtual {\n if (msg.sender != address(this)) {\n LibCommonRichErrors.OnlyCallableBySelfError(msg.sender).rrevert();\n }\n _;\n }\n\n /// @dev The caller of this function must be the owner.\n modifier onlyOwner() virtual {\n {\n address owner = IOwnableFeature(address(this)).owner();\n if (msg.sender != owner) {\n LibOwnableRichErrors.OnlyOwnerError(\n msg.sender,\n owner\n ).rrevert();\n }\n }\n _;\n }\n\n constructor() internal {\n // Remember this feature's original address.\n _implementation = address(this);\n }\n\n /// @dev Registers a function implemented by this feature at `_implementation`.\n /// Can and should only be called within a `migrate()`.\n /// @param selector The selector of the function whose implementation\n /// is at `_implementation`.\n function _registerFeatureFunction(bytes4 selector)\n internal\n {\n ISimpleFunctionRegistryFeature(address(this)).extend(selector, _implementation);\n }\n\n /// @dev Encode a feature version as a `uint256`.\n /// @param major The major version number of the feature.\n /// @param minor The minor version number of the feature.\n /// @param revision The revision number of the feature.\n /// @return encodedVersion The encoded version number.\n function _encodeVersion(uint32 major, uint32 minor, uint32 revision)\n internal\n pure\n returns (uint256 encodedVersion)\n {\n return (uint256(major) << 64) | (uint256(minor) << 32) | uint256(revision);\n }\n}\n"
},
"../errors/LibCommonRichErrors.sol": {
"id": 1,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibCommonRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function OnlyCallableBySelfError(address sender)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyCallableBySelfError(address)\")),\n sender\n );\n }\n\n function IllegalReentrancyError(bytes4 selector, uint256 reentrancyFlags)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IllegalReentrancyError(bytes4,uint256)\")),\n selector,\n reentrancyFlags\n );\n }\n}\n"
},
"../errors/LibOwnableRichErrors.sol": {
"id": 4,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibOwnableRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function OnlyOwnerError(\n address sender,\n address owner\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyOwnerError(address,address)\")),\n sender,\n owner\n );\n }\n\n function TransferOwnerToZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"TransferOwnerToZeroError()\"))\n );\n }\n\n function MigrateCallFailedError(address target, bytes memory resultData)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MigrateCallFailedError(address,bytes)\")),\n target,\n resultData\n );\n }\n}\n"
},
"../features/interfaces/ISimpleFunctionRegistryFeature.sol": {
"id": 31,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Basic registry management features.\ninterface ISimpleFunctionRegistryFeature {\n\n /// @dev A function implementation was updated via `extend()` or `rollback()`.\n /// @param selector The function selector.\n /// @param oldImpl The implementation contract address being replaced.\n /// @param newImpl The replacement implementation contract address.\n event ProxyFunctionUpdated(bytes4 indexed selector, address oldImpl, address newImpl);\n\n /// @dev Roll back to a prior implementation of a function.\n /// @param selector The function selector.\n /// @param targetImpl The address of an older implementation of the function.\n function rollback(bytes4 selector, address targetImpl) external;\n\n /// @dev Register or replace a function.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function extend(bytes4 selector, address impl) external;\n\n /// @dev Retrieve the length of the rollback history for a function.\n /// @param selector The function selector.\n /// @return rollbackLength The number of items in the rollback history for\n /// the function.\n function getRollbackLength(bytes4 selector)\n external\n view\n returns (uint256 rollbackLength);\n\n /// @dev Retrieve an entry in the rollback history for a function.\n /// @param selector The function selector.\n /// @param idx The index in the rollback history.\n /// @return impl An implementation address for the function at\n /// index `idx`.\n function getRollbackEntryAtIndex(bytes4 selector, uint256 idx)\n external\n view\n returns (address impl);\n}\n"
},
"./LibMigrate.sol": {
"id": 48,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\n\n\nlibrary LibMigrate {\n\n /// @dev Magic bytes returned by a migrator to indicate success.\n /// This is `keccack('MIGRATE_SUCCESS')`.\n bytes4 internal constant MIGRATE_SUCCESS = 0x2c64c5ef;\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Perform a delegatecall and ensure it returns the magic bytes.\n /// @param target The call target.\n /// @param data The call data.\n function delegatecallMigrateFunction(\n address target,\n bytes memory data\n )\n internal\n {\n (bool success, bytes memory resultData) = target.delegatecall(data);\n if (!success ||\n resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != MIGRATE_SUCCESS)\n {\n LibOwnableRichErrors.MigrateCallFailedError(target, resultData).rrevert();\n }\n }\n}\n"
},
"../external/IAllowanceTarget.sol": {
"id": 15,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IAuthorizableV06.sol\";\n\n\n/// @dev The allowance target for the TokenSpender feature.\ninterface IAllowanceTarget is\n IAuthorizableV06\n{\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData\n )\n external\n returns (bytes memory resultData);\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/interfaces/IAuthorizableV06.sol": {
"id": 75,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./IOwnableV06.sol\";\n\n\ninterface IAuthorizableV06 is\n IOwnableV06\n{\n // Event logged when a new address is authorized.\n event AuthorizedAddressAdded(\n address indexed target,\n address indexed caller\n );\n\n // Event logged when a currently authorized address is unauthorized.\n event AuthorizedAddressRemoved(\n address indexed target,\n address indexed caller\n );\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function addAuthorizedAddress(address target)\n external;\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n function removeAuthorizedAddress(address target)\n external;\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n external;\n\n /// @dev Gets all authorized addresses.\n /// @return authorizedAddresses Array of authorized addresses.\n function getAuthorizedAddresses()\n external\n view\n returns (address[] memory authorizedAddresses);\n\n /// @dev Whether an adderss is authorized to call privileged functions.\n /// @param addr Address to query.\n /// @return isAuthorized Whether the address is authorized.\n function authorized(address addr) external view returns (bool isAuthorized);\n\n /// @dev All addresseses authorized to call privileged functions.\n /// @param idx Index of authorized address.\n /// @return addr Authorized address.\n function authorities(uint256 idx) external view returns (address addr);\n\n}\n"
},
"../storage/LibTokenSpenderStorage.sol": {
"id": 56,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IAllowanceTarget.sol\";\n\n\n/// @dev Storage helpers for the `TokenSpender` feature.\nlibrary LibTokenSpenderStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Allowance target contract.\n IAllowanceTarget allowanceTarget;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.TokenSpender\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../features/interfaces/IFeature.sol": {
"id": 26,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Basic interface for a feature contract.\ninterface IFeature {\n\n // solhint-disable func-name-mixedcase\n\n /// @dev The name of this feature set.\n function FEATURE_NAME() external view returns (string memory name);\n\n /// @dev The version of this feature set.\n function FEATURE_VERSION() external view returns (uint256 version);\n}\n"
},
"../features/interfaces/ITokenSpenderFeature.sol": {
"id": 32,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\n\n\n/// @dev Feature that allows spending token allowances.\ninterface ITokenSpenderFeature {\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`.\n /// Only callable from within.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _spendERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n external;\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner`.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function getSpendableERC20BalanceOf(IERC20TokenV06 token, address owner)\n external\n view\n returns (uint256 amount);\n\n /// @dev Get the address of the allowance target.\n /// @return target The target of token allowances.\n function getAllowanceTarget() external view returns (address target);\n}\n"
},
"../features/TransformERC20Feature.sol": {
"id": 24,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../errors/LibTransformERC20RichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../fixins/FixinTokenSpender.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../external/IFlashWallet.sol\";\nimport \"../external/FlashWallet.sol\";\nimport \"../storage/LibTransformERC20Storage.sol\";\nimport \"../transformers/IERC20Transformer.sol\";\nimport \"../transformers/LibERC20Transformer.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ITransformERC20Feature.sol\";\n\n\n/// @dev Feature to composably transform between ERC20 tokens.\ncontract TransformERC20Feature is\n IFeature,\n ITransformERC20Feature,\n FixinCommon,\n FixinTokenSpender\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Stack vars for `_transformERC20Private()`.\n struct TransformERC20PrivateState {\n IFlashWallet wallet;\n address transformerDeployer;\n uint256 takerOutputTokenBalanceBefore;\n uint256 takerOutputTokenBalanceAfter;\n }\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"TransformERC20\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 3, 1);\n\n constructor(bytes32 greedyTokensBloomFilter)\n public\n FixinTokenSpender(greedyTokensBloomFilter)\n {}\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @param transformerDeployer The trusted deployer for transformers.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate(address transformerDeployer)\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.getTransformerDeployer.selector);\n _registerFeatureFunction(this.createTransformWallet.selector);\n _registerFeatureFunction(this.getTransformWallet.selector);\n _registerFeatureFunction(this.setTransformerDeployer.selector);\n _registerFeatureFunction(this.setQuoteSigner.selector);\n _registerFeatureFunction(this.getQuoteSigner.selector);\n _registerFeatureFunction(this.transformERC20.selector);\n _registerFeatureFunction(this._transformERC20.selector);\n if (this.getTransformWallet() == IFlashWallet(address(0))) {\n // Create the transform wallet if it doesn't exist.\n this.createTransformWallet();\n }\n LibTransformERC20Storage.getStorage().transformerDeployer = transformerDeployer;\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Replace the allowed deployer for transformers.\n /// Only callable by the owner.\n /// @param transformerDeployer The address of the trusted deployer for transformers.\n function setTransformerDeployer(address transformerDeployer)\n external\n override\n onlyOwner\n {\n LibTransformERC20Storage.getStorage().transformerDeployer = transformerDeployer;\n emit TransformerDeployerUpdated(transformerDeployer);\n }\n\n /// @dev Replace the optional signer for `transformERC20()` calldata.\n /// Only callable by the owner.\n /// @param quoteSigner The address of the new calldata signer.\n function setQuoteSigner(address quoteSigner)\n external\n override\n onlyOwner\n {\n LibTransformERC20Storage.getStorage().quoteSigner = quoteSigner;\n emit QuoteSignerUpdated(quoteSigner);\n }\n\n /// @dev Return the allowed deployer for transformers.\n /// @return deployer The transform deployer address.\n function getTransformerDeployer()\n public\n override\n view\n returns (address deployer)\n {\n return LibTransformERC20Storage.getStorage().transformerDeployer;\n }\n\n /// @dev Return the optional signer for `transformERC20()` calldata.\n /// @return signer The signer address.\n function getQuoteSigner()\n public\n override\n view\n returns (address signer)\n {\n return LibTransformERC20Storage.getStorage().quoteSigner;\n }\n\n /// @dev Deploy a new wallet instance and replace the current one with it.\n /// Useful if we somehow break the current wallet instance.\n /// Only callable by the owner.\n /// @return wallet The new wallet instance.\n function createTransformWallet()\n public\n override\n onlyOwner\n returns (IFlashWallet wallet)\n {\n wallet = new FlashWallet();\n LibTransformERC20Storage.getStorage().wallet = wallet;\n }\n\n /// @dev Executes a series of transformations to convert an ERC20 `inputToken`\n /// to an ERC20 `outputToken`.\n /// @param inputToken The token being provided by the sender.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the sender.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the sender.\n /// If set to `uint256(-1)`, the entire spendable balance of the taker\n /// will be solt.\n /// @param minOutputTokenAmount The minimum amount of `outputToken` the sender\n /// must receive for the entire transformation to succeed. If set to zero,\n /// the minimum output token transfer will not be asserted.\n /// @param transformations The transformations to execute on the token balance(s)\n /// in sequence.\n /// @return outputTokenAmount The amount of `outputToken` received by the sender.\n function transformERC20(\n IERC20TokenV06 inputToken,\n IERC20TokenV06 outputToken,\n uint256 inputTokenAmount,\n uint256 minOutputTokenAmount,\n Transformation[] memory transformations\n )\n public\n override\n payable\n returns (uint256 outputTokenAmount)\n {\n return _transformERC20Private(\n TransformERC20Args({\n taker: msg.sender,\n inputToken: inputToken,\n outputToken: outputToken,\n inputTokenAmount: inputTokenAmount,\n minOutputTokenAmount: minOutputTokenAmount,\n transformations: transformations\n })\n );\n }\n\n /// @dev Internal version of `transformERC20()`. Only callable from within.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20(TransformERC20Args memory args)\n public\n virtual\n override\n payable\n onlySelf\n returns (uint256 outputTokenAmount)\n {\n return _transformERC20Private(args);\n }\n\n /// @dev Private version of `transformERC20()`.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20Private(TransformERC20Args memory args)\n private\n returns (uint256 outputTokenAmount)\n {\n // If the input token amount is -1 and we are not selling ETH,\n // transform the taker's entire spendable balance.\n if (args.inputTokenAmount == uint256(-1)) {\n if (LibERC20Transformer.isTokenETH(args.inputToken)) {\n // We can't pull more ETH from the taker, so we just set the\n // input token amount to the value attached to the call.\n args.inputTokenAmount = msg.value;\n } else {\n args.inputTokenAmount = _getSpendableERC20BalanceOf(\n args.inputToken,\n args.taker\n );\n }\n }\n\n TransformERC20PrivateState memory state;\n state.wallet = getTransformWallet();\n state.transformerDeployer = getTransformerDeployer();\n\n // Remember the initial output token balance of the taker.\n state.takerOutputTokenBalanceBefore =\n LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker);\n\n // Pull input tokens from the taker to the wallet and transfer attached ETH.\n _transferInputTokensAndAttachedEth(\n args.inputToken,\n args.taker,\n address(state.wallet),\n args.inputTokenAmount\n );\n\n {\n // Perform transformations.\n for (uint256 i = 0; i < args.transformations.length; ++i) {\n _executeTransformation(\n state.wallet,\n args.transformations[i],\n state.transformerDeployer,\n args.taker\n );\n }\n }\n\n // Compute how much output token has been transferred to the taker.\n state.takerOutputTokenBalanceAfter =\n LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker);\n if (state.takerOutputTokenBalanceAfter < state.takerOutputTokenBalanceBefore) {\n LibTransformERC20RichErrors.NegativeTransformERC20OutputError(\n address(args.outputToken),\n state.takerOutputTokenBalanceBefore - state.takerOutputTokenBalanceAfter\n ).rrevert();\n }\n outputTokenAmount = state.takerOutputTokenBalanceAfter.safeSub(\n state.takerOutputTokenBalanceBefore\n );\n // Ensure enough output token has been sent to the taker.\n if (outputTokenAmount < args.minOutputTokenAmount) {\n LibTransformERC20RichErrors.IncompleteTransformERC20Error(\n address(args.outputToken),\n outputTokenAmount,\n args.minOutputTokenAmount\n ).rrevert();\n }\n\n // Emit an event.\n emit TransformedERC20(\n args.taker,\n address(args.inputToken),\n address(args.outputToken),\n args.inputTokenAmount,\n outputTokenAmount\n );\n }\n\n /// @dev Return the current wallet instance that will serve as the execution\n /// context for transformations.\n /// @return wallet The wallet instance.\n function getTransformWallet()\n public\n override\n view\n returns (IFlashWallet wallet)\n {\n return LibTransformERC20Storage.getStorage().wallet;\n }\n\n /// @dev Transfer input tokens from the taker and any attached ETH to `to`\n /// @param inputToken The token to pull from the taker.\n /// @param from The from (taker) address.\n /// @param to The recipient of tokens and ETH.\n /// @param amount Amount of `inputToken` tokens to transfer.\n function _transferInputTokensAndAttachedEth(\n IERC20TokenV06 inputToken,\n address from,\n address payable to,\n uint256 amount\n )\n private\n {\n // Transfer any attached ETH.\n if (msg.value != 0) {\n to.transfer(msg.value);\n }\n // Transfer input tokens.\n if (!LibERC20Transformer.isTokenETH(inputToken) && amount != 0) {\n // Token is not ETH, so pull ERC20 tokens.\n _transferERC20Tokens(\n inputToken,\n from,\n to,\n amount\n );\n } else if (msg.value < amount) {\n // Token is ETH, so the caller must attach enough ETH to the call.\n LibTransformERC20RichErrors.InsufficientEthAttachedError(\n msg.value,\n amount\n ).rrevert();\n }\n }\n\n /// @dev Executs a transformer in the context of `wallet`.\n /// @param wallet The wallet instance.\n /// @param transformation The transformation.\n /// @param transformerDeployer The address of the transformer deployer.\n /// @param taker The taker address.\n function _executeTransformation(\n IFlashWallet wallet,\n Transformation memory transformation,\n address transformerDeployer,\n address payable taker\n )\n private\n {\n // Derive the transformer address from the deployment nonce.\n address payable transformer = LibERC20Transformer.getDeployedAddress(\n transformerDeployer,\n transformation.deploymentNonce\n );\n // Call `transformer.transform()` as the wallet.\n bytes memory resultData = wallet.executeDelegateCall(\n // The call target.\n transformer,\n // Call data.\n abi.encodeWithSelector(\n IERC20Transformer.transform.selector,\n IERC20Transformer.TransformContext({\n sender: msg.sender,\n taker: taker,\n data: transformation.data\n })\n )\n );\n // Ensure the transformer returned the magic bytes.\n if (resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != LibERC20Transformer.TRANSFORMER_SUCCESS\n ) {\n LibTransformERC20RichErrors.TransformerFailedError(\n transformer,\n transformation.data,\n resultData\n ).rrevert();\n }\n }\n}\n"
},
"../errors/LibTransformERC20RichErrors.sol": {
"id": 9,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibTransformERC20RichErrors {\n\n // solhint-disable func-name-mixedcase,separate-by-one-line-in-contract\n\n function InsufficientEthAttachedError(\n uint256 ethAttached,\n uint256 ethNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientEthAttachedError(uint256,uint256)\")),\n ethAttached,\n ethNeeded\n );\n }\n\n function IncompleteTransformERC20Error(\n address outputToken,\n uint256 outputTokenAmount,\n uint256 minOutputTokenAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteTransformERC20Error(address,uint256,uint256)\")),\n outputToken,\n outputTokenAmount,\n minOutputTokenAmount\n );\n }\n\n function NegativeTransformERC20OutputError(\n address outputToken,\n uint256 outputTokenLostAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NegativeTransformERC20OutputError(address,uint256)\")),\n outputToken,\n outputTokenLostAmount\n );\n }\n\n function TransformerFailedError(\n address transformer,\n bytes memory transformerData,\n bytes memory resultData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"TransformerFailedError(address,bytes,bytes)\")),\n transformer,\n transformerData,\n resultData\n );\n }\n\n // Common Transformer errors ///////////////////////////////////////////////\n\n function OnlyCallableByDeployerError(\n address caller,\n address deployer\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyCallableByDeployerError(address,address)\")),\n caller,\n deployer\n );\n }\n\n function InvalidExecutionContextError(\n address actualContext,\n address expectedContext\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidExecutionContextError(address,address)\")),\n actualContext,\n expectedContext\n );\n }\n\n enum InvalidTransformDataErrorCode {\n INVALID_TOKENS,\n INVALID_ARRAY_LENGTH\n }\n\n function InvalidTransformDataError(\n InvalidTransformDataErrorCode errorCode,\n bytes memory transformData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidTransformDataError(uint8,bytes)\")),\n errorCode,\n transformData\n );\n }\n\n // FillQuoteTransformer errors /////////////////////////////////////////////\n\n function IncompleteFillSellQuoteError(\n address sellToken,\n uint256 soldAmount,\n uint256 sellAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteFillSellQuoteError(address,uint256,uint256)\")),\n sellToken,\n soldAmount,\n sellAmount\n );\n }\n\n function IncompleteFillBuyQuoteError(\n address buyToken,\n uint256 boughtAmount,\n uint256 buyAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteFillBuyQuoteError(address,uint256,uint256)\")),\n buyToken,\n boughtAmount,\n buyAmount\n );\n }\n\n function InsufficientTakerTokenError(\n uint256 tokenBalance,\n uint256 tokensNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientTakerTokenError(uint256,uint256)\")),\n tokenBalance,\n tokensNeeded\n );\n }\n\n function InsufficientProtocolFeeError(\n uint256 ethBalance,\n uint256 ethNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientProtocolFeeError(uint256,uint256)\")),\n ethBalance,\n ethNeeded\n );\n }\n\n function InvalidERC20AssetDataError(\n bytes memory assetData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidERC20AssetDataError(bytes)\")),\n assetData\n );\n }\n\n function InvalidTakerFeeTokenError(\n address token\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidTakerFeeTokenError(address)\")),\n token\n );\n }\n}\n"
},
"../fixins/FixinTokenSpender.sol": {
"id": 44,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../features/interfaces/ITokenSpenderFeature.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"../external/FeeCollector.sol\";\nimport \"../vendor/v3/IStaking.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n\n/// @dev Helpers for moving tokens around.\nabstract contract FixinTokenSpender {\n using LibRichErrorsV06 for bytes;\n\n // Mask of the lower 20 bytes of a bytes32.\n uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;\n /// @dev A bloom filter for tokens that consume all gas when `transferFrom()` fails.\n bytes32 public immutable GREEDY_TOKENS_BLOOM_FILTER;\n\n /// @param greedyTokensBloomFilter The bloom filter for all greedy tokens.\n constructor(bytes32 greedyTokensBloomFilter)\n internal\n {\n GREEDY_TOKENS_BLOOM_FILTER = greedyTokensBloomFilter;\n }\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _transferERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n internal\n {\n bool success;\n bytes memory revertData;\n\n require(address(token) != address(this), \"FixinTokenSpender/CANNOT_INVOKE_SELF\");\n\n // If the token eats all gas when failing, we do not want to perform\n // optimistic fall through to the old AllowanceTarget contract if the\n // direct transferFrom() fails.\n if (_isTokenPossiblyGreedy(token)) {\n // If the token does not have a direct allowance on us then we use\n // the allowance target.\n if (token.allowance(owner, address(this)) < amount) {\n _transferFromLegacyAllowanceTarget(\n token,\n owner,\n to,\n amount,\n \"\"\n );\n return;\n }\n }\n\n assembly {\n let ptr := mload(0x40) // free memory pointer\n\n // selector for transferFrom(address,address,uint256)\n mstore(ptr, 0x23b872dd00000000000000000000000000000000000000000000000000000000)\n mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK))\n mstore(add(ptr, 0x24), and(to, ADDRESS_MASK))\n mstore(add(ptr, 0x44), amount)\n\n success := call(\n gas(),\n and(token, ADDRESS_MASK),\n 0,\n ptr,\n 0x64,\n 0,\n 0\n )\n\n let rdsize := returndatasize()\n\n returndatacopy(add(ptr, 0x20), 0, rdsize) // reuse memory\n\n // Check for ERC20 success. ERC20 tokens should return a boolean,\n // but some don't. We accept 0-length return data as success, or at\n // least 32 bytes that starts with a 32-byte boolean true.\n success := and(\n success, // call itself succeeded\n or(\n iszero(rdsize), // no return data, or\n and(\n iszero(lt(rdsize, 32)), // at least 32 bytes\n eq(mload(add(ptr, 0x20)), 1) // starts with uint256(1)\n )\n )\n )\n\n if iszero(success) {\n // revertData is a bytes, so length-prefixed data\n mstore(ptr, rdsize)\n revertData := ptr\n\n // update free memory pointer (ptr + 32-byte length + return data)\n mstore(0x40, add(add(ptr, 0x20), rdsize))\n }\n }\n\n if (!success) {\n _transferFromLegacyAllowanceTarget(\n token,\n owner,\n to,\n amount,\n revertData\n );\n }\n }\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner` by this address.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function _getSpendableERC20BalanceOf(\n IERC20TokenV06 token,\n address owner\n )\n internal\n view\n returns (uint256)\n {\n return LibSafeMathV06.min256(\n token.allowance(owner, address(this)),\n token.balanceOf(owner)\n );\n }\n\n /// @dev Check if a token possibly belongs to the `GREEDY_TOKENS_BLOOM_FILTER`\n /// bloom filter.\n function _isTokenPossiblyGreedy(IERC20TokenV06 token)\n internal\n view\n returns (bool isPossiblyGreedy)\n {\n // The hash is given by:\n // (1 << (keccak256(token) % 256)) | (1 << (token % 256))\n bytes32 h;\n assembly {\n mstore(0, token)\n h := or(shl(mod(keccak256(0, 32), 256), 1), shl(mod(token, 256), 1))\n }\n return (h & GREEDY_TOKENS_BLOOM_FILTER) == h;\n }\n\n /// @dev Transfer tokens using the legacy allowance target instead of\n /// allowances directly set on the exchange proxy.\n function _transferFromLegacyAllowanceTarget(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount,\n bytes memory initialRevertData\n )\n private\n {\n // Try the old AllowanceTarget.\n try ITokenSpenderFeature(address(this))._spendERC20Tokens(\n token,\n owner,\n to,\n amount\n ) {\n } catch (bytes memory revertData) {\n // Bubble up the first error message. (In general, the fallback to the\n // allowance target is opportunistic. We ignore the specific error\n // message if it fails.)\n LibSpenderRichErrors.SpenderERC20TransferFromFailedError(\n address(token),\n owner,\n to,\n amount,\n initialRevertData.length != 0 ? initialRevertData : revertData\n ).rrevert();\n }\n }\n}\n"
},
"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol": {
"id": 62,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./IERC20TokenV06.sol\";\n\n\ninterface IEtherTokenV06 is\n IERC20TokenV06\n{\n /// @dev Wrap ether.\n function deposit() external payable;\n\n /// @dev Unwrap ether.\n function withdraw(uint256 amount) external;\n}\n"
},
"../external/FeeCollector.sol": {
"id": 12,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n/// @dev The collector contract for protocol fees\ncontract FeeCollector is AuthorizableV06 {\n /// @dev Allow ether transfers to the collector.\n receive() external payable { }\n\n constructor() public {\n _addAuthorizedAddress(msg.sender);\n }\n\n /// @dev Approve the staking contract and join a pool. Only an authority\n /// can call this.\n /// @param weth The WETH contract.\n /// @param staking The staking contract.\n /// @param poolId The pool ID this contract is collecting fees for.\n function initialize(\n IEtherTokenV06 weth,\n IStaking staking,\n bytes32 poolId\n )\n external\n onlyAuthorized\n {\n weth.approve(address(staking), type(uint256).max);\n staking.joinStakingPoolAsMaker(poolId);\n }\n\n /// @dev Convert all held ether to WETH. Only an authority can call this.\n /// @param weth The WETH contract.\n function convertToWeth(\n IEtherTokenV06 weth\n )\n external\n onlyAuthorized\n {\n if (address(this).balance > 0) {\n weth.deposit{value: address(this).balance}();\n }\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol": {
"id": 64,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./interfaces/IAuthorizableV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibAuthorizableRichErrorsV06.sol\";\nimport \"./OwnableV06.sol\";\n\n\n// solhint-disable no-empty-blocks\ncontract AuthorizableV06 is\n OwnableV06,\n IAuthorizableV06\n{\n /// @dev Only authorized addresses can invoke functions with this modifier.\n modifier onlyAuthorized {\n _assertSenderIsAuthorized();\n _;\n }\n\n // @dev Whether an address is authorized to call privileged functions.\n // @param 0 Address to query.\n // @return 0 Whether the address is authorized.\n mapping (address => bool) public override authorized;\n // @dev Whether an address is authorized to call privileged functions.\n // @param 0 Index of authorized address.\n // @return 0 Authorized address.\n address[] public override authorities;\n\n /// @dev Initializes the `owner` address.\n constructor()\n public\n OwnableV06()\n {}\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function addAuthorizedAddress(address target)\n external\n override\n onlyOwner\n {\n _addAuthorizedAddress(target);\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n function removeAuthorizedAddress(address target)\n external\n override\n onlyOwner\n {\n if (!authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));\n }\n for (uint256 i = 0; i < authorities.length; i++) {\n if (authorities[i] == target) {\n _removeAuthorizedAddressAtIndex(target, i);\n break;\n }\n }\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n external\n override\n onlyOwner\n {\n _removeAuthorizedAddressAtIndex(target, index);\n }\n\n /// @dev Gets all authorized addresses.\n /// @return Array of authorized addresses.\n function getAuthorizedAddresses()\n external\n override\n view\n returns (address[] memory)\n {\n return authorities;\n }\n\n /// @dev Reverts if msg.sender is not authorized.\n function _assertSenderIsAuthorized()\n internal\n view\n {\n if (!authorized[msg.sender]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.SenderNotAuthorizedError(msg.sender));\n }\n }\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function _addAuthorizedAddress(address target)\n internal\n {\n // Ensure that the target is not the zero address.\n if (target == address(0)) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.ZeroCantBeAuthorizedError());\n }\n\n // Ensure that the target is not already authorized.\n if (authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetAlreadyAuthorizedError(target));\n }\n\n authorized[target] = true;\n authorities.push(target);\n emit AuthorizedAddressAdded(target, msg.sender);\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function _removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n internal\n {\n if (!authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));\n }\n if (index >= authorities.length) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.IndexOutOfBoundsError(\n index,\n authorities.length\n ));\n }\n if (authorities[index] != target) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.AuthorizedAddressMismatchError(\n authorities[index],\n target\n ));\n }\n\n delete authorized[target];\n authorities[index] = authorities[authorities.length - 1];\n authorities.pop();\n emit AuthorizedAddressRemoved(target, msg.sender);\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibAuthorizableRichErrorsV06.sol": {
"id": 69,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibAuthorizableRichErrorsV06 {\n\n // bytes4(keccak256(\"AuthorizedAddressMismatchError(address,address)\"))\n bytes4 internal constant AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR =\n 0x140a84db;\n\n // bytes4(keccak256(\"IndexOutOfBoundsError(uint256,uint256)\"))\n bytes4 internal constant INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR =\n 0xe9f83771;\n\n // bytes4(keccak256(\"SenderNotAuthorizedError(address)\"))\n bytes4 internal constant SENDER_NOT_AUTHORIZED_ERROR_SELECTOR =\n 0xb65a25b9;\n\n // bytes4(keccak256(\"TargetAlreadyAuthorizedError(address)\"))\n bytes4 internal constant TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR =\n 0xde16f1a0;\n\n // bytes4(keccak256(\"TargetNotAuthorizedError(address)\"))\n bytes4 internal constant TARGET_NOT_AUTHORIZED_ERROR_SELECTOR =\n 0xeb5108a2;\n\n // bytes4(keccak256(\"ZeroCantBeAuthorizedError()\"))\n bytes internal constant ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES =\n hex\"57654fe4\";\n\n // solhint-disable func-name-mixedcase\n function AuthorizedAddressMismatchError(\n address authorized,\n address target\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR,\n authorized,\n target\n );\n }\n\n function IndexOutOfBoundsError(\n uint256 index,\n uint256 length\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR,\n index,\n length\n );\n }\n\n function SenderNotAuthorizedError(address sender)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n SENDER_NOT_AUTHORIZED_ERROR_SELECTOR,\n sender\n );\n }\n\n function TargetAlreadyAuthorizedError(address target)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR,\n target\n );\n }\n\n function TargetNotAuthorizedError(address target)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n TARGET_NOT_AUTHORIZED_ERROR_SELECTOR,\n target\n );\n }\n\n function ZeroCantBeAuthorizedError()\n internal\n pure\n returns (bytes memory)\n {\n return ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES;\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/OwnableV06.sol": {
"id": 68,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2019 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./interfaces/IOwnableV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibOwnableRichErrorsV06.sol\";\n\n\ncontract OwnableV06 is\n IOwnableV06\n{\n /// @dev The owner of this contract.\n /// @return 0 The owner address.\n address public override owner;\n\n constructor() public {\n owner = msg.sender;\n }\n\n modifier onlyOwner() {\n _assertSenderIsOwner();\n _;\n }\n\n /// @dev Change the owner of this contract.\n /// @param newOwner New owner address.\n function transferOwnership(address newOwner)\n public\n override\n onlyOwner\n {\n if (newOwner == address(0)) {\n LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.TransferOwnerToZeroError());\n } else {\n owner = newOwner;\n emit OwnershipTransferred(msg.sender, newOwner);\n }\n }\n\n function _assertSenderIsOwner()\n internal\n view\n {\n if (msg.sender != owner) {\n LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.OnlyOwnerError(\n msg.sender,\n owner\n ));\n }\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibOwnableRichErrorsV06.sol": {
"id": 72,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\npragma solidity ^0.6.5;\n\n\nlibrary LibOwnableRichErrorsV06 {\n\n // bytes4(keccak256(\"OnlyOwnerError(address,address)\"))\n bytes4 internal constant ONLY_OWNER_ERROR_SELECTOR =\n 0x1de45ad1;\n\n // bytes4(keccak256(\"TransferOwnerToZeroError()\"))\n bytes internal constant TRANSFER_OWNER_TO_ZERO_ERROR_BYTES =\n hex\"e69edc3e\";\n\n // solhint-disable func-name-mixedcase\n function OnlyOwnerError(\n address sender,\n address owner\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n ONLY_OWNER_ERROR_SELECTOR,\n sender,\n owner\n );\n }\n\n function TransferOwnerToZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return TRANSFER_OWNER_TO_ZERO_ERROR_BYTES;\n }\n}\n"
},
"../vendor/v3/IStaking.sol": {
"id": 60,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\ninterface IStaking {\n function joinStakingPoolAsMaker(bytes32) external;\n function payProtocolFee(address, address, uint256) external payable;\n}\n"
},
"../external/IFlashWallet.sol": {
"id": 16,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol\";\n\n\n/// @dev A contract that can execute arbitrary calls from its owner.\ninterface IFlashWallet {\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @param value Ether to attach to the call.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData,\n uint256 value\n )\n external\n payable\n returns (bytes memory resultData);\n\n /// @dev Execute an arbitrary delegatecall, in the context of this puppet.\n /// Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeDelegateCall(\n address payable target,\n bytes calldata callData\n )\n external\n payable\n returns (bytes memory resultData);\n\n /// @dev Allows the puppet to receive ETH.\n receive() external payable;\n\n /// @dev Fetch the immutable owner/deployer of this contract.\n /// @return owner_ The immutable owner/deployer/\n function owner() external view returns (address owner_);\n}\n"
},
"../external/FlashWallet.sol": {
"id": 14,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibOwnableRichErrorsV06.sol\";\nimport \"../errors/LibWalletRichErrors.sol\";\nimport \"./IFlashWallet.sol\";\n\n\n/// @dev A contract that can execute arbitrary calls from its owner.\ncontract FlashWallet is\n IFlashWallet\n{\n // solhint-disable no-unused-vars,indent,no-empty-blocks\n using LibRichErrorsV06 for bytes;\n\n // solhint-disable\n /// @dev Store the owner/deployer as an immutable to make this contract stateless.\n address public override immutable owner;\n // solhint-enable\n\n constructor() public {\n // The deployer is the owner.\n owner = msg.sender;\n }\n\n /// @dev Allows only the (immutable) owner to call a function.\n modifier onlyOwner() virtual {\n if (msg.sender != owner) {\n LibOwnableRichErrorsV06.OnlyOwnerError(\n msg.sender,\n owner\n ).rrevert();\n }\n _;\n }\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @param value Ether to attach to the call.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData,\n uint256 value\n )\n external\n payable\n override\n onlyOwner\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.call{value: value}(callData);\n if (!success) {\n LibWalletRichErrors\n .WalletExecuteCallFailedError(\n address(this),\n target,\n callData,\n value,\n resultData\n )\n .rrevert();\n }\n }\n\n /// @dev Execute an arbitrary delegatecall, in the context of this puppet.\n /// Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeDelegateCall(\n address payable target,\n bytes calldata callData\n )\n external\n payable\n override\n onlyOwner\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.delegatecall(callData);\n if (!success) {\n LibWalletRichErrors\n .WalletExecuteDelegateCallFailedError(\n address(this),\n target,\n callData,\n resultData\n )\n .rrevert();\n }\n }\n\n // solhint-disable\n /// @dev Allows this contract to receive ether.\n receive() external override payable {}\n // solhint-enable\n\n /// @dev Signal support for receiving ERC1155 tokens.\n /// @param interfaceID The interface ID, as per ERC-165 rules.\n /// @return hasSupport `true` if this contract supports an ERC-165 interface.\n function supportsInterface(bytes4 interfaceID)\n external\n pure\n returns (bool hasSupport)\n {\n return interfaceID == this.supportsInterface.selector ||\n interfaceID == this.onERC1155Received.selector ^ this.onERC1155BatchReceived.selector ||\n interfaceID == this.tokenFallback.selector;\n }\n\n /// @dev Allow this contract to receive ERC1155 tokens.\n /// @return success `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n function onERC1155Received(\n address, // operator,\n address, // from,\n uint256, // id,\n uint256, // value,\n bytes calldata //data\n )\n external\n pure\n returns (bytes4 success)\n {\n return this.onERC1155Received.selector;\n }\n\n /// @dev Allow this contract to receive ERC1155 tokens.\n /// @return success `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n function onERC1155BatchReceived(\n address, // operator,\n address, // from,\n uint256[] calldata, // ids,\n uint256[] calldata, // values,\n bytes calldata // data\n )\n external\n pure\n returns (bytes4 success)\n {\n return this.onERC1155BatchReceived.selector;\n }\n\n /// @dev Allows this contract to receive ERC223 tokens.\n function tokenFallback(\n address, // from,\n uint256, // value,\n bytes calldata // value\n )\n external\n pure\n {}\n}\n"
},
"../errors/LibWalletRichErrors.sol": {
"id": 10,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibWalletRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function WalletExecuteCallFailedError(\n address wallet,\n address callTarget,\n bytes memory callData,\n uint256 callValue,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"WalletExecuteCallFailedError(address,address,bytes,uint256,bytes)\")),\n wallet,\n callTarget,\n callData,\n callValue,\n errorData\n );\n }\n\n function WalletExecuteDelegateCallFailedError(\n address wallet,\n address callTarget,\n bytes memory callData,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"WalletExecuteDelegateCallFailedError(address,address,bytes,bytes)\")),\n wallet,\n callTarget,\n callData,\n errorData\n );\n }\n}\n"
},
"../storage/LibTransformERC20Storage.sol": {
"id": 57,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IFlashWallet.sol\";\n\n\n/// @dev Storage helpers for the `TransformERC20` feature.\nlibrary LibTransformERC20Storage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The current wallet instance.\n IFlashWallet wallet;\n // The transformer deployer address.\n address transformerDeployer;\n // The optional signer for `transformERC20()` calldata.\n address quoteSigner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.TransformERC20\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../transformers/IERC20Transformer.sol": {
"id": 58,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\n\n\n/// @dev A transformation callback used in `TransformERC20.transformERC20()`.\ninterface IERC20Transformer {\n\n /// @dev Context information to pass into `transform()` by `TransformERC20.transformERC20()`.\n struct TransformContext {\n // The caller of `TransformERC20.transformERC20()`.\n address payable sender;\n // taker The taker address, which may be distinct from `sender` in the case\n // meta-transactions.\n address payable taker;\n // Arbitrary data to pass to the transformer.\n bytes data;\n }\n\n /// @dev Called from `TransformERC20.transformERC20()`. This will be\n /// delegatecalled in the context of the FlashWallet instance being used.\n /// @param context Context information.\n /// @return success The success bytes (`LibERC20Transformer.TRANSFORMER_SUCCESS`).\n function transform(TransformContext calldata context)\n external\n returns (bytes4 success);\n}\n"
},
"../transformers/LibERC20Transformer.sol": {
"id": 59,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\n\n\nlibrary LibERC20Transformer {\n\n using LibERC20TokenV06 for IERC20TokenV06;\n\n /// @dev ETH pseudo-token address.\n address constant internal ETH_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n /// @dev ETH pseudo-token.\n IERC20TokenV06 constant internal ETH_TOKEN = IERC20TokenV06(ETH_TOKEN_ADDRESS);\n /// @dev Return value indicating success in `IERC20Transformer.transform()`.\n /// This is just `keccak256('TRANSFORMER_SUCCESS')`.\n bytes4 constant internal TRANSFORMER_SUCCESS = 0x13c9929e;\n\n /// @dev Transfer ERC20 tokens and ETH.\n /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`).\n /// @param to The recipient.\n /// @param amount The transfer amount.\n function transformerTransfer(\n IERC20TokenV06 token,\n address payable to,\n uint256 amount\n )\n internal\n {\n if (isTokenETH(token)) {\n to.transfer(amount);\n } else {\n token.compatTransfer(to, amount);\n }\n }\n\n /// @dev Check if a token is the ETH pseudo-token.\n /// @param token The token to check.\n /// @return isETH `true` if the token is the ETH pseudo-token.\n function isTokenETH(IERC20TokenV06 token)\n internal\n pure\n returns (bool isETH)\n {\n return address(token) == ETH_TOKEN_ADDRESS;\n }\n\n /// @dev Check the balance of an ERC20 token or ETH.\n /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`).\n /// @param owner Holder of the tokens.\n /// @return tokenBalance The balance of `owner`.\n function getTokenBalanceOf(IERC20TokenV06 token, address owner)\n internal\n view\n returns (uint256 tokenBalance)\n {\n if (isTokenETH(token)) {\n return owner.balance;\n }\n return token.balanceOf(owner);\n }\n\n /// @dev RLP-encode a 32-bit or less account nonce.\n /// @param nonce A positive integer in the range 0 <= nonce < 2^32.\n /// @return rlpNonce The RLP encoding.\n function rlpEncodeNonce(uint32 nonce)\n internal\n pure\n returns (bytes memory rlpNonce)\n {\n // See https://github.com/ethereum/wiki/wiki/RLP for RLP encoding rules.\n if (nonce == 0) {\n rlpNonce = new bytes(1);\n rlpNonce[0] = 0x80;\n } else if (nonce < 0x80) {\n rlpNonce = new bytes(1);\n rlpNonce[0] = byte(uint8(nonce));\n } else if (nonce <= 0xFF) {\n rlpNonce = new bytes(2);\n rlpNonce[0] = 0x81;\n rlpNonce[1] = byte(uint8(nonce));\n } else if (nonce <= 0xFFFF) {\n rlpNonce = new bytes(3);\n rlpNonce[0] = 0x82;\n rlpNonce[1] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[2] = byte(uint8(nonce));\n } else if (nonce <= 0xFFFFFF) {\n rlpNonce = new bytes(4);\n rlpNonce[0] = 0x83;\n rlpNonce[1] = byte(uint8((nonce & 0xFF0000) >> 16));\n rlpNonce[2] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[3] = byte(uint8(nonce));\n } else {\n rlpNonce = new bytes(5);\n rlpNonce[0] = 0x84;\n rlpNonce[1] = byte(uint8((nonce & 0xFF000000) >> 24));\n rlpNonce[2] = byte(uint8((nonce & 0xFF0000) >> 16));\n rlpNonce[3] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[4] = byte(uint8(nonce));\n }\n }\n\n /// @dev Compute the expected deployment address by `deployer` at\n /// the nonce given by `deploymentNonce`.\n /// @param deployer The address of the deployer.\n /// @param deploymentNonce The nonce that the deployer had when deploying\n /// a contract.\n /// @return deploymentAddress The deployment address.\n function getDeployedAddress(address deployer, uint32 deploymentNonce)\n internal\n pure\n returns (address payable deploymentAddress)\n {\n // The address of if a deployed contract is the lower 20 bytes of the\n // hash of the RLP-encoded deployer's account address + account nonce.\n // See: https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed\n bytes memory rlpNonce = rlpEncodeNonce(deploymentNonce);\n return address(uint160(uint256(keccak256(abi.encodePacked(\n byte(uint8(0xC0 + 21 + rlpNonce.length)),\n byte(uint8(0x80 + 20)),\n deployer,\n rlpNonce\n )))));\n }\n}\n"
},
"../features/interfaces/ITransformERC20Feature.sol": {
"id": 33,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../../transformers/IERC20Transformer.sol\";\nimport \"../../external/IFlashWallet.sol\";\n\n\n/// @dev Feature to composably transform between ERC20 tokens.\ninterface ITransformERC20Feature {\n\n /// @dev Defines a transformation to run in `transformERC20()`.\n struct Transformation {\n // The deployment nonce for the transformer.\n // The address of the transformer contract will be derived from this\n // value.\n uint32 deploymentNonce;\n // Arbitrary data to pass to the transformer.\n bytes data;\n }\n\n /// @dev Arguments for `_transformERC20()`.\n struct TransformERC20Args {\n // The taker address.\n address payable taker;\n // The token being provided by the taker.\n // If `0xeee...`, ETH is implied and should be provided with the call.`\n IERC20TokenV06 inputToken;\n // The token to be acquired by the taker.\n // `0xeee...` implies ETH.\n IERC20TokenV06 outputToken;\n // The amount of `inputToken` to take from the taker.\n // If set to `uint256(-1)`, the entire spendable balance of the taker\n // will be solt.\n uint256 inputTokenAmount;\n // The minimum amount of `outputToken` the taker\n // must receive for the entire transformation to succeed. If set to zero,\n // the minimum output token transfer will not be asserted.\n uint256 minOutputTokenAmount;\n // The transformations to execute on the token balance(s)\n // in sequence.\n Transformation[] transformations;\n }\n\n /// @dev Raised upon a successful `transformERC20`.\n /// @param taker The taker (caller) address.\n /// @param inputToken The token being provided by the taker.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the taker.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the taker.\n /// @param outputTokenAmount The amount of `outputToken` received by the taker.\n event TransformedERC20(\n address indexed taker,\n address inputToken,\n address outputToken,\n uint256 inputTokenAmount,\n uint256 outputTokenAmount\n );\n\n /// @dev Raised when `setTransformerDeployer()` is called.\n /// @param transformerDeployer The new deployer address.\n event TransformerDeployerUpdated(address transformerDeployer);\n\n /// @dev Raised when `setQuoteSigner()` is called.\n /// @param quoteSigner The new quote signer.\n event QuoteSignerUpdated(address quoteSigner);\n\n /// @dev Replace the allowed deployer for transformers.\n /// Only callable by the owner.\n /// @param transformerDeployer The address of the new trusted deployer\n /// for transformers.\n function setTransformerDeployer(address transformerDeployer)\n external;\n\n /// @dev Replace the optional signer for `transformERC20()` calldata.\n /// Only callable by the owner.\n /// @param quoteSigner The address of the new calldata signer.\n function setQuoteSigner(address quoteSigner)\n external;\n\n /// @dev Deploy a new flash wallet instance and replace the current one with it.\n /// Useful if we somehow break the current wallet instance.\n /// Only callable by the owner.\n /// @return wallet The new wallet instance.\n function createTransformWallet()\n external\n returns (IFlashWallet wallet);\n\n /// @dev Executes a series of transformations to convert an ERC20 `inputToken`\n /// to an ERC20 `outputToken`.\n /// @param inputToken The token being provided by the sender.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the sender.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the sender.\n /// @param minOutputTokenAmount The minimum amount of `outputToken` the sender\n /// must receive for the entire transformation to succeed.\n /// @param transformations The transformations to execute on the token balance(s)\n /// in sequence.\n /// @return outputTokenAmount The amount of `outputToken` received by the sender.\n function transformERC20(\n IERC20TokenV06 inputToken,\n IERC20TokenV06 outputToken,\n uint256 inputTokenAmount,\n uint256 minOutputTokenAmount,\n Transformation[] calldata transformations\n )\n external\n payable\n returns (uint256 outputTokenAmount);\n\n /// @dev Internal version of `transformERC20()`. Only callable from within.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20(TransformERC20Args calldata args)\n external\n payable\n returns (uint256 outputTokenAmount);\n\n /// @dev Return the current wallet instance that will serve as the execution\n /// context for transformations.\n /// @return wallet The wallet instance.\n function getTransformWallet()\n external\n view\n returns (IFlashWallet wallet);\n\n /// @dev Return the allowed deployer for transformers.\n /// @return deployer The transform deployer address.\n function getTransformerDeployer()\n external\n view\n returns (address deployer);\n\n /// @dev Return the optional signer for `transformERC20()` calldata.\n /// @return signer The transform deployer address.\n function getQuoteSigner()\n external\n view\n returns (address signer);\n}\n"
},
"../features/MetaTransactionsFeature.sol": {
"id": 19,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../errors/LibMetaTransactionsRichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../fixins/FixinReentrancyGuard.sol\";\nimport \"../fixins/FixinTokenSpender.sol\";\nimport \"../fixins/FixinEIP712.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../storage/LibMetaTransactionsStorage.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/IMetaTransactionsFeature.sol\";\nimport \"./interfaces/INativeOrdersFeature.sol\";\nimport \"./interfaces/ITransformERC20Feature.sol\";\nimport \"./libs/LibSignature.sol\";\n\n/// @dev MetaTransactions feature.\ncontract MetaTransactionsFeature is\n IFeature,\n IMetaTransactionsFeature,\n FixinCommon,\n FixinReentrancyGuard,\n FixinEIP712,\n FixinTokenSpender\n{\n using LibBytesV06 for bytes;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Describes the state of a meta transaction.\n struct ExecuteState {\n // Sender of the meta-transaction.\n address sender;\n // Hash of the meta-transaction data.\n bytes32 hash;\n // The meta-transaction data.\n MetaTransactionData mtx;\n // The meta-transaction signature (by `mtx.signer`).\n LibSignature.Signature signature;\n // The selector of the function being called.\n bytes4 selector;\n // The ETH balance of this contract before performing the call.\n uint256 selfBalance;\n // The block number at which the meta-transaction was executed.\n uint256 executedBlockNumber;\n }\n\n /// @dev Arguments for a `TransformERC20.transformERC20()` call.\n struct ExternalTransformERC20Args {\n IERC20TokenV06 inputToken;\n IERC20TokenV06 outputToken;\n uint256 inputTokenAmount;\n uint256 minOutputTokenAmount;\n ITransformERC20Feature.Transformation[] transformations;\n }\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"MetaTransactions\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 1, 0);\n /// @dev EIP712 typehash of the `MetaTransactionData` struct.\n bytes32 public immutable MTX_EIP712_TYPEHASH = keccak256(\n \"MetaTransactionData(\"\n \"address signer,\"\n \"address sender,\"\n \"uint256 minGasPrice,\"\n \"uint256 maxGasPrice,\"\n \"uint256 expirationTimeSeconds,\"\n \"uint256 salt,\"\n \"bytes callData,\"\n \"uint256 value,\"\n \"address feeToken,\"\n \"uint256 feeAmount\"\n \")\"\n );\n\n /// @dev Refunds up to `msg.value` leftover ETH at the end of the call.\n modifier refundsAttachedEth() {\n _;\n uint256 remainingBalance =\n LibSafeMathV06.min256(msg.value, address(this).balance);\n if (remainingBalance > 0) {\n msg.sender.transfer(remainingBalance);\n }\n }\n\n constructor(address zeroExAddress, bytes32 greedyTokensBloomFilter)\n public\n FixinCommon()\n FixinEIP712(zeroExAddress)\n FixinTokenSpender(greedyTokensBloomFilter)\n {\n // solhint-disable-next-line no-empty-blocks\n }\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate()\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.executeMetaTransaction.selector);\n _registerFeatureFunction(this.batchExecuteMetaTransactions.selector);\n _registerFeatureFunction(this.getMetaTransactionExecutedBlock.selector);\n _registerFeatureFunction(this.getMetaTransactionHashExecutedBlock.selector);\n _registerFeatureFunction(this.getMetaTransactionHash.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Execute a single meta-transaction.\n /// @param mtx The meta-transaction.\n /// @param signature The signature by `mtx.signer`.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function executeMetaTransaction(\n MetaTransactionData memory mtx,\n LibSignature.Signature memory signature\n )\n public\n payable\n override\n nonReentrant(REENTRANCY_MTX)\n refundsAttachedEth\n returns (bytes memory returnResult)\n {\n ExecuteState memory state;\n state.sender = msg.sender;\n state.mtx = mtx;\n state.hash = getMetaTransactionHash(mtx);\n state.signature = signature;\n\n returnResult = _executeMetaTransactionPrivate(state);\n }\n\n /// @dev Execute multiple meta-transactions.\n /// @param mtxs The meta-transactions.\n /// @param signatures The signature by each respective `mtx.signer`.\n /// @return returnResults The ABI-encoded results of the underlying calls.\n function batchExecuteMetaTransactions(\n MetaTransactionData[] memory mtxs,\n LibSignature.Signature[] memory signatures\n )\n public\n payable\n override\n nonReentrant(REENTRANCY_MTX)\n refundsAttachedEth\n returns (bytes[] memory returnResults)\n {\n if (mtxs.length != signatures.length) {\n LibMetaTransactionsRichErrors.InvalidMetaTransactionsArrayLengthsError(\n mtxs.length,\n signatures.length\n ).rrevert();\n }\n returnResults = new bytes[](mtxs.length);\n for (uint256 i = 0; i < mtxs.length; ++i) {\n ExecuteState memory state;\n state.sender = msg.sender;\n state.mtx = mtxs[i];\n state.hash = getMetaTransactionHash(mtxs[i]);\n state.signature = signatures[i];\n\n returnResults[i] = _executeMetaTransactionPrivate(state);\n }\n }\n\n /// @dev Get the block at which a meta-transaction has been executed.\n /// @param mtx The meta-transaction.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionExecutedBlock(MetaTransactionData memory mtx)\n public\n override\n view\n returns (uint256 blockNumber)\n {\n return getMetaTransactionHashExecutedBlock(getMetaTransactionHash(mtx));\n }\n\n /// @dev Get the block at which a meta-transaction hash has been executed.\n /// @param mtxHash The meta-transaction hash.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionHashExecutedBlock(bytes32 mtxHash)\n public\n override\n view\n returns (uint256 blockNumber)\n {\n return LibMetaTransactionsStorage.getStorage().mtxHashToExecutedBlockNumber[mtxHash];\n }\n\n /// @dev Get the EIP712 hash of a meta-transaction.\n /// @param mtx The meta-transaction.\n /// @return mtxHash The EIP712 hash of `mtx`.\n function getMetaTransactionHash(MetaTransactionData memory mtx)\n public\n override\n view\n returns (bytes32 mtxHash)\n {\n return _getEIP712Hash(keccak256(abi.encode(\n MTX_EIP712_TYPEHASH,\n mtx.signer,\n mtx.sender,\n mtx.minGasPrice,\n mtx.maxGasPrice,\n mtx.expirationTimeSeconds,\n mtx.salt,\n keccak256(mtx.callData),\n mtx.value,\n mtx.feeToken,\n mtx.feeAmount\n )));\n }\n\n /// @dev Execute a meta-transaction by `sender`. Low-level, hidden variant.\n /// @param state The `ExecuteState` for this metatransaction, with `sender`,\n /// `hash`, `mtx`, and `signature` fields filled.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function _executeMetaTransactionPrivate(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n _validateMetaTransaction(state);\n\n // Mark the transaction executed by storing the block at which it was executed.\n // Currently the block number just indicates that the mtx was executed and\n // serves no other purpose from within this contract.\n LibMetaTransactionsStorage.getStorage()\n .mtxHashToExecutedBlockNumber[state.hash] = block.number;\n\n // Pay the fee to the sender.\n if (state.mtx.feeAmount > 0) {\n _transferERC20Tokens(\n state.mtx.feeToken,\n state.mtx.signer,\n state.sender,\n state.mtx.feeAmount\n );\n }\n\n // Execute the call based on the selector.\n state.selector = state.mtx.callData.readBytes4(0);\n if (state.selector == ITransformERC20Feature.transformERC20.selector) {\n returnResult = _executeTransformERC20Call(state);\n } else if (state.selector == INativeOrdersFeature.fillLimitOrder.selector) {\n returnResult = _executeFillLimitOrderCall(state);\n } else if (state.selector == INativeOrdersFeature.fillRfqOrder.selector) {\n returnResult = _executeFillRfqOrderCall(state);\n } else {\n LibMetaTransactionsRichErrors\n .MetaTransactionUnsupportedFunctionError(state.hash, state.selector)\n .rrevert();\n }\n emit MetaTransactionExecuted(\n state.hash,\n state.selector,\n state.mtx.signer,\n state.mtx.sender\n );\n }\n\n /// @dev Validate that a meta-transaction is executable.\n function _validateMetaTransaction(ExecuteState memory state)\n private\n view\n {\n // Must be from the required sender, if set.\n if (state.mtx.sender != address(0) && state.mtx.sender != state.sender) {\n LibMetaTransactionsRichErrors\n .MetaTransactionWrongSenderError(\n state.hash,\n state.sender,\n state.mtx.sender\n ).rrevert();\n }\n // Must not be expired.\n if (state.mtx.expirationTimeSeconds <= block.timestamp) {\n LibMetaTransactionsRichErrors\n .MetaTransactionExpiredError(\n state.hash,\n block.timestamp,\n state.mtx.expirationTimeSeconds\n ).rrevert();\n }\n // Must have a valid gas price.\n if (state.mtx.minGasPrice > tx.gasprice || state.mtx.maxGasPrice < tx.gasprice) {\n LibMetaTransactionsRichErrors\n .MetaTransactionGasPriceError(\n state.hash,\n tx.gasprice,\n state.mtx.minGasPrice,\n state.mtx.maxGasPrice\n ).rrevert();\n }\n // Must have enough ETH.\n state.selfBalance = address(this).balance;\n if (state.mtx.value > state.selfBalance) {\n LibMetaTransactionsRichErrors\n .MetaTransactionInsufficientEthError(\n state.hash,\n state.selfBalance,\n state.mtx.value\n ).rrevert();\n }\n\n if (LibSignature.getSignerOfHash(state.hash, state.signature) !=\n state.mtx.signer) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.WRONG_SIGNER,\n state.hash,\n state.mtx.signer,\n // TODO: Remove this field from SignatureValidationError\n // when rich reverts are part of the protocol repo.\n \"\"\n ).rrevert();\n }\n // Transaction must not have been already executed.\n state.executedBlockNumber = LibMetaTransactionsStorage\n .getStorage().mtxHashToExecutedBlockNumber[state.hash];\n if (state.executedBlockNumber != 0) {\n LibMetaTransactionsRichErrors\n .MetaTransactionAlreadyExecutedError(\n state.hash,\n state.executedBlockNumber\n ).rrevert();\n }\n }\n\n /// @dev Execute a `ITransformERC20Feature.transformERC20()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `ITransformERC20Feature._transformERC20()` variant, where we can override\n /// the taker address.\n function _executeTransformERC20Call(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n // HACK(dorothy-zbornak): `abi.decode()` with the individual args\n // will cause a stack overflow. But we can prefix the call data with an\n // offset to transform it into the encoding for the equivalent single struct arg,\n // since decoding a single struct arg consumes far less stack space than\n // decoding multiple struct args.\n\n // Where the encoding for multiple args (with the selector ommitted)\n // would typically look like:\n // | argument | offset |\n // |--------------------------|---------|\n // | inputToken | 0 |\n // | outputToken | 32 |\n // | inputTokenAmount | 64 |\n // | minOutputTokenAmount | 96 |\n // | transformations (offset) | 128 | = 32\n // | transformations (data) | 160 |\n\n // We will ABI-decode a single struct arg copy with the layout:\n // | argument | offset |\n // |--------------------------|---------|\n // | (arg 1 offset) | 0 | = 32\n // | inputToken | 32 |\n // | outputToken | 64 |\n // | inputTokenAmount | 96 |\n // | minOutputTokenAmount | 128 |\n // | transformations (offset) | 160 | = 32\n // | transformations (data) | 192 |\n\n ExternalTransformERC20Args memory args;\n {\n bytes memory encodedStructArgs = new bytes(state.mtx.callData.length - 4 + 32);\n // Copy the args data from the original, after the new struct offset prefix.\n bytes memory fromCallData = state.mtx.callData;\n assert(fromCallData.length >= 160);\n uint256 fromMem;\n uint256 toMem;\n assembly {\n // Prefix the calldata with a struct offset,\n // which points to just one word over.\n mstore(add(encodedStructArgs, 32), 32)\n // Copy everything after the selector.\n fromMem := add(fromCallData, 36)\n // Start copying after the struct offset.\n toMem := add(encodedStructArgs, 64)\n }\n LibBytesV06.memCopy(toMem, fromMem, fromCallData.length - 4);\n // Decode call args for `ITransformERC20Feature.transformERC20()` as a struct.\n args = abi.decode(encodedStructArgs, (ExternalTransformERC20Args));\n }\n // Call `ITransformERC20Feature._transformERC20()` (internal variant).\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n ITransformERC20Feature._transformERC20.selector,\n ITransformERC20Feature.TransformERC20Args({\n taker: state.mtx.signer, // taker is mtx signer\n inputToken: args.inputToken,\n outputToken: args.outputToken,\n inputTokenAmount: args.inputTokenAmount,\n minOutputTokenAmount: args.minOutputTokenAmount,\n transformations: args.transformations\n })\n ),\n state.mtx.value\n );\n }\n\n /// @dev Extract arguments from call data by copying everything after the\n /// 4-byte selector into a new byte array.\n /// @param callData The call data from which arguments are to be extracted.\n /// @return args The extracted arguments as a byte array.\n function _extractArgumentsFromCallData(\n bytes memory callData\n )\n private\n pure\n returns (bytes memory args)\n {\n args = new bytes(callData.length - 4);\n uint256 fromMem;\n uint256 toMem;\n\n assembly {\n fromMem := add(callData, 36) // skip length and 4-byte selector\n toMem := add(args, 32) // write after length prefix\n }\n\n LibBytesV06.memCopy(toMem, fromMem, args.length);\n\n return args;\n }\n\n /// @dev Execute a `INativeOrdersFeature.fillLimitOrder()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `INativeOrdersFeature._fillLimitOrder()` variant, where we can override\n /// the taker address.\n function _executeFillLimitOrderCall(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n LibNativeOrder.LimitOrder memory order;\n LibSignature.Signature memory signature;\n uint128 takerTokenFillAmount;\n\n bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);\n (order, signature, takerTokenFillAmount) = abi.decode(args, (LibNativeOrder.LimitOrder, LibSignature.Signature, uint128));\n\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n INativeOrdersFeature._fillLimitOrder.selector,\n order,\n signature,\n takerTokenFillAmount,\n state.mtx.signer, // taker is mtx signer\n msg.sender\n ),\n state.mtx.value\n );\n }\n\n /// @dev Execute a `INativeOrdersFeature.fillRfqOrder()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `INativeOrdersFeature._fillRfqOrder()` variant, where we can overrideunimpleme\n /// the taker address.\n function _executeFillRfqOrderCall(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n LibNativeOrder.RfqOrder memory order;\n LibSignature.Signature memory signature;\n uint128 takerTokenFillAmount;\n\n bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);\n (order, signature, takerTokenFillAmount) = abi.decode(args, (LibNativeOrder.RfqOrder, LibSignature.Signature, uint128));\n\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n INativeOrdersFeature._fillRfqOrder.selector,\n order,\n signature,\n takerTokenFillAmount,\n state.mtx.signer // taker is mtx signer\n ),\n state.mtx.value\n );\n }\n\n /// @dev Make an arbitrary internal, meta-transaction call.\n /// Warning: Do not let unadulterated `callData` into this function.\n function _callSelf(bytes32 hash, bytes memory callData, uint256 value)\n private\n returns (bytes memory returnResult)\n {\n bool success;\n (success, returnResult) = address(this).call{value: value}(callData);\n if (!success) {\n LibMetaTransactionsRichErrors.MetaTransactionCallFailedError(\n hash,\n callData,\n returnResult\n ).rrevert();\n }\n }\n}\n"
},
"../errors/LibMetaTransactionsRichErrors.sol": {
"id": 2,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibMetaTransactionsRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function InvalidMetaTransactionsArrayLengthsError(\n uint256 mtxCount,\n uint256 signatureCount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidMetaTransactionsArrayLengthsError(uint256,uint256)\")),\n mtxCount,\n signatureCount\n );\n }\n\n function MetaTransactionUnsupportedFunctionError(\n bytes32 mtxHash,\n bytes4 selector\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionUnsupportedFunctionError(bytes32,bytes4)\")),\n mtxHash,\n selector\n );\n }\n\n function MetaTransactionWrongSenderError(\n bytes32 mtxHash,\n address sender,\n address expectedSender\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionWrongSenderError(bytes32,address,address)\")),\n mtxHash,\n sender,\n expectedSender\n );\n }\n\n function MetaTransactionExpiredError(\n bytes32 mtxHash,\n uint256 time,\n uint256 expirationTime\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionExpiredError(bytes32,uint256,uint256)\")),\n mtxHash,\n time,\n expirationTime\n );\n }\n\n function MetaTransactionGasPriceError(\n bytes32 mtxHash,\n uint256 gasPrice,\n uint256 minGasPrice,\n uint256 maxGasPrice\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionGasPriceError(bytes32,uint256,uint256,uint256)\")),\n mtxHash,\n gasPrice,\n minGasPrice,\n maxGasPrice\n );\n }\n\n function MetaTransactionInsufficientEthError(\n bytes32 mtxHash,\n uint256 ethBalance,\n uint256 ethRequired\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionInsufficientEthError(bytes32,uint256,uint256)\")),\n mtxHash,\n ethBalance,\n ethRequired\n );\n }\n\n function MetaTransactionInvalidSignatureError(\n bytes32 mtxHash,\n bytes memory signature,\n bytes memory errData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionInvalidSignatureError(bytes32,bytes,bytes)\")),\n mtxHash,\n signature,\n errData\n );\n }\n\n function MetaTransactionAlreadyExecutedError(\n bytes32 mtxHash,\n uint256 executedBlockNumber\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionAlreadyExecutedError(bytes32,uint256)\")),\n mtxHash,\n executedBlockNumber\n );\n }\n\n function MetaTransactionCallFailedError(\n bytes32 mtxHash,\n bytes memory callData,\n bytes memory returnData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionCallFailedError(bytes32,bytes,bytes)\")),\n mtxHash,\n callData,\n returnData\n );\n }\n}\n"
},
"../fixins/FixinReentrancyGuard.sol": {
"id": 43,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../storage/LibReentrancyGuardStorage.sol\";\n\n\n/// @dev Common feature utilities.\nabstract contract FixinReentrancyGuard {\n\n using LibRichErrorsV06 for bytes;\n using LibBytesV06 for bytes;\n\n // Combinable reentrancy flags.\n /// @dev Reentrancy guard flag for meta-transaction functions.\n uint256 constant internal REENTRANCY_MTX = 0x1;\n\n /// @dev Cannot reenter a function with the same reentrancy guard flags.\n modifier nonReentrant(uint256 reentrancyFlags) virtual {\n LibReentrancyGuardStorage.Storage storage stor =\n LibReentrancyGuardStorage.getStorage();\n {\n uint256 currentFlags = stor.reentrancyFlags;\n // Revert if any bits in `reentrancyFlags` has already been set.\n if ((currentFlags & reentrancyFlags) != 0) {\n LibCommonRichErrors.IllegalReentrancyError(\n msg.data.readBytes4(0),\n reentrancyFlags\n ).rrevert();\n }\n // Update reentrancy flags.\n stor.reentrancyFlags = currentFlags | reentrancyFlags;\n }\n\n _;\n\n // Clear reentrancy flags.\n stor.reentrancyFlags = stor.reentrancyFlags & (~reentrancyFlags);\n }\n}\n"
},
"../storage/LibReentrancyGuardStorage.sol": {
"id": 53,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IFlashWallet.sol\";\n\n\n/// @dev Storage helpers for the `FixinReentrancyGuard` mixin.\nlibrary LibReentrancyGuardStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Reentrancy flags set whenever a non-reentrant function is entered\n // and cleared when it is exited.\n uint256 reentrancyFlags;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.ReentrancyGuard\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../fixins/FixinEIP712.sol": {
"id": 41,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\n\n\n/// @dev EIP712 helpers for features.\nabstract contract FixinEIP712 {\n\n /// @dev The domain hash separator for the entire exchange proxy.\n bytes32 public immutable EIP712_DOMAIN_SEPARATOR;\n\n constructor(address zeroExAddress) internal {\n // Compute `EIP712_DOMAIN_SEPARATOR`\n {\n uint256 chainId;\n assembly { chainId := chainid() }\n EIP712_DOMAIN_SEPARATOR = keccak256(\n abi.encode(\n keccak256(\n \"EIP712Domain(\"\n \"string name,\"\n \"string version,\"\n \"uint256 chainId,\"\n \"address verifyingContract\"\n \")\"\n ),\n keccak256(\"ZeroEx\"),\n keccak256(\"1.0.0\"),\n chainId,\n zeroExAddress\n )\n );\n }\n }\n\n function _getEIP712Hash(bytes32 structHash)\n internal\n view\n returns (bytes32 eip712Hash)\n {\n return keccak256(abi.encodePacked(\n hex\"1901\",\n EIP712_DOMAIN_SEPARATOR,\n structHash\n ));\n }\n}\n"
},
"../storage/LibMetaTransactionsStorage.sol": {
"id": 49,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `MetaTransactions` feature.\nlibrary LibMetaTransactionsStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The block number when a hash was executed.\n mapping (bytes32 => uint256) mtxHashToExecutedBlockNumber;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.MetaTransactions\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../features/interfaces/IMetaTransactionsFeature.sol": {
"id": 27,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\n\n/// @dev Meta-transactions feature.\ninterface IMetaTransactionsFeature {\n /// @dev Describes an exchange proxy meta transaction.\n struct MetaTransactionData {\n // Signer of meta-transaction. On whose behalf to execute the MTX.\n address payable signer;\n // Required sender, or NULL for anyone.\n address sender;\n // Minimum gas price.\n uint256 minGasPrice;\n // Maximum gas price.\n uint256 maxGasPrice;\n // MTX is invalid after this time.\n uint256 expirationTimeSeconds;\n // Nonce to make this MTX unique.\n uint256 salt;\n // Encoded call data to a function on the exchange proxy.\n bytes callData;\n // Amount of ETH to attach to the call.\n uint256 value;\n // ERC20 fee `signer` pays `sender`.\n IERC20TokenV06 feeToken;\n // ERC20 fee amount.\n uint256 feeAmount;\n }\n\n /// @dev Emitted whenever a meta-transaction is executed via\n /// `executeMetaTransaction()` or `executeMetaTransactions()`.\n /// @param hash The meta-transaction hash.\n /// @param selector The selector of the function being executed.\n /// @param signer Who to execute the meta-transaction on behalf of.\n /// @param sender Who executed the meta-transaction.\n event MetaTransactionExecuted(\n bytes32 hash,\n bytes4 indexed selector,\n address signer,\n address sender\n );\n\n /// @dev Execute a single meta-transaction.\n /// @param mtx The meta-transaction.\n /// @param signature The signature by `mtx.signer`.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function executeMetaTransaction(\n MetaTransactionData calldata mtx,\n LibSignature.Signature calldata signature\n )\n external\n payable\n returns (bytes memory returnResult);\n\n /// @dev Execute multiple meta-transactions.\n /// @param mtxs The meta-transactions.\n /// @param signatures The signature by each respective `mtx.signer`.\n /// @return returnResults The ABI-encoded results of the underlying calls.\n function batchExecuteMetaTransactions(\n MetaTransactionData[] calldata mtxs,\n LibSignature.Signature[] calldata signatures\n )\n external\n payable\n returns (bytes[] memory returnResults);\n\n /// @dev Get the block at which a meta-transaction has been executed.\n /// @param mtx The meta-transaction.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionExecutedBlock(MetaTransactionData calldata mtx)\n external\n view\n returns (uint256 blockNumber);\n\n /// @dev Get the block at which a meta-transaction hash has been executed.\n /// @param mtxHash The meta-transaction hash.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionHashExecutedBlock(bytes32 mtxHash)\n external\n view\n returns (uint256 blockNumber);\n\n /// @dev Get the EIP712 hash of a meta-transaction.\n /// @param mtx The meta-transaction.\n /// @return mtxHash The EIP712 hash of `mtx`.\n function getMetaTransactionHash(MetaTransactionData calldata mtx)\n external\n view\n returns (bytes32 mtxHash);\n}\n"
},
"../features/libs/LibSignature.sol": {
"id": 35,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../../errors/LibSignatureRichErrors.sol\";\n\n\n/// @dev A library for validating signatures.\nlibrary LibSignature {\n using LibRichErrorsV06 for bytes;\n\n // '\\x19Ethereum Signed Message:\\n32\\x00\\x00\\x00\\x00' in a word.\n uint256 private constant ETH_SIGN_HASH_PREFIX =\n 0x19457468657265756d205369676e6564204d6573736167653a0a333200000000;\n /// @dev Exclusive upper limit on ECDSA signatures 'R' values.\n /// The valid range is given by fig (282) of the yellow paper.\n uint256 private constant ECDSA_SIGNATURE_R_LIMIT =\n uint256(0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141);\n /// @dev Exclusive upper limit on ECDSA signatures 'S' values.\n /// The valid range is given by fig (283) of the yellow paper.\n uint256 private constant ECDSA_SIGNATURE_S_LIMIT = ECDSA_SIGNATURE_R_LIMIT / 2 + 1;\n\n /// @dev Allowed signature types.\n enum SignatureType {\n ILLEGAL,\n INVALID,\n EIP712,\n ETHSIGN\n }\n\n /// @dev Encoded EC signature.\n struct Signature {\n // How to validate the signature.\n SignatureType signatureType;\n // EC Signature data.\n uint8 v;\n // EC Signature data.\n bytes32 r;\n // EC Signature data.\n bytes32 s;\n }\n\n /// @dev Retrieve the signer of a signature.\n /// Throws if the signature can't be validated.\n /// @param hash The hash that was signed.\n /// @param signature The signature.\n /// @return recovered The recovered signer address.\n function getSignerOfHash(\n bytes32 hash,\n Signature memory signature\n )\n internal\n pure\n returns (address recovered)\n {\n // Ensure this is a signature type that can be validated against a hash.\n _validateHashCompatibleSignature(hash, signature);\n\n if (signature.signatureType == SignatureType.EIP712) {\n // Signed using EIP712\n recovered = ecrecover(\n hash,\n signature.v,\n signature.r,\n signature.s\n );\n } else if (signature.signatureType == SignatureType.ETHSIGN) {\n // Signed using `eth_sign`\n // Need to hash `hash` with \"\\x19Ethereum Signed Message:\\n32\" prefix\n // in packed encoding.\n bytes32 ethSignHash;\n assembly {\n // Use scratch space\n mstore(0, ETH_SIGN_HASH_PREFIX) // length of 28 bytes\n mstore(28, hash) // length of 32 bytes\n ethSignHash := keccak256(0, 60)\n }\n recovered = ecrecover(\n ethSignHash,\n signature.v,\n signature.r,\n signature.s\n );\n }\n // `recovered` can be null if the signature values are out of range.\n if (recovered == address(0)) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,\n hash\n ).rrevert();\n }\n }\n\n /// @dev Validates that a signature is compatible with a hash signee.\n /// @param hash The hash that was signed.\n /// @param signature The signature.\n function _validateHashCompatibleSignature(\n bytes32 hash,\n Signature memory signature\n )\n private\n pure\n {\n // Ensure the r and s are within malleability limits.\n if (uint256(signature.r) >= ECDSA_SIGNATURE_R_LIMIT ||\n uint256(signature.s) >= ECDSA_SIGNATURE_S_LIMIT)\n {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,\n hash\n ).rrevert();\n }\n\n // Always illegal signature.\n if (signature.signatureType == SignatureType.ILLEGAL) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.ILLEGAL,\n hash\n ).rrevert();\n }\n\n // Always invalid.\n if (signature.signatureType == SignatureType.INVALID) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.ALWAYS_INVALID,\n hash\n ).rrevert();\n }\n\n // Solidity should check that the signature type is within enum range for us\n // when abi-decoding.\n }\n}\n"
},
"../errors/LibSignatureRichErrors.sol": {
"id": 6,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSignatureRichErrors {\n\n enum SignatureValidationErrorCodes {\n ALWAYS_INVALID,\n INVALID_LENGTH,\n UNSUPPORTED,\n ILLEGAL,\n WRONG_SIGNER,\n BAD_SIGNATURE_DATA\n }\n\n // solhint-disable func-name-mixedcase\n\n function SignatureValidationError(\n SignatureValidationErrorCodes code,\n bytes32 hash,\n address signerAddress,\n bytes memory signature\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SignatureValidationError(uint8,bytes32,address,bytes)\")),\n code,\n hash,\n signerAddress,\n signature\n );\n }\n\n function SignatureValidationError(\n SignatureValidationErrorCodes code,\n bytes32 hash\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SignatureValidationError(uint8,bytes32)\")),\n code,\n hash\n );\n }\n}\n"
},
"../features/interfaces/INativeOrdersFeature.sol": {
"id": 29,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./INativeOrdersEvents.sol\";\n\n\n/// @dev Feature for interacting with limit orders.\ninterface INativeOrdersFeature is\n INativeOrdersEvents\n{\n\n /// @dev Transfers protocol fees from the `FeeCollector` pools into\n /// the staking contract.\n /// @param poolIds Staking pool IDs\n function transferProtocolFeesForPools(bytes32[] calldata poolIds)\n external;\n\n /// @dev Fill a limit order. The taker and sender will be the caller.\n /// @param order The limit order. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n payable\n returns (uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n returns (uint128 makerTokenFilledAmount);\n\n /// @dev Fill a limit order. Internal variant. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// `msg.sender` (not `sender`).\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @param sender The order sender.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount,\n address taker,\n address sender\n )\n external\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order. Internal variant.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n external\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Cancel a single limit order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The limit order.\n function cancelLimitOrder(LibNativeOrder.LimitOrder calldata order)\n external;\n\n /// @dev Cancel a single RFQ order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The RFQ order.\n function cancelRfqOrder(LibNativeOrder.RfqOrder calldata order)\n external;\n\n /// @dev Mark what tx.origin addresses are allowed to fill an order that\n /// specifies the message sender as its txOrigin.\n /// @param origins An array of origin addresses to update.\n /// @param allowed True to register, false to unregister.\n function registerAllowedRfqOrigins(address[] memory origins, bool allowed)\n external;\n\n /// @dev Cancel multiple limit orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The limit orders.\n function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] calldata orders)\n external;\n\n /// @dev Cancel multiple RFQ orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The RFQ orders.\n function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] calldata orders)\n external;\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairLimitOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n external;\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairLimitOrders(\n IERC20TokenV06[] calldata makerTokens,\n IERC20TokenV06[] calldata takerTokens,\n uint256[] calldata minValidSalts\n )\n external;\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairRfqOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n external;\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairRfqOrders(\n IERC20TokenV06[] calldata makerTokens,\n IERC20TokenV06[] calldata takerTokens,\n uint256[] calldata minValidSalts\n )\n external;\n\n /// @dev Get the order info for a limit order.\n /// @param order The limit order.\n /// @return orderInfo Info about the order.\n function getLimitOrderInfo(LibNativeOrder.LimitOrder calldata order)\n external\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo);\n\n /// @dev Get the order info for an RFQ order.\n /// @param order The RFQ order.\n /// @return orderInfo Info about the order.\n function getRfqOrderInfo(LibNativeOrder.RfqOrder calldata order)\n external\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo);\n\n /// @dev Get the canonical hash of a limit order.\n /// @param order The limit order.\n /// @return orderHash The order hash.\n function getLimitOrderHash(LibNativeOrder.LimitOrder calldata order)\n external\n view\n returns (bytes32 orderHash);\n\n /// @dev Get the canonical hash of an RFQ order.\n /// @param order The RFQ order.\n /// @return orderHash The order hash.\n function getRfqOrderHash(LibNativeOrder.RfqOrder calldata order)\n external\n view\n returns (bytes32 orderHash);\n\n /// @dev Get the protocol fee multiplier. This should be multiplied by the\n /// gas price to arrive at the required protocol fee to fill a native order.\n /// @return multiplier The protocol fee multiplier.\n function getProtocolFeeMultiplier()\n external\n view\n returns (uint32 multiplier);\n\n /// @dev Get order info, fillable amount, and signature validity for a limit order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getLimitOrderRelevantState(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n );\n\n /// @dev Get order info, fillable amount, and signature validity for an RFQ order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getRfqOrderRelevantState(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n );\n\n /// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getLimitOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The limit orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetLimitOrderRelevantStates(\n LibNativeOrder.LimitOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n );\n\n /// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getRfqOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The RFQ orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetRfqOrderRelevantStates(\n LibNativeOrder.RfqOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n );\n}\n"
},
"../features/libs/LibNativeOrder.sol": {
"id": 34,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\n\n\n/// @dev A library for common native order operations.\nlibrary LibNativeOrder {\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n enum OrderStatus {\n INVALID,\n FILLABLE,\n FILLED,\n CANCELLED,\n EXPIRED\n }\n\n /// @dev A standard OTC or OO limit order.\n struct LimitOrder {\n IERC20TokenV06 makerToken;\n IERC20TokenV06 takerToken;\n uint128 makerAmount;\n uint128 takerAmount;\n uint128 takerTokenFeeAmount;\n address maker;\n address taker;\n address sender;\n address feeRecipient;\n bytes32 pool;\n uint64 expiry;\n uint256 salt;\n }\n\n /// @dev An RFQ limit order.\n struct RfqOrder {\n IERC20TokenV06 makerToken;\n IERC20TokenV06 takerToken;\n uint128 makerAmount;\n uint128 takerAmount;\n address maker;\n address taker;\n address txOrigin;\n bytes32 pool;\n uint64 expiry;\n uint256 salt;\n }\n\n /// @dev Info on a limit or RFQ order.\n struct OrderInfo {\n bytes32 orderHash;\n OrderStatus status;\n uint128 takerTokenFilledAmount;\n }\n\n uint256 private constant UINT_128_MASK = (1 << 128) - 1;\n uint256 private constant UINT_64_MASK = (1 << 64) - 1;\n uint256 private constant ADDRESS_MASK = (1 << 160) - 1;\n\n // The type hash for limit orders, which is:\n // keccak256(abi.encodePacked(\n // \"LimitOrder(\",\n // \"address makerToken,\",\n // \"address takerToken,\",\n // \"uint128 makerAmount,\",\n // \"uint128 takerAmount,\",\n // \"uint128 takerTokenFeeAmount,\",\n // \"address maker,\",\n // \"address taker,\",\n // \"address sender,\",\n // \"address feeRecipient,\",\n // \"bytes32 pool,\",\n // \"uint64 expiry,\",\n // \"uint256 salt\"\n // \")\"\n // ))\n uint256 private constant _LIMIT_ORDER_TYPEHASH =\n 0xce918627cb55462ddbb85e73de69a8b322f2bc88f4507c52fcad6d4c33c29d49;\n\n // The type hash for RFQ orders, which is:\n // keccak256(abi.encodePacked(\n // \"RfqOrder(\",\n // \"address makerToken,\",\n // \"address takerToken,\",\n // \"uint128 makerAmount,\",\n // \"uint128 takerAmount,\",\n // \"address maker,\",\n // \"address taker,\",\n // \"address txOrigin,\",\n // \"bytes32 pool,\",\n // \"uint64 expiry,\",\n // \"uint256 salt\"\n // \")\"\n // ))\n uint256 private constant _RFQ_ORDER_TYPEHASH =\n 0xe593d3fdfa8b60e5e17a1b2204662ecbe15c23f2084b9ad5bae40359540a7da9;\n\n /// @dev Get the struct hash of a limit order.\n /// @param order The limit order.\n /// @return structHash The struct hash of the order.\n function getLimitOrderStructHash(LimitOrder memory order)\n internal\n pure\n returns (bytes32 structHash)\n {\n // The struct hash is:\n // keccak256(abi.encode(\n // TYPE_HASH,\n // order.makerToken,\n // order.takerToken,\n // order.makerAmount,\n // order.takerAmount,\n // order.takerTokenFeeAmount,\n // order.maker,\n // order.taker,\n // order.sender,\n // order.feeRecipient,\n // order.pool,\n // order.expiry,\n // order.salt,\n // ))\n assembly {\n let mem := mload(0x40)\n mstore(mem, _LIMIT_ORDER_TYPEHASH)\n // order.makerToken;\n mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))\n // order.takerToken;\n mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))\n // order.makerAmount;\n mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))\n // order.takerAmount;\n mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))\n // order.takerTokenFeeAmount;\n mstore(add(mem, 0xA0), and(UINT_128_MASK, mload(add(order, 0x80))))\n // order.maker;\n mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))\n // order.taker;\n mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))\n // order.sender;\n mstore(add(mem, 0x100), and(ADDRESS_MASK, mload(add(order, 0xE0))))\n // order.feeRecipient;\n mstore(add(mem, 0x120), and(ADDRESS_MASK, mload(add(order, 0x100))))\n // order.pool;\n mstore(add(mem, 0x140), mload(add(order, 0x120)))\n // order.expiry;\n mstore(add(mem, 0x160), and(UINT_64_MASK, mload(add(order, 0x140))))\n // order.salt;\n mstore(add(mem, 0x180), mload(add(order, 0x160)))\n structHash := keccak256(mem, 0x1A0)\n }\n }\n\n /// @dev Get the struct hash of a RFQ order.\n /// @param order The RFQ order.\n /// @return structHash The struct hash of the order.\n function getRfqOrderStructHash(RfqOrder memory order)\n internal\n pure\n returns (bytes32 structHash)\n {\n // The struct hash is:\n // keccak256(abi.encode(\n // TYPE_HASH,\n // order.makerToken,\n // order.takerToken,\n // order.makerAmount,\n // order.takerAmount,\n // order.maker,\n // order.taker,\n // order.txOrigin,\n // order.pool,\n // order.expiry,\n // order.salt,\n // ))\n assembly {\n let mem := mload(0x40)\n mstore(mem, _RFQ_ORDER_TYPEHASH)\n // order.makerToken;\n mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))\n // order.takerToken;\n mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))\n // order.makerAmount;\n mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))\n // order.takerAmount;\n mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))\n // order.maker;\n mstore(add(mem, 0xA0), and(ADDRESS_MASK, mload(add(order, 0x80))))\n // order.taker;\n mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))\n // order.txOrigin;\n mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))\n // order.pool;\n mstore(add(mem, 0x100), mload(add(order, 0xE0)))\n // order.expiry;\n mstore(add(mem, 0x120), and(UINT_64_MASK, mload(add(order, 0x100))))\n // order.salt;\n mstore(add(mem, 0x140), mload(add(order, 0x120)))\n structHash := keccak256(mem, 0x160)\n }\n }\n\n /// @dev Refund any leftover protocol fees in `msg.value` to `msg.sender`.\n /// @param ethProtocolFeePaid How much ETH was paid in protocol fees.\n function refundExcessProtocolFeeToSender(uint256 ethProtocolFeePaid)\n internal\n {\n if (msg.value > ethProtocolFeePaid && msg.sender != address(this)) {\n uint256 refundAmount = msg.value.safeSub(ethProtocolFeePaid);\n (bool success,) = msg\n .sender\n .call{value: refundAmount}(\"\");\n if (!success) {\n LibNativeOrdersRichErrors.ProtocolFeeRefundFailed(\n msg.sender,\n refundAmount\n ).rrevert();\n }\n }\n }\n}\n"
},
"../errors/LibNativeOrdersRichErrors.sol": {
"id": 3,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibNativeOrdersRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function ProtocolFeeRefundFailed(\n address receiver,\n uint256 refundAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"ProtocolFeeRefundFailed(address,uint256)\")),\n receiver,\n refundAmount\n );\n }\n\n function OrderNotFillableByOriginError(\n bytes32 orderHash,\n address txOrigin,\n address orderTxOrigin\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableByOriginError(bytes32,address,address)\")),\n orderHash,\n txOrigin,\n orderTxOrigin\n );\n }\n\n function OrderNotFillableError(\n bytes32 orderHash,\n uint8 orderStatus\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableError(bytes32,uint8)\")),\n orderHash,\n orderStatus\n );\n }\n\n function OrderNotSignedByMakerError(\n bytes32 orderHash,\n address signer,\n address maker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotSignedByMakerError(bytes32,address,address)\")),\n orderHash,\n signer,\n maker\n );\n }\n\n function OrderNotFillableBySenderError(\n bytes32 orderHash,\n address sender,\n address orderSender\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableBySenderError(bytes32,address,address)\")),\n orderHash,\n sender,\n orderSender\n );\n }\n\n function OrderNotFillableByTakerError(\n bytes32 orderHash,\n address taker,\n address orderTaker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableByTakerError(bytes32,address,address)\")),\n orderHash,\n taker,\n orderTaker\n );\n }\n\n function CancelSaltTooLowError(\n uint256 minValidSalt,\n uint256 oldMinValidSalt\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"CancelSaltTooLowError(uint256,uint256)\")),\n minValidSalt,\n oldMinValidSalt\n );\n }\n\n function FillOrKillFailedError(\n bytes32 orderHash,\n uint256 takerTokenFilledAmount,\n uint256 takerTokenFillAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"FillOrKillFailedError(bytes32,uint256,uint256)\")),\n orderHash,\n takerTokenFilledAmount,\n takerTokenFillAmount\n );\n }\n\n function OnlyOrderMakerAllowed(\n bytes32 orderHash,\n address sender,\n address maker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyOrderMakerAllowed(bytes32,address,address)\")),\n orderHash,\n sender,\n maker\n );\n }\n\n function BatchFillIncompleteError(\n bytes32 orderHash,\n uint256 takerTokenFilledAmount,\n uint256 takerTokenFillAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"BatchFillIncompleteError(bytes32,uint256,uint256)\")),\n orderHash,\n takerTokenFilledAmount,\n takerTokenFillAmount\n );\n }\n}\n"
},
"../features/interfaces/INativeOrdersEvents.sol": {
"id": 28,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\n\n\n/// @dev Events emitted by NativeOrdersFeature.\ninterface INativeOrdersEvents {\n\n /// @dev Emitted whenever a `LimitOrder` is filled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The maker of the order.\n /// @param taker The taker of the order.\n /// @param feeRecipient Fee recipient of the order.\n /// @param takerTokenFilledAmount How much taker token was filled.\n /// @param makerTokenFilledAmount How much maker token was filled.\n /// @param protocolFeePaid How much protocol fee was paid.\n /// @param pool The fee pool associated with this order.\n event LimitOrderFilled(\n bytes32 orderHash,\n address maker,\n address taker,\n address feeRecipient,\n address makerToken,\n address takerToken,\n uint128 takerTokenFilledAmount,\n uint128 makerTokenFilledAmount,\n uint128 takerTokenFeeFilledAmount,\n uint256 protocolFeePaid,\n bytes32 pool\n );\n\n /// @dev Emitted whenever an `RfqOrder` is filled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The maker of the order.\n /// @param taker The taker of the order.\n /// @param takerTokenFilledAmount How much taker token was filled.\n /// @param makerTokenFilledAmount How much maker token was filled.\n /// @param pool The fee pool associated with this order.\n event RfqOrderFilled(\n bytes32 orderHash,\n address maker,\n address taker,\n address makerToken,\n address takerToken,\n uint128 takerTokenFilledAmount,\n uint128 makerTokenFilledAmount,\n bytes32 pool\n );\n\n /// @dev Emitted whenever a limit or RFQ order is cancelled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The order maker.\n event OrderCancelled(\n bytes32 orderHash,\n address maker\n );\n\n /// @dev Emitted whenever Limit orders are cancelled by pair by a maker.\n /// @param maker The maker of the order.\n /// @param makerToken The maker token in a pair for the orders cancelled.\n /// @param takerToken The taker token in a pair for the orders cancelled.\n /// @param minValidSalt The new minimum valid salt an order with this pair must\n /// have.\n event PairCancelledLimitOrders(\n address maker,\n address makerToken,\n address takerToken,\n uint256 minValidSalt\n );\n\n /// @dev Emitted whenever RFQ orders are cancelled by pair by a maker.\n /// @param maker The maker of the order.\n /// @param makerToken The maker token in a pair for the orders cancelled.\n /// @param takerToken The taker token in a pair for the orders cancelled.\n /// @param minValidSalt The new minimum valid salt an order with this pair must\n /// have.\n event PairCancelledRfqOrders(\n address maker,\n address makerToken,\n address takerToken,\n uint256 minValidSalt\n );\n\n /// @dev Emitted when new addresses are allowed or disallowed to fill\n /// orders with a given txOrigin.\n /// @param origin The address doing the allowing.\n /// @param addrs The address being allowed/disallowed.\n /// @param allowed Indicates whether the address should be allowed.\n event RfqOrderOriginsAllowed(\n address origin,\n address[] addrs,\n bool allowed\n );\n}\n"
},
"../features/NativeOrdersFeature.sol": {
"id": 20,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../migrations/LibMigrate.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/INativeOrdersFeature.sol\";\nimport \"./native_orders/NativeOrdersSettlement.sol\";\n\n\n/// @dev Feature for interacting with limit and RFQ orders.\ncontract NativeOrdersFeature is\n IFeature,\n NativeOrdersSettlement\n{\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"LimitOrders\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 1);\n\n constructor(\n address zeroExAddress,\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier,\n bytes32 greedyTokensBloomFilter\n )\n public\n NativeOrdersSettlement(\n zeroExAddress,\n weth,\n staking,\n feeCollectorController,\n protocolFeeMultiplier,\n greedyTokensBloomFilter\n )\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate()\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.transferProtocolFeesForPools.selector);\n _registerFeatureFunction(this.fillLimitOrder.selector);\n _registerFeatureFunction(this.fillRfqOrder.selector);\n _registerFeatureFunction(this.fillOrKillLimitOrder.selector);\n _registerFeatureFunction(this.fillOrKillRfqOrder.selector);\n _registerFeatureFunction(this._fillLimitOrder.selector);\n _registerFeatureFunction(this._fillRfqOrder.selector);\n _registerFeatureFunction(this.cancelLimitOrder.selector);\n _registerFeatureFunction(this.cancelRfqOrder.selector);\n _registerFeatureFunction(this.batchCancelLimitOrders.selector);\n _registerFeatureFunction(this.batchCancelRfqOrders.selector);\n _registerFeatureFunction(this.cancelPairLimitOrders.selector);\n _registerFeatureFunction(this.batchCancelPairLimitOrders.selector);\n _registerFeatureFunction(this.cancelPairRfqOrders.selector);\n _registerFeatureFunction(this.batchCancelPairRfqOrders.selector);\n _registerFeatureFunction(this.getLimitOrderInfo.selector);\n _registerFeatureFunction(this.getRfqOrderInfo.selector);\n _registerFeatureFunction(this.getLimitOrderHash.selector);\n _registerFeatureFunction(this.getRfqOrderHash.selector);\n _registerFeatureFunction(this.getProtocolFeeMultiplier.selector);\n _registerFeatureFunction(this.registerAllowedRfqOrigins.selector);\n _registerFeatureFunction(this.getLimitOrderRelevantState.selector);\n _registerFeatureFunction(this.getRfqOrderRelevantState.selector);\n _registerFeatureFunction(this.batchGetLimitOrderRelevantStates.selector);\n _registerFeatureFunction(this.batchGetRfqOrderRelevantStates.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n}\n"
},
"../features/native_orders/NativeOrdersSettlement.sol": {
"id": 39,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../fixins/FixinCommon.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../../vendor/v3/IStaking.sol\";\nimport \"../interfaces/INativeOrdersEvents.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./NativeOrdersCancellation.sol\";\nimport \"./NativeOrdersProtocolFees.sol\";\n\n\n/// @dev Mixin for settling limit and RFQ orders.\nabstract contract NativeOrdersSettlement is\n INativeOrdersEvents,\n NativeOrdersCancellation,\n NativeOrdersProtocolFees,\n FixinCommon\n{\n using LibSafeMathV06 for uint128;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Params for `_settleOrder()`.\n struct SettleOrderInfo {\n // Order hash.\n bytes32 orderHash;\n // Maker of the order.\n address maker;\n // Taker of the order.\n address taker;\n // Maker token.\n IERC20TokenV06 makerToken;\n // Taker token.\n IERC20TokenV06 takerToken;\n // Maker token amount.\n uint128 makerAmount;\n // Taker token amount.\n uint128 takerAmount;\n // Maximum taker token amount to fill.\n uint128 takerTokenFillAmount;\n // How much taker token amount has already been filled in this order.\n uint128 takerTokenFilledAmount;\n }\n\n /// @dev Params for `_fillLimitOrderPrivate()`\n struct FillLimitOrderPrivateParams {\n // The limit order.\n LibNativeOrder.LimitOrder order;\n // The order signature.\n LibSignature.Signature signature;\n // Maximum taker token to fill this order with.\n uint128 takerTokenFillAmount;\n // The order taker.\n address taker;\n // The order sender.\n address sender;\n }\n\n // @dev Fill results returned by `_fillLimitOrderPrivate()` and\n /// `_fillRfqOrderPrivate()`.\n struct FillNativeOrderResults {\n uint256 ethProtocolFeePaid;\n uint128 takerTokenFilledAmount;\n uint128 makerTokenFilledAmount;\n uint128 takerTokenFeeFilledAmount;\n }\n\n constructor(\n address zeroExAddress,\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier,\n bytes32 greedyTokensBloomFilter\n )\n public\n NativeOrdersCancellation(zeroExAddress, greedyTokensBloomFilter)\n NativeOrdersProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Fill a limit order. The taker and sender will be the caller.\n /// @param order The limit order. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: msg.sender,\n sender: msg.sender\n }));\n LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH should be attached to pay the\n /// protocol fee.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n msg.sender\n );\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n payable\n returns (uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: msg.sender,\n sender: msg.sender\n }));\n // Must have filled exactly the amount requested.\n if (results.takerTokenFilledAmount < takerTokenFillAmount) {\n LibNativeOrdersRichErrors.FillOrKillFailedError(\n getLimitOrderHash(order),\n results.takerTokenFilledAmount,\n takerTokenFillAmount\n ).rrevert();\n }\n LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);\n makerTokenFilledAmount = results.makerTokenFilledAmount;\n }\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n returns (uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n msg.sender\n );\n // Must have filled exactly the amount requested.\n if (results.takerTokenFilledAmount < takerTokenFillAmount) {\n LibNativeOrdersRichErrors.FillOrKillFailedError(\n getRfqOrderHash(order),\n results.takerTokenFilledAmount,\n takerTokenFillAmount\n ).rrevert();\n }\n makerTokenFilledAmount = results.makerTokenFilledAmount;\n }\n\n /// @dev Fill a limit order. Internal variant. ETH protocol fees can be\n /// attached to this call.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @param sender The order sender.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker,\n address sender\n )\n public\n virtual\n payable\n onlySelf\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: taker,\n sender: sender\n }));\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order. Internal variant. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// `msg.sender` (not `sender`).\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n public\n virtual\n onlySelf\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n taker\n );\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Mark what tx.origin addresses are allowed to fill an order that\n /// specifies the message sender as its txOrigin.\n /// @param origins An array of origin addresses to update.\n /// @param allowed True to register, false to unregister.\n function registerAllowedRfqOrigins(\n address[] memory origins,\n bool allowed\n )\n external\n {\n require(msg.sender == tx.origin,\n \"NativeOrdersFeature/NO_CONTRACT_ORIGINS\");\n\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n for (uint256 i = 0; i < origins.length; i++) {\n stor.originRegistry[msg.sender][origins[i]] = allowed;\n }\n\n emit RfqOrderOriginsAllowed(msg.sender, origins, allowed);\n }\n\n /// @dev Fill a limit order. Private variant. Does not refund protocol fees.\n /// @param params Function params.\n /// @return results Results of the fill.\n function _fillLimitOrderPrivate(FillLimitOrderPrivateParams memory params)\n private\n returns (FillNativeOrderResults memory results)\n {\n LibNativeOrder.OrderInfo memory orderInfo = getLimitOrderInfo(params.order);\n\n // Must be fillable.\n if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n LibNativeOrdersRichErrors.OrderNotFillableError(\n orderInfo.orderHash,\n uint8(orderInfo.status)\n ).rrevert();\n }\n\n // Must be fillable by the taker.\n if (params.order.taker != address(0) && params.order.taker != params.taker) {\n LibNativeOrdersRichErrors.OrderNotFillableByTakerError(\n orderInfo.orderHash,\n params.taker,\n params.order.taker\n ).rrevert();\n }\n\n // Must be fillable by the sender.\n if (params.order.sender != address(0) && params.order.sender != params.sender) {\n LibNativeOrdersRichErrors.OrderNotFillableBySenderError(\n orderInfo.orderHash,\n params.sender,\n params.order.sender\n ).rrevert();\n }\n\n // Signature must be valid for the order.\n {\n address signer = LibSignature.getSignerOfHash(\n orderInfo.orderHash,\n params.signature\n );\n if (signer != params.order.maker) {\n LibNativeOrdersRichErrors.OrderNotSignedByMakerError(\n orderInfo.orderHash,\n signer,\n params.order.maker\n ).rrevert();\n }\n }\n\n // Pay the protocol fee.\n results.ethProtocolFeePaid = _collectProtocolFee(params.order.pool);\n\n // Settle between the maker and taker.\n (results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(\n SettleOrderInfo({\n orderHash: orderInfo.orderHash,\n maker: params.order.maker,\n taker: params.taker,\n makerToken: IERC20TokenV06(params.order.makerToken),\n takerToken: IERC20TokenV06(params.order.takerToken),\n makerAmount: params.order.makerAmount,\n takerAmount: params.order.takerAmount,\n takerTokenFillAmount: params.takerTokenFillAmount,\n takerTokenFilledAmount: orderInfo.takerTokenFilledAmount\n })\n );\n\n // Pay the fee recipient.\n if (params.order.takerTokenFeeAmount > 0) {\n results.takerTokenFeeFilledAmount = uint128(LibMathV06.getPartialAmountFloor(\n results.takerTokenFilledAmount,\n params.order.takerAmount,\n params.order.takerTokenFeeAmount\n ));\n _transferERC20Tokens(\n params.order.takerToken,\n params.taker,\n params.order.feeRecipient,\n uint256(results.takerTokenFeeFilledAmount)\n );\n }\n\n emit LimitOrderFilled(\n orderInfo.orderHash,\n params.order.maker,\n params.taker,\n params.order.feeRecipient,\n address(params.order.makerToken),\n address(params.order.takerToken),\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount,\n results.takerTokenFeeFilledAmount,\n results.ethProtocolFeePaid,\n params.order.pool\n );\n }\n\n /// @dev Fill an RFQ order. Private variant. Does not refund protocol fees.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return results Results of the fill.\n function _fillRfqOrderPrivate(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n private\n returns (FillNativeOrderResults memory results)\n {\n LibNativeOrder.OrderInfo memory orderInfo = getRfqOrderInfo(order);\n\n // Must be fillable.\n if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n LibNativeOrdersRichErrors.OrderNotFillableError(\n orderInfo.orderHash,\n uint8(orderInfo.status)\n ).rrevert();\n }\n\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n // Must be fillable by the tx.origin.\n if (order.txOrigin != tx.origin && !stor.originRegistry[order.txOrigin][tx.origin]) {\n LibNativeOrdersRichErrors.OrderNotFillableByOriginError(\n orderInfo.orderHash,\n tx.origin,\n order.txOrigin\n ).rrevert();\n }\n }\n\n // Must be fillable by the taker.\n if (order.taker != address(0) && order.taker != taker) {\n LibNativeOrdersRichErrors.OrderNotFillableByTakerError(\n orderInfo.orderHash,\n taker,\n order.taker\n ).rrevert();\n }\n\n // Signature must be valid for the order.\n {\n address signer = LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n if (signer != order.maker) {\n LibNativeOrdersRichErrors.OrderNotSignedByMakerError(\n orderInfo.orderHash,\n signer,\n order.maker\n ).rrevert();\n }\n }\n\n // Settle between the maker and taker.\n (results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(\n SettleOrderInfo({\n orderHash: orderInfo.orderHash,\n maker: order.maker,\n taker: taker,\n makerToken: IERC20TokenV06(order.makerToken),\n takerToken: IERC20TokenV06(order.takerToken),\n makerAmount: order.makerAmount,\n takerAmount: order.takerAmount,\n takerTokenFillAmount: takerTokenFillAmount,\n takerTokenFilledAmount: orderInfo.takerTokenFilledAmount\n })\n );\n\n emit RfqOrderFilled(\n orderInfo.orderHash,\n order.maker,\n taker,\n address(order.makerToken),\n address(order.takerToken),\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount,\n order.pool\n );\n }\n\n /// @dev Settle the trade between an order's maker and taker.\n /// @param settleInfo Information needed to execute the settlement.\n /// @return takerTokenFilledAmount How much taker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _settleOrder(SettleOrderInfo memory settleInfo)\n private\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n // Clamp the taker token fill amount to the fillable amount.\n takerTokenFilledAmount = LibSafeMathV06.min128(\n settleInfo.takerTokenFillAmount,\n settleInfo.takerAmount.safeSub128(settleInfo.takerTokenFilledAmount)\n );\n // Compute the maker token amount.\n // This should never overflow because the values are all clamped to\n // (2^128-1).\n makerTokenFilledAmount = uint128(LibMathV06.getPartialAmountFloor(\n uint256(takerTokenFilledAmount),\n uint256(settleInfo.takerAmount),\n uint256(settleInfo.makerAmount)\n ));\n\n if (takerTokenFilledAmount == 0 || makerTokenFilledAmount == 0) {\n // Nothing to do.\n return (0, 0);\n }\n\n // Update filled state for the order.\n LibNativeOrdersStorage\n .getStorage()\n .orderHashToTakerTokenFilledAmount[settleInfo.orderHash] =\n // OK to overwrite the whole word because we shouldn't get to this\n // function if the order is cancelled.\n settleInfo.takerTokenFilledAmount.safeAdd128(takerTokenFilledAmount);\n\n // Transfer taker -> maker.\n _transferERC20Tokens(\n settleInfo.takerToken,\n settleInfo.taker,\n settleInfo.maker,\n takerTokenFilledAmount\n );\n\n // Transfer maker -> taker.\n _transferERC20Tokens(\n settleInfo.makerToken,\n settleInfo.maker,\n settleInfo.taker,\n makerTokenFilledAmount\n );\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol": {
"id": 66,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2019 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./LibSafeMathV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibMathRichErrorsV06.sol\";\n\n\nlibrary LibMathV06 {\n\n using LibSafeMathV06 for uint256;\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// Reverts if rounding error is >= 0.1%\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded down.\n function safeGetPartialAmountFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n if (isRoundingErrorFloor(\n numerator,\n denominator,\n target\n )) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(\n numerator,\n denominator,\n target\n ));\n }\n\n partialAmount = numerator.safeMul(target).safeDiv(denominator);\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// Reverts if rounding error is >= 0.1%\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded up.\n function safeGetPartialAmountCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n if (isRoundingErrorCeil(\n numerator,\n denominator,\n target\n )) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(\n numerator,\n denominator,\n target\n ));\n }\n\n // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):\n // ceil(a / b) = floor((a + b - 1) / b)\n // To implement `ceil(a / b)` using safeDiv.\n partialAmount = numerator.safeMul(target)\n .safeAdd(denominator.safeSub(1))\n .safeDiv(denominator);\n\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded down.\n function getPartialAmountFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n partialAmount = numerator.safeMul(target).safeDiv(denominator);\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded up.\n function getPartialAmountCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):\n // ceil(a / b) = floor((a + b - 1) / b)\n // To implement `ceil(a / b)` using safeDiv.\n partialAmount = numerator.safeMul(target)\n .safeAdd(denominator.safeSub(1))\n .safeDiv(denominator);\n\n return partialAmount;\n }\n\n /// @dev Checks if rounding error >= 0.1% when rounding down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to multiply with numerator/denominator.\n /// @return isError Rounding error is present.\n function isRoundingErrorFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bool isError)\n {\n if (denominator == 0) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());\n }\n\n // The absolute rounding error is the difference between the rounded\n // value and the ideal value. The relative rounding error is the\n // absolute rounding error divided by the absolute value of the\n // ideal value. This is undefined when the ideal value is zero.\n //\n // The ideal value is `numerator * target / denominator`.\n // Let's call `numerator * target % denominator` the remainder.\n // The absolute error is `remainder / denominator`.\n //\n // When the ideal value is zero, we require the absolute error to\n // be zero. Fortunately, this is always the case. The ideal value is\n // zero iff `numerator == 0` and/or `target == 0`. In this case the\n // remainder and absolute error are also zero.\n if (target == 0 || numerator == 0) {\n return false;\n }\n\n // Otherwise, we want the relative rounding error to be strictly\n // less than 0.1%.\n // The relative error is `remainder / (numerator * target)`.\n // We want the relative error less than 1 / 1000:\n // remainder / (numerator * denominator) < 1 / 1000\n // or equivalently:\n // 1000 * remainder < numerator * target\n // so we have a rounding error iff:\n // 1000 * remainder >= numerator * target\n uint256 remainder = mulmod(\n target,\n numerator,\n denominator\n );\n isError = remainder.safeMul(1000) >= numerator.safeMul(target);\n return isError;\n }\n\n /// @dev Checks if rounding error >= 0.1% when rounding up.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to multiply with numerator/denominator.\n /// @return isError Rounding error is present.\n function isRoundingErrorCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bool isError)\n {\n if (denominator == 0) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());\n }\n\n // See the comments in `isRoundingError`.\n if (target == 0 || numerator == 0) {\n // When either is zero, the ideal value and rounded value are zero\n // and there is no rounding error. (Although the relative error\n // is undefined.)\n return false;\n }\n // Compute remainder as before\n uint256 remainder = mulmod(\n target,\n numerator,\n denominator\n );\n remainder = denominator.safeSub(remainder) % denominator;\n isError = remainder.safeMul(1000) >= numerator.safeMul(target);\n return isError;\n }\n}\n"
},
"@0x/contracts-utils/contracts/src/v06/errors/LibMathRichErrorsV06.sol": {
"id": 71,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibMathRichErrorsV06 {\n\n // bytes4(keccak256(\"DivisionByZeroError()\"))\n bytes internal constant DIVISION_BY_ZERO_ERROR =\n hex\"a791837c\";\n\n // bytes4(keccak256(\"RoundingError(uint256,uint256,uint256)\"))\n bytes4 internal constant ROUNDING_ERROR_SELECTOR =\n 0x339f3de2;\n\n // solhint-disable func-name-mixedcase\n function DivisionByZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return DIVISION_BY_ZERO_ERROR;\n }\n\n function RoundingError(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n ROUNDING_ERROR_SELECTOR,\n numerator,\n denominator,\n target\n );\n }\n}\n"
},
"../storage/LibNativeOrdersStorage.sol": {
"id": 50,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for `NativeOrdersFeature`.\nlibrary LibNativeOrdersStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // How much taker token has been filled in order.\n // The lower `uint128` is the taker token fill amount.\n // The high bit will be `1` if the order was directly cancelled.\n mapping(bytes32 => uint256) orderHashToTakerTokenFilledAmount;\n // The minimum valid order salt for a given maker and order pair (maker, taker)\n // for limit orders.\n mapping(address => mapping(address => mapping(address => uint256)))\n limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;\n // The minimum valid order salt for a given maker and order pair (maker, taker)\n // for RFQ orders.\n mapping(address => mapping(address => mapping(address => uint256)))\n rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;\n // For a given order origin, which tx.origin addresses are allowed to\n // fill the order.\n mapping(address => mapping(address => bool)) originRegistry;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.NativeOrders\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../features/native_orders/NativeOrdersCancellation.sol": {
"id": 36,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../interfaces/INativeOrdersEvents.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./NativeOrdersInfo.sol\";\n\n/// @dev Feature for cancelling limit and RFQ orders.\nabstract contract NativeOrdersCancellation is\n INativeOrdersEvents,\n NativeOrdersInfo\n{\n using LibRichErrorsV06 for bytes;\n\n /// @dev Highest bit of a uint256, used to flag cancelled orders.\n uint256 private constant HIGH_BIT = 1 << 255;\n\n constructor(\n address zeroExAddress,\n bytes32 greedyTokensBloomFilter\n )\n internal\n NativeOrdersInfo(zeroExAddress, greedyTokensBloomFilter)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Cancel a single limit order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The limit order.\n function cancelLimitOrder(LibNativeOrder.LimitOrder memory order)\n public\n {\n bytes32 orderHash = getLimitOrderHash(order);\n if (msg.sender != order.maker) {\n LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(\n orderHash,\n msg.sender,\n order.maker\n ).rrevert();\n }\n _cancelOrderHash(orderHash, order.maker);\n }\n\n /// @dev Cancel a single RFQ order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The RFQ order.\n function cancelRfqOrder(LibNativeOrder.RfqOrder memory order)\n public\n {\n bytes32 orderHash = getRfqOrderHash(order);\n if (msg.sender != order.maker) {\n LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(\n orderHash,\n msg.sender,\n order.maker\n ).rrevert();\n }\n _cancelOrderHash(orderHash, order.maker);\n }\n\n /// @dev Cancel multiple limit orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The limit orders.\n function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] memory orders)\n public\n {\n for (uint256 i = 0; i < orders.length; ++i) {\n cancelLimitOrder(orders[i]);\n }\n }\n\n /// @dev Cancel multiple RFQ orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The RFQ orders.\n function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] memory orders)\n public\n {\n for (uint256 i = 0; i < orders.length; ++i) {\n cancelRfqOrder(orders[i]);\n }\n }\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairLimitOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n public\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n uint256 oldMinValidSalt =\n stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)];\n\n // New min salt must >= the old one.\n if (oldMinValidSalt > minValidSalt) {\n LibNativeOrdersRichErrors.\n CancelSaltTooLowError(minValidSalt, oldMinValidSalt)\n .rrevert();\n }\n\n stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)] = minValidSalt;\n\n emit PairCancelledLimitOrders(\n msg.sender,\n address(makerToken),\n address(takerToken),\n minValidSalt\n );\n }\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairLimitOrders(\n IERC20TokenV06[] memory makerTokens,\n IERC20TokenV06[] memory takerTokens,\n uint256[] memory minValidSalts\n )\n public\n {\n require(\n makerTokens.length == takerTokens.length &&\n makerTokens.length == minValidSalts.length,\n \"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS\"\n );\n\n for (uint256 i = 0; i < makerTokens.length; ++i) {\n cancelPairLimitOrders(\n makerTokens[i],\n takerTokens[i],\n minValidSalts[i]\n );\n }\n }\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairRfqOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n public\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n uint256 oldMinValidSalt =\n stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)];\n\n // New min salt must >= the old one.\n if (oldMinValidSalt > minValidSalt) {\n LibNativeOrdersRichErrors.\n CancelSaltTooLowError(minValidSalt, oldMinValidSalt)\n .rrevert();\n }\n\n stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)] = minValidSalt;\n\n emit PairCancelledRfqOrders(\n msg.sender,\n address(makerToken),\n address(takerToken),\n minValidSalt\n );\n }\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairRfqOrders(\n IERC20TokenV06[] memory makerTokens,\n IERC20TokenV06[] memory takerTokens,\n uint256[] memory minValidSalts\n )\n public\n {\n require(\n makerTokens.length == takerTokens.length &&\n makerTokens.length == minValidSalts.length,\n \"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS\"\n );\n\n for (uint256 i = 0; i < makerTokens.length; ++i) {\n cancelPairRfqOrders(\n makerTokens[i],\n takerTokens[i],\n minValidSalts[i]\n );\n }\n }\n\n /// @dev Cancel a limit or RFQ order directly by its order hash.\n /// @param orderHash The order's order hash.\n /// @param maker The order's maker.\n function _cancelOrderHash(bytes32 orderHash, address maker)\n private\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n // Set the high bit on the raw taker token fill amount to indicate\n // a cancel. It's OK to cancel twice.\n stor.orderHashToTakerTokenFilledAmount[orderHash] |= HIGH_BIT;\n\n emit OrderCancelled(orderHash, maker);\n }\n}\n"
},
"../features/native_orders/NativeOrdersInfo.sol": {
"id": 37,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol\";\nimport \"../../fixins/FixinEIP712.sol\";\nimport \"../../fixins/FixinTokenSpender.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\n\n\n/// @dev Feature for getting info about limit and RFQ orders.\nabstract contract NativeOrdersInfo is\n FixinEIP712,\n FixinTokenSpender\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n // @dev Params for `_getActualFillableTakerTokenAmount()`.\n struct GetActualFillableTakerTokenAmountParams {\n address maker;\n IERC20TokenV06 makerToken;\n uint128 orderMakerAmount;\n uint128 orderTakerAmount;\n LibNativeOrder.OrderInfo orderInfo;\n }\n\n /// @dev Highest bit of a uint256, used to flag cancelled orders.\n uint256 private constant HIGH_BIT = 1 << 255;\n\n constructor(\n address zeroExAddress,\n bytes32 greedyTokensBloomFilter\n )\n internal\n FixinEIP712(zeroExAddress)\n FixinTokenSpender(greedyTokensBloomFilter)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Get the order info for a limit order.\n /// @param order The limit order.\n /// @return orderInfo Info about the order.\n function getLimitOrderInfo(LibNativeOrder.LimitOrder memory order)\n public\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo)\n {\n // Recover maker and compute order hash.\n orderInfo.orderHash = getLimitOrderHash(order);\n uint256 minValidSalt = LibNativeOrdersStorage.getStorage()\n .limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [order.maker]\n [address(order.makerToken)]\n [address(order.takerToken)];\n _populateCommonOrderInfoFields(\n orderInfo,\n order.takerAmount,\n order.expiry,\n order.salt,\n minValidSalt\n );\n }\n\n /// @dev Get the order info for an RFQ order.\n /// @param order The RFQ order.\n /// @return orderInfo Info about the order.\n function getRfqOrderInfo(LibNativeOrder.RfqOrder memory order)\n public\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo)\n {\n // Recover maker and compute order hash.\n orderInfo.orderHash = getRfqOrderHash(order);\n uint256 minValidSalt = LibNativeOrdersStorage.getStorage()\n .rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [order.maker]\n [address(order.makerToken)]\n [address(order.takerToken)];\n _populateCommonOrderInfoFields(\n orderInfo,\n order.takerAmount,\n order.expiry,\n order.salt,\n minValidSalt\n );\n\n // Check for missing txOrigin.\n if (order.txOrigin == address(0)) {\n orderInfo.status = LibNativeOrder.OrderStatus.INVALID;\n }\n }\n\n /// @dev Get the canonical hash of a limit order.\n /// @param order The limit order.\n /// @return orderHash The order hash.\n function getLimitOrderHash(LibNativeOrder.LimitOrder memory order)\n public\n view\n returns (bytes32 orderHash)\n {\n return _getEIP712Hash(\n LibNativeOrder.getLimitOrderStructHash(order)\n );\n }\n\n /// @dev Get the canonical hash of an RFQ order.\n /// @param order The RFQ order.\n /// @return orderHash The order hash.\n function getRfqOrderHash(LibNativeOrder.RfqOrder memory order)\n public\n view\n returns (bytes32 orderHash)\n {\n return _getEIP712Hash(\n LibNativeOrder.getRfqOrderStructHash(order)\n );\n }\n\n /// @dev Get order info, fillable amount, and signature validity for a limit order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getLimitOrderRelevantState(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature calldata signature\n )\n public\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfo = getLimitOrderInfo(order);\n actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams({\n maker: order.maker,\n makerToken: order.makerToken,\n orderMakerAmount: order.makerAmount,\n orderTakerAmount: order.takerAmount,\n orderInfo: orderInfo\n })\n );\n isSignatureValid = order.maker ==\n LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n }\n\n /// @dev Get order info, fillable amount, and signature validity for an RFQ order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getRfqOrderRelevantState(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature\n )\n public\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfo = getRfqOrderInfo(order);\n actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams({\n maker: order.maker,\n makerToken: order.makerToken,\n orderMakerAmount: order.makerAmount,\n orderTakerAmount: order.takerAmount,\n orderInfo: orderInfo\n })\n );\n isSignatureValid = order.maker ==\n LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n }\n\n /// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getLimitOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The limit orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetLimitOrderRelevantStates(\n LibNativeOrder.LimitOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n )\n {\n require(\n orders.length == signatures.length,\n \"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS\"\n );\n orderInfos = new LibNativeOrder.OrderInfo[](orders.length);\n actualFillableTakerTokenAmounts = new uint128[](orders.length);\n isSignatureValids = new bool[](orders.length);\n for (uint256 i = 0; i < orders.length; ++i) {\n try\n this.getLimitOrderRelevantState(orders[i], signatures[i])\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfos[i] = orderInfo;\n actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;\n isSignatureValids[i] = isSignatureValid;\n }\n catch {}\n }\n }\n\n /// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getRfqOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The RFQ orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetRfqOrderRelevantStates(\n LibNativeOrder.RfqOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n )\n {\n require(\n orders.length == signatures.length,\n \"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS\"\n );\n orderInfos = new LibNativeOrder.OrderInfo[](orders.length);\n actualFillableTakerTokenAmounts = new uint128[](orders.length);\n isSignatureValids = new bool[](orders.length);\n for (uint256 i = 0; i < orders.length; ++i) {\n try\n this.getRfqOrderRelevantState(orders[i], signatures[i])\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfos[i] = orderInfo;\n actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;\n isSignatureValids[i] = isSignatureValid;\n }\n catch {}\n }\n }\n\n /// @dev Populate `status` and `takerTokenFilledAmount` fields in\n /// `orderInfo`, which use the same code path for both limit and\n /// RFQ orders.\n /// @param orderInfo `OrderInfo` with `orderHash` and `maker` filled.\n /// @param takerAmount The order's taker token amount..\n /// @param expiry The order's expiry.\n /// @param salt The order's salt.\n /// @param salt The minimum valid salt for the maker and pair combination.\n function _populateCommonOrderInfoFields(\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 takerAmount,\n uint64 expiry,\n uint256 salt,\n uint256 minValidSalt\n )\n private\n view\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n // Get the filled and direct cancel state.\n {\n // The high bit of the raw taker token filled amount will be set\n // if the order was cancelled.\n uint256 rawTakerTokenFilledAmount =\n stor.orderHashToTakerTokenFilledAmount[orderInfo.orderHash];\n orderInfo.takerTokenFilledAmount = uint128(rawTakerTokenFilledAmount);\n if (orderInfo.takerTokenFilledAmount >= takerAmount) {\n orderInfo.status = LibNativeOrder.OrderStatus.FILLED;\n return;\n }\n if (rawTakerTokenFilledAmount & HIGH_BIT != 0) {\n orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;\n return;\n }\n }\n\n // Check for expiration.\n if (expiry <= uint64(block.timestamp)) {\n orderInfo.status = LibNativeOrder.OrderStatus.EXPIRED;\n return;\n }\n\n // Check if the order was cancelled by salt.\n if (minValidSalt > salt) {\n orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;\n return;\n }\n orderInfo.status = LibNativeOrder.OrderStatus.FILLABLE;\n }\n\n /// @dev Calculate the actual fillable taker token amount of an order\n /// based on maker allowance and balances.\n function _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams memory params\n )\n private\n view\n returns (uint128 actualFillableTakerTokenAmount)\n {\n if (params.orderMakerAmount == 0 || params.orderTakerAmount == 0) {\n // Empty order.\n return 0;\n }\n if (params.orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n // Not fillable.\n return 0;\n }\n\n // Get the fillable maker amount based on the order quantities and\n // previously filled amount\n uint256 fillableMakerTokenAmount = LibMathV06.getPartialAmountFloor(\n uint256(\n params.orderTakerAmount\n - params.orderInfo.takerTokenFilledAmount\n ),\n uint256(params.orderTakerAmount),\n uint256(params.orderMakerAmount)\n );\n // Clamp it to the amount of maker tokens we can spend on behalf of the\n // maker.\n fillableMakerTokenAmount = LibSafeMathV06.min256(\n fillableMakerTokenAmount,\n _getSpendableERC20BalanceOf(params.makerToken, params.maker)\n );\n // Convert to taker token amount.\n return LibMathV06.getPartialAmountCeil(\n fillableMakerTokenAmount,\n uint256(params.orderMakerAmount),\n uint256(params.orderTakerAmount)\n ).safeDowncastToUint128();\n }\n}\n"
},
"../features/native_orders/NativeOrdersProtocolFees.sol": {
"id": 38,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../../fixins/FixinProtocolFees.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../vendor/v3/IStaking.sol\";\n\n\n/// @dev Mixin for protocol fee utility functions.\nabstract contract NativeOrdersProtocolFees is\n FixinProtocolFees\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier\n )\n internal\n FixinProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Transfers protocol fees from the `FeeCollector` pools into\n /// the staking contract.\n /// @param poolIds Staking pool IDs\n function transferProtocolFeesForPools(bytes32[] calldata poolIds)\n external\n {\n for (uint256 i = 0; i < poolIds.length; ++i) {\n _transferFeesForPool(poolIds[i]);\n }\n }\n\n /// @dev Get the protocol fee multiplier. This should be multiplied by the\n /// gas price to arrive at the required protocol fee to fill a native order.\n /// @return multiplier The protocol fee multiplier.\n function getProtocolFeeMultiplier()\n external\n view\n returns (uint32 multiplier)\n {\n return PROTOCOL_FEE_MULTIPLIER;\n }\n}\n"
},
"../fixins/FixinProtocolFees.sol": {
"id": 42,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"../external/FeeCollector.sol\";\nimport \"../external/FeeCollectorController.sol\";\nimport \"../external/LibFeeCollector.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n\n/// @dev Helpers for collecting protocol fees.\nabstract contract FixinProtocolFees {\n\n /// @dev The protocol fee multiplier.\n uint32 public immutable PROTOCOL_FEE_MULTIPLIER;\n /// @dev The `FeeCollectorController` contract.\n FeeCollectorController private immutable FEE_COLLECTOR_CONTROLLER;\n /// @dev Hash of the fee collector init code.\n bytes32 private immutable FEE_COLLECTOR_INIT_CODE_HASH;\n /// @dev The WETH token contract.\n IEtherTokenV06 private immutable WETH;\n /// @dev The staking contract.\n IStaking private immutable STAKING;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier\n )\n internal\n {\n FEE_COLLECTOR_CONTROLLER = feeCollectorController;\n FEE_COLLECTOR_INIT_CODE_HASH =\n feeCollectorController.FEE_COLLECTOR_INIT_CODE_HASH();\n WETH = weth;\n STAKING = staking;\n PROTOCOL_FEE_MULTIPLIER = protocolFeeMultiplier;\n }\n\n /// @dev Collect the specified protocol fee in ETH.\n /// The fee is stored in a per-pool fee collector contract.\n /// @param poolId The pool ID for which a fee is being collected.\n /// @return ethProtocolFeePaid How much protocol fee was collected in ETH.\n function _collectProtocolFee(bytes32 poolId)\n internal\n returns (uint256 ethProtocolFeePaid)\n {\n uint256 protocolFeePaid = _getSingleProtocolFee();\n if (protocolFeePaid == 0) {\n // Nothing to do.\n return 0;\n }\n FeeCollector feeCollector = _getFeeCollector(poolId);\n (bool success,) = address(feeCollector).call{value: protocolFeePaid}(\"\");\n require(success, \"FixinProtocolFees/ETHER_TRANSFER_FALIED\");\n return protocolFeePaid;\n }\n\n /// @dev Transfer fees for a given pool to the staking contract.\n /// @param poolId Identifies the pool whose fees are being paid.\n function _transferFeesForPool(bytes32 poolId)\n internal\n {\n // This will create a FeeCollector contract (if necessary) and wrap\n // fees for the pool ID.\n FeeCollector feeCollector =\n FEE_COLLECTOR_CONTROLLER.prepareFeeCollectorToPayFees(poolId);\n // All fees in the fee collector should be in WETH now.\n uint256 bal = WETH.balanceOf(address(feeCollector));\n if (bal > 1) {\n // Leave 1 wei behind to avoid high SSTORE cost of zero-->non-zero.\n STAKING.payProtocolFee(\n address(feeCollector),\n address(feeCollector),\n bal - 1);\n }\n }\n\n /// @dev Compute the CREATE2 address for a fee collector.\n /// @param poolId The fee collector's pool ID.\n function _getFeeCollector(bytes32 poolId)\n internal\n view\n returns (FeeCollector)\n {\n return FeeCollector(LibFeeCollector.getFeeCollectorAddress(\n address(FEE_COLLECTOR_CONTROLLER),\n FEE_COLLECTOR_INIT_CODE_HASH,\n poolId\n ));\n }\n\n /// @dev Get the cost of a single protocol fee.\n /// @return protocolFeeAmount The protocol fee amount, in ETH/WETH.\n function _getSingleProtocolFee()\n internal\n view\n returns (uint256 protocolFeeAmount)\n {\n return uint256(PROTOCOL_FEE_MULTIPLIER) * tx.gasprice;\n }\n}\n"
},
"../external/FeeCollectorController.sol": {
"id": 13,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"../vendor/v3/IStaking.sol\";\nimport \"./FeeCollector.sol\";\nimport \"./LibFeeCollector.sol\";\n\n\n/// @dev A contract that manages `FeeCollector` contracts.\ncontract FeeCollectorController {\n\n /// @dev Hash of the fee collector init code.\n bytes32 public immutable FEE_COLLECTOR_INIT_CODE_HASH;\n /// @dev The WETH contract.\n IEtherTokenV06 private immutable WETH;\n /// @dev The staking contract.\n IStaking private immutable STAKING;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking\n )\n public\n {\n FEE_COLLECTOR_INIT_CODE_HASH = keccak256(type(FeeCollector).creationCode);\n WETH = weth;\n STAKING = staking;\n }\n\n /// @dev Deploy (if needed) a `FeeCollector` contract for `poolId`\n /// and wrap its ETH into WETH. Anyone may call this.\n /// @param poolId The pool ID associated with the staking pool.\n /// @return feeCollector The `FeeCollector` contract instance.\n function prepareFeeCollectorToPayFees(bytes32 poolId)\n external\n returns (FeeCollector feeCollector)\n {\n feeCollector = getFeeCollector(poolId);\n uint256 codeSize;\n assembly {\n codeSize := extcodesize(feeCollector)\n }\n\n if (codeSize == 0) {\n // Create and initialize the contract if necessary.\n new FeeCollector{salt: bytes32(poolId)}();\n feeCollector.initialize(WETH, STAKING, poolId);\n }\n\n if (address(feeCollector).balance > 1) {\n feeCollector.convertToWeth(WETH);\n }\n\n return feeCollector;\n }\n\n /// @dev Get the `FeeCollector` contract for a given pool ID. The contract\n /// will not actually exist until `prepareFeeCollectorToPayFees()`\n /// has been called once.\n /// @param poolId The pool ID associated with the staking pool.\n /// @return feeCollector The `FeeCollector` contract instance.\n function getFeeCollector(bytes32 poolId)\n public\n view\n returns (FeeCollector feeCollector)\n {\n return FeeCollector(LibFeeCollector.getFeeCollectorAddress(\n address(this),\n FEE_COLLECTOR_INIT_CODE_HASH,\n poolId\n ));\n }\n}\n"
},
"../external/LibFeeCollector.sol": {
"id": 17,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Helpers for computing `FeeCollector` contract addresses.\nlibrary LibFeeCollector {\n\n /// @dev Compute the CREATE2 address for a fee collector.\n /// @param controller The address of the `FeeCollectorController` contract.\n /// @param initCodeHash The init code hash of the `FeeCollector` contract.\n /// @param poolId The fee collector's pool ID.\n function getFeeCollectorAddress(address controller, bytes32 initCodeHash, bytes32 poolId)\n internal\n pure\n returns (address payable feeCollectorAddress)\n {\n // Compute the CREATE2 address for the fee collector.\n return address(uint256(keccak256(abi.encodePacked(\n byte(0xff),\n controller,\n poolId, // pool ID is salt\n initCodeHash\n ))));\n }\n}\n"
},
"../external/AllowanceTarget.sol": {
"id": 11,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"./IAllowanceTarget.sol\";\n\n\n/// @dev The allowance target for the TokenSpender feature.\ncontract AllowanceTarget is\n IAllowanceTarget,\n AuthorizableV06\n{\n // solhint-disable no-unused-vars,indent,no-empty-blocks\n using LibRichErrorsV06 for bytes;\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData\n )\n external\n override\n onlyAuthorized\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.call(callData);\n if (!success) {\n resultData.rrevert();\n }\n }\n}\n"
},
"./InitialMigration.sol": {
"id": 46,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../ZeroEx.sol\";\nimport \"../features/interfaces/IBootstrapFeature.sol\";\nimport \"../features/SimpleFunctionRegistryFeature.sol\";\nimport \"../features/OwnableFeature.sol\";\nimport \"./LibBootstrap.sol\";\n\n\n/// @dev A contract for deploying and configuring a minimal ZeroEx contract.\ncontract InitialMigration {\n\n /// @dev Features to bootstrap into the the proxy contract.\n struct BootstrapFeatures {\n SimpleFunctionRegistryFeature registry;\n OwnableFeature ownable;\n }\n\n /// @dev The allowed caller of `initializeZeroEx()`. In production, this would be\n /// the governor.\n address public immutable initializeCaller;\n /// @dev The real address of this contract.\n address private immutable _implementation;\n\n /// @dev Instantiate this contract and set the allowed caller of `initializeZeroEx()`\n /// to `initializeCaller_`.\n /// @param initializeCaller_ The allowed caller of `initializeZeroEx()`.\n constructor(address initializeCaller_) public {\n initializeCaller = initializeCaller_;\n _implementation = address(this);\n }\n\n /// @dev Initialize the `ZeroEx` contract with the minimum feature set,\n /// transfers ownership to `owner`, then self-destructs.\n /// Only callable by `initializeCaller` set in the contstructor.\n /// @param owner The owner of the contract.\n /// @param zeroEx The instance of the ZeroEx contract. ZeroEx should\n /// been constructed with this contract as the bootstrapper.\n /// @param features Features to bootstrap into the proxy.\n /// @return _zeroEx The configured ZeroEx contract. Same as the `zeroEx` parameter.\n function initializeZeroEx(\n address payable owner,\n ZeroEx zeroEx,\n BootstrapFeatures memory features\n )\n public\n virtual\n returns (ZeroEx _zeroEx)\n {\n // Must be called by the allowed initializeCaller.\n require(msg.sender == initializeCaller, \"InitialMigration/INVALID_SENDER\");\n\n // Bootstrap the initial feature set.\n IBootstrapFeature(address(zeroEx)).bootstrap(\n address(this),\n abi.encodeWithSelector(this.bootstrap.selector, owner, features)\n );\n\n // Self-destruct. This contract should not hold any funds but we send\n // them to the owner just in case.\n this.die(owner);\n\n return zeroEx;\n }\n\n /// @dev Sets up the initial state of the `ZeroEx` contract.\n /// The `ZeroEx` contract will delegatecall into this function.\n /// @param owner The new owner of the ZeroEx contract.\n /// @param features Features to bootstrap into the proxy.\n /// @return success Magic bytes if successful.\n function bootstrap(address owner, BootstrapFeatures memory features)\n public\n virtual\n returns (bytes4 success)\n {\n // Deploy and migrate the initial features.\n // Order matters here.\n\n // Initialize Registry.\n LibBootstrap.delegatecallBootstrapFunction(\n address(features.registry),\n abi.encodeWithSelector(\n SimpleFunctionRegistryFeature.bootstrap.selector\n )\n );\n\n // Initialize OwnableFeature.\n LibBootstrap.delegatecallBootstrapFunction(\n address(features.ownable),\n abi.encodeWithSelector(\n OwnableFeature.bootstrap.selector\n )\n );\n\n // De-register `SimpleFunctionRegistryFeature._extendSelf`.\n SimpleFunctionRegistryFeature(address(this)).rollback(\n SimpleFunctionRegistryFeature._extendSelf.selector,\n address(0)\n );\n\n // Transfer ownership to the real owner.\n OwnableFeature(address(this)).transferOwnership(owner);\n\n success = LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Self-destructs this contract. Only callable by this contract.\n /// @param ethRecipient Who to transfer outstanding ETH to.\n function die(address payable ethRecipient) public virtual {\n require(msg.sender == _implementation, \"InitialMigration/INVALID_SENDER\");\n selfdestruct(ethRecipient);\n }\n}\n"
},
"../features/SimpleFunctionRegistryFeature.sol": {
"id": 22,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../storage/LibProxyStorage.sol\";\nimport \"../storage/LibSimpleFunctionRegistryStorage.sol\";\nimport \"../errors/LibSimpleFunctionRegistryRichErrors.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ISimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Basic registry management features.\ncontract SimpleFunctionRegistryFeature is\n IFeature,\n ISimpleFunctionRegistryFeature,\n FixinCommon\n{\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"SimpleFunctionRegistry\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initializes this feature, registering its own functions.\n /// @return success Magic bytes if successful.\n function bootstrap()\n external\n returns (bytes4 success)\n {\n // Register the registration functions (inception vibes).\n _extend(this.extend.selector, _implementation);\n _extend(this._extendSelf.selector, _implementation);\n // Register the rollback function.\n _extend(this.rollback.selector, _implementation);\n // Register getters.\n _extend(this.getRollbackLength.selector, _implementation);\n _extend(this.getRollbackEntryAtIndex.selector, _implementation);\n return LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Roll back to a prior implementation of a function.\n /// Only directly callable by an authority.\n /// @param selector The function selector.\n /// @param targetImpl The address of an older implementation of the function.\n function rollback(bytes4 selector, address targetImpl)\n external\n override\n onlyOwner\n {\n (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n ) = _getStorages();\n\n address currentImpl = proxyStor.impls[selector];\n if (currentImpl == targetImpl) {\n // Do nothing if already at targetImpl.\n return;\n }\n // Walk history backwards until we find the target implementation.\n address[] storage history = stor.implHistory[selector];\n uint256 i = history.length;\n for (; i > 0; --i) {\n address impl = history[i - 1];\n history.pop();\n if (impl == targetImpl) {\n break;\n }\n }\n if (i == 0) {\n LibSimpleFunctionRegistryRichErrors.NotInRollbackHistoryError(\n selector,\n targetImpl\n ).rrevert();\n }\n proxyStor.impls[selector] = targetImpl;\n emit ProxyFunctionUpdated(selector, currentImpl, targetImpl);\n }\n\n /// @dev Register or replace a function.\n /// Only directly callable by an authority.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function extend(bytes4 selector, address impl)\n external\n override\n onlyOwner\n {\n _extend(selector, impl);\n }\n\n /// @dev Register or replace a function.\n /// Only callable from within.\n /// This function is only used during the bootstrap process and\n /// should be deregistered by the deployer after bootstrapping is\n /// complete.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function _extendSelf(bytes4 selector, address impl)\n external\n onlySelf\n {\n _extend(selector, impl);\n }\n\n /// @dev Retrieve the length of the rollback history for a function.\n /// @param selector The function selector.\n /// @return rollbackLength The number of items in the rollback history for\n /// the function.\n function getRollbackLength(bytes4 selector)\n external\n override\n view\n returns (uint256 rollbackLength)\n {\n return LibSimpleFunctionRegistryStorage.getStorage().implHistory[selector].length;\n }\n\n /// @dev Retrieve an entry in the rollback history for a function.\n /// @param selector The function selector.\n /// @param idx The index in the rollback history.\n /// @return impl An implementation address for the function at\n /// index `idx`.\n function getRollbackEntryAtIndex(bytes4 selector, uint256 idx)\n external\n override\n view\n returns (address impl)\n {\n return LibSimpleFunctionRegistryStorage.getStorage().implHistory[selector][idx];\n }\n\n /// @dev Register or replace a function.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function _extend(bytes4 selector, address impl)\n private\n {\n (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n ) = _getStorages();\n\n address oldImpl = proxyStor.impls[selector];\n address[] storage history = stor.implHistory[selector];\n history.push(oldImpl);\n proxyStor.impls[selector] = impl;\n emit ProxyFunctionUpdated(selector, oldImpl, impl);\n }\n\n /// @dev Get the storage buckets for this feature and the proxy.\n /// @return stor Storage bucket for this feature.\n /// @return proxyStor age bucket for the proxy.\n function _getStorages()\n private\n pure\n returns (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n )\n {\n return (\n LibSimpleFunctionRegistryStorage.getStorage(),\n LibProxyStorage.getStorage()\n );\n }\n}\n"
},
"../storage/LibSimpleFunctionRegistryStorage.sol": {
"id": 54,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `SimpleFunctionRegistry` feature.\nlibrary LibSimpleFunctionRegistryStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Mapping of function selector -> implementation history.\n mapping(bytes4 => address[]) implHistory;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.SimpleFunctionRegistry\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"../errors/LibSimpleFunctionRegistryRichErrors.sol": {
"id": 7,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSimpleFunctionRegistryRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function NotInRollbackHistoryError(bytes4 selector, address targetImpl)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NotInRollbackHistoryError(bytes4,address)\")),\n selector,\n targetImpl\n );\n }\n}\n"
},
"../features/OwnableFeature.sol": {
"id": 21,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\nimport \"../storage/LibOwnableStorage.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/IOwnableFeature.sol\";\nimport \"./SimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Owner management features.\ncontract OwnableFeature is\n IFeature,\n IOwnableFeature,\n FixinCommon\n{\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"Ownable\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initializes this feature. The intial owner will be set to this (ZeroEx)\n /// to allow the bootstrappers to call `extend()`. Ownership should be\n /// transferred to the real owner by the bootstrapper after\n /// bootstrapping is complete.\n /// @return success Magic bytes if successful.\n function bootstrap() external returns (bytes4 success) {\n // Set the owner to ourselves to allow bootstrappers to call `extend()`.\n LibOwnableStorage.getStorage().owner = address(this);\n\n // Register feature functions.\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.transferOwnership.selector, _implementation);\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.owner.selector, _implementation);\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.migrate.selector, _implementation);\n return LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Change the owner of this contract.\n /// Only directly callable by the owner.\n /// @param newOwner New owner address.\n function transferOwnership(address newOwner)\n external\n override\n onlyOwner\n {\n LibOwnableStorage.Storage storage proxyStor = LibOwnableStorage.getStorage();\n\n if (newOwner == address(0)) {\n LibOwnableRichErrors.TransferOwnerToZeroError().rrevert();\n } else {\n proxyStor.owner = newOwner;\n emit OwnershipTransferred(msg.sender, newOwner);\n }\n }\n\n /// @dev Execute a migration function in the context of the ZeroEx contract.\n /// The result of the function being called should be the magic bytes\n /// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.\n /// Temporarily sets the owner to ourselves so we can perform admin functions.\n /// Before returning, the owner will be set to `newOwner`.\n /// @param target The migrator contract address.\n /// @param data The call data.\n /// @param newOwner The address of the new owner.\n function migrate(address target, bytes calldata data, address newOwner)\n external\n override\n onlyOwner\n {\n if (newOwner == address(0)) {\n LibOwnableRichErrors.TransferOwnerToZeroError().rrevert();\n }\n\n LibOwnableStorage.Storage storage stor = LibOwnableStorage.getStorage();\n // The owner will be temporarily set to `address(this)` inside the call.\n stor.owner = address(this);\n\n // Perform the migration.\n LibMigrate.delegatecallMigrateFunction(target, data);\n\n // Update the owner.\n stor.owner = newOwner;\n\n emit Migrated(msg.sender, target, newOwner);\n }\n\n /// @dev Get the owner of this contract.\n /// @return owner_ The owner of this contract.\n function owner() external override view returns (address owner_) {\n return LibOwnableStorage.getStorage().owner;\n }\n}\n"
},
"../storage/LibOwnableStorage.sol": {
"id": 51,
"content": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `Ownable` feature.\nlibrary LibOwnableStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The owner of this contract.\n address owner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.Ownable\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
}
},
"sourceCodes": {
"./FullMigration.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../ZeroEx.sol\";\nimport \"../features/interfaces/IOwnableFeature.sol\";\nimport \"../features/TokenSpenderFeature.sol\";\nimport \"../features/TransformERC20Feature.sol\";\nimport \"../features/MetaTransactionsFeature.sol\";\nimport \"../features/NativeOrdersFeature.sol\";\nimport \"../external/AllowanceTarget.sol\";\nimport \"./InitialMigration.sol\";\n\n\n/// @dev A contract for deploying and configuring the full ZeroEx contract.\ncontract FullMigration {\n\n // solhint-disable no-empty-blocks,indent\n\n /// @dev Features to add the the proxy contract.\n struct Features {\n SimpleFunctionRegistryFeature registry;\n OwnableFeature ownable;\n TokenSpenderFeature tokenSpender;\n TransformERC20Feature transformERC20;\n MetaTransactionsFeature metaTransactions;\n NativeOrdersFeature nativeOrders;\n }\n\n /// @dev Parameters needed to initialize features.\n struct MigrateOpts {\n address transformerDeployer;\n }\n\n /// @dev The allowed caller of `initializeZeroEx()`.\n address public immutable initializeCaller;\n /// @dev The initial migration contract.\n InitialMigration private _initialMigration;\n\n /// @dev Instantiate this contract and set the allowed caller of `initializeZeroEx()`\n /// to `initializeCaller`.\n /// @param initializeCaller_ The allowed caller of `initializeZeroEx()`.\n constructor(address payable initializeCaller_)\n public\n {\n initializeCaller = initializeCaller_;\n // Create an initial migration contract with this contract set to the\n // allowed `initializeCaller`.\n _initialMigration = new InitialMigration(address(this));\n }\n\n /// @dev Retrieve the bootstrapper address to use when constructing `ZeroEx`.\n /// @return bootstrapper The bootstrapper address.\n function getBootstrapper()\n external\n view\n returns (address bootstrapper)\n {\n return address(_initialMigration);\n }\n\n /// @dev Initialize the `ZeroEx` contract with the full feature set,\n /// transfer ownership to `owner`, then self-destruct.\n /// @param owner The owner of the contract.\n /// @param zeroEx The instance of the ZeroEx contract. ZeroEx should\n /// been constructed with this contract as the bootstrapper.\n /// @param features Features to add to the proxy.\n /// @return _zeroEx The configured ZeroEx contract. Same as the `zeroEx` parameter.\n /// @param migrateOpts Parameters needed to initialize features.\n function migrateZeroEx(\n address payable owner,\n ZeroEx zeroEx,\n Features memory features,\n MigrateOpts memory migrateOpts\n )\n public\n returns (ZeroEx _zeroEx)\n {\n require(msg.sender == initializeCaller, \"FullMigration/INVALID_SENDER\");\n\n // Perform the initial migration with the owner set to this contract.\n _initialMigration.initializeZeroEx(\n address(uint160(address(this))),\n zeroEx,\n InitialMigration.BootstrapFeatures({\n registry: features.registry,\n ownable: features.ownable\n })\n );\n\n // Add features.\n _addFeatures(zeroEx, owner, features, migrateOpts);\n\n // Transfer ownership to the real owner.\n IOwnableFeature(address(zeroEx)).transferOwnership(owner);\n\n // Self-destruct.\n this.die(owner);\n\n return zeroEx;\n }\n\n /// @dev Destroy this contract. Only callable from ourselves (from `initializeZeroEx()`).\n /// @param ethRecipient Receiver of any ETH in this contract.\n function die(address payable ethRecipient)\n external\n virtual\n {\n require(msg.sender == address(this), \"FullMigration/INVALID_SENDER\");\n // This contract should not hold any funds but we send\n // them to the ethRecipient just in case.\n selfdestruct(ethRecipient);\n }\n\n /// @dev Deploy and register features to the ZeroEx contract.\n /// @param zeroEx The bootstrapped ZeroEx contract.\n /// @param owner The ultimate owner of the ZeroEx contract.\n /// @param features Features to add to the proxy.\n /// @param migrateOpts Parameters needed to initialize features.\n function _addFeatures(\n ZeroEx zeroEx,\n address owner,\n Features memory features,\n MigrateOpts memory migrateOpts\n )\n private\n {\n IOwnableFeature ownable = IOwnableFeature(address(zeroEx));\n // TokenSpenderFeature\n {\n // Create the allowance target.\n AllowanceTarget allowanceTarget = new AllowanceTarget();\n // Let the ZeroEx contract use the allowance target.\n allowanceTarget.addAuthorizedAddress(address(zeroEx));\n // Transfer ownership of the allowance target to the (real) owner.\n allowanceTarget.transferOwnership(owner);\n // Register the feature.\n ownable.migrate(\n address(features.tokenSpender),\n abi.encodeWithSelector(\n TokenSpenderFeature.migrate.selector,\n allowanceTarget\n ),\n address(this)\n );\n }\n // TransformERC20Feature\n {\n // Register the feature.\n ownable.migrate(\n address(features.transformERC20),\n abi.encodeWithSelector(\n TransformERC20Feature.migrate.selector,\n migrateOpts.transformerDeployer\n ),\n address(this)\n );\n }\n // MetaTransactionsFeature\n {\n // Register the feature.\n ownable.migrate(\n address(features.metaTransactions),\n abi.encodeWithSelector(\n MetaTransactionsFeature.migrate.selector\n ),\n address(this)\n );\n }\n // NativeOrdersFeature\n {\n // Register the feature.\n ownable.migrate(\n address(features.nativeOrders),\n abi.encodeWithSelector(\n NativeOrdersFeature.migrate.selector\n ),\n address(this)\n );\n }\n }\n}\n",
"../ZeroEx.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"./migrations/LibBootstrap.sol\";\nimport \"./features/BootstrapFeature.sol\";\nimport \"./storage/LibProxyStorage.sol\";\nimport \"./errors/LibProxyRichErrors.sol\";\n\n\n/// @dev An extensible proxy contract that serves as a universal entry point for\n/// interacting with the 0x protocol.\ncontract ZeroEx {\n // solhint-disable separate-by-one-line-in-contract,indent,var-name-mixedcase\n using LibBytesV06 for bytes;\n\n /// @dev Construct this contract and register the `BootstrapFeature` feature.\n /// After constructing this contract, `bootstrap()` should be called\n /// by `bootstrap()` to seed the initial feature set.\n /// @param bootstrapper Who can call `bootstrap()`.\n constructor(address bootstrapper) public {\n // Temporarily create and register the bootstrap feature.\n // It will deregister itself after `bootstrap()` has been called.\n BootstrapFeature bootstrap = new BootstrapFeature(bootstrapper);\n LibProxyStorage.getStorage().impls[bootstrap.bootstrap.selector] =\n address(bootstrap);\n }\n\n // solhint-disable state-visibility\n\n /// @dev Forwards calls to the appropriate implementation contract.\n fallback() external payable {\n bytes4 selector = msg.data.readBytes4(0);\n address impl = getFunctionImplementation(selector);\n if (impl == address(0)) {\n _revertWithData(LibProxyRichErrors.NotImplementedError(selector));\n }\n\n (bool success, bytes memory resultData) = impl.delegatecall(msg.data);\n if (!success) {\n _revertWithData(resultData);\n }\n _returnWithData(resultData);\n }\n\n /// @dev Fallback for just receiving ether.\n receive() external payable {}\n\n // solhint-enable state-visibility\n\n /// @dev Get the implementation contract of a registered function.\n /// @param selector The function selector.\n /// @return impl The implementation contract address.\n function getFunctionImplementation(bytes4 selector)\n public\n view\n returns (address impl)\n {\n return LibProxyStorage.getStorage().impls[selector];\n }\n\n /// @dev Revert with arbitrary bytes.\n /// @param data Revert data.\n function _revertWithData(bytes memory data) private pure {\n assembly { revert(add(data, 32), mload(data)) }\n }\n\n /// @dev Return with arbitrary bytes.\n /// @param data Return data.\n function _returnWithData(bytes memory data) private pure {\n assembly { return(add(data, 32), mload(data)) }\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./errors/LibBytesRichErrorsV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\n\n\nlibrary LibBytesV06 {\n\n using LibBytesV06 for bytes;\n\n /// @dev Gets the memory address for a byte array.\n /// @param input Byte array to lookup.\n /// @return memoryAddress Memory address of byte array. This\n /// points to the header of the byte array which contains\n /// the length.\n function rawAddress(bytes memory input)\n internal\n pure\n returns (uint256 memoryAddress)\n {\n assembly {\n memoryAddress := input\n }\n return memoryAddress;\n }\n\n /// @dev Gets the memory address for the contents of a byte array.\n /// @param input Byte array to lookup.\n /// @return memoryAddress Memory address of the contents of the byte array.\n function contentAddress(bytes memory input)\n internal\n pure\n returns (uint256 memoryAddress)\n {\n assembly {\n memoryAddress := add(input, 32)\n }\n return memoryAddress;\n }\n\n /// @dev Copies `length` bytes from memory location `source` to `dest`.\n /// @param dest memory address to copy bytes to.\n /// @param source memory address to copy bytes from.\n /// @param length number of bytes to copy.\n function memCopy(\n uint256 dest,\n uint256 source,\n uint256 length\n )\n internal\n pure\n {\n if (length < 32) {\n // Handle a partial word by reading destination and masking\n // off the bits we are interested in.\n // This correctly handles overlap, zero lengths and source == dest\n assembly {\n let mask := sub(exp(256, sub(32, length)), 1)\n let s := and(mload(source), not(mask))\n let d := and(mload(dest), mask)\n mstore(dest, or(s, d))\n }\n } else {\n // Skip the O(length) loop when source == dest.\n if (source == dest) {\n return;\n }\n\n // For large copies we copy whole words at a time. The final\n // word is aligned to the end of the range (instead of after the\n // previous) to handle partial words. So a copy will look like this:\n //\n // ####\n // ####\n // ####\n // ####\n //\n // We handle overlap in the source and destination range by\n // changing the copying direction. This prevents us from\n // overwriting parts of source that we still need to copy.\n //\n // This correctly handles source == dest\n //\n if (source > dest) {\n assembly {\n // We subtract 32 from `sEnd` and `dEnd` because it\n // is easier to compare with in the loop, and these\n // are also the addresses we need for copying the\n // last bytes.\n length := sub(length, 32)\n let sEnd := add(source, length)\n let dEnd := add(dest, length)\n\n // Remember the last 32 bytes of source\n // This needs to be done here and not after the loop\n // because we may have overwritten the last bytes in\n // source already due to overlap.\n let last := mload(sEnd)\n\n // Copy whole words front to back\n // Note: the first check is always true,\n // this could have been a do-while loop.\n // solhint-disable-next-line no-empty-blocks\n for {} lt(source, sEnd) {} {\n mstore(dest, mload(source))\n source := add(source, 32)\n dest := add(dest, 32)\n }\n\n // Write the last 32 bytes\n mstore(dEnd, last)\n }\n } else {\n assembly {\n // We subtract 32 from `sEnd` and `dEnd` because those\n // are the starting points when copying a word at the end.\n length := sub(length, 32)\n let sEnd := add(source, length)\n let dEnd := add(dest, length)\n\n // Remember the first 32 bytes of source\n // This needs to be done here and not after the loop\n // because we may have overwritten the first bytes in\n // source already due to overlap.\n let first := mload(source)\n\n // Copy whole words back to front\n // We use a signed comparisson here to allow dEnd to become\n // negative (happens when source and dest < 32). Valid\n // addresses in local memory will never be larger than\n // 2**255, so they can be safely re-interpreted as signed.\n // Note: the first check is always true,\n // this could have been a do-while loop.\n // solhint-disable-next-line no-empty-blocks\n for {} slt(dest, dEnd) {} {\n mstore(dEnd, mload(sEnd))\n sEnd := sub(sEnd, 32)\n dEnd := sub(dEnd, 32)\n }\n\n // Write the first 32 bytes\n mstore(dest, first)\n }\n }\n }\n }\n\n /// @dev Returns a slices from a byte array.\n /// @param b The byte array to take a slice from.\n /// @param from The starting index for the slice (inclusive).\n /// @param to The final index for the slice (exclusive).\n /// @return result The slice containing bytes at indices [from, to)\n function slice(\n bytes memory b,\n uint256 from,\n uint256 to\n )\n internal\n pure\n returns (bytes memory result)\n {\n // Ensure that the from and to positions are valid positions for a slice within\n // the byte array that is being used.\n if (from > to) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,\n from,\n to\n ));\n }\n if (to > b.length) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,\n to,\n b.length\n ));\n }\n\n // Create a new bytes structure and copy contents\n result = new bytes(to - from);\n memCopy(\n result.contentAddress(),\n b.contentAddress() + from,\n result.length\n );\n return result;\n }\n\n /// @dev Returns a slice from a byte array without preserving the input.\n /// When `from == 0`, the original array will match the slice.\n /// In other cases its state will be corrupted.\n /// @param b The byte array to take a slice from. Will be destroyed in the process.\n /// @param from The starting index for the slice (inclusive).\n /// @param to The final index for the slice (exclusive).\n /// @return result The slice containing bytes at indices [from, to)\n function sliceDestructive(\n bytes memory b,\n uint256 from,\n uint256 to\n )\n internal\n pure\n returns (bytes memory result)\n {\n // Ensure that the from and to positions are valid positions for a slice within\n // the byte array that is being used.\n if (from > to) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,\n from,\n to\n ));\n }\n if (to > b.length) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,\n to,\n b.length\n ));\n }\n\n // Create a new bytes structure around [from, to) in-place.\n assembly {\n result := add(b, from)\n mstore(result, sub(to, from))\n }\n return result;\n }\n\n /// @dev Pops the last byte off of a byte array by modifying its length.\n /// @param b Byte array that will be modified.\n /// @return result The byte that was popped off.\n function popLastByte(bytes memory b)\n internal\n pure\n returns (bytes1 result)\n {\n if (b.length == 0) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired,\n b.length,\n 0\n ));\n }\n\n // Store last byte.\n result = b[b.length - 1];\n\n assembly {\n // Decrement length of byte array.\n let newLen := sub(mload(b), 1)\n mstore(b, newLen)\n }\n return result;\n }\n\n /// @dev Tests equality of two byte arrays.\n /// @param lhs First byte array to compare.\n /// @param rhs Second byte array to compare.\n /// @return equal True if arrays are the same. False otherwise.\n function equals(\n bytes memory lhs,\n bytes memory rhs\n )\n internal\n pure\n returns (bool equal)\n {\n // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare.\n // We early exit on unequal lengths, but keccak would also correctly\n // handle this.\n return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs);\n }\n\n /// @dev Reads an address from a position in a byte array.\n /// @param b Byte array containing an address.\n /// @param index Index in byte array of address.\n /// @return result address from byte array.\n function readAddress(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (address result)\n {\n if (b.length < index + 20) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,\n b.length,\n index + 20 // 20 is length of address\n ));\n }\n\n // Add offset to index:\n // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)\n // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)\n index += 20;\n\n // Read address from array memory\n assembly {\n // 1. Add index to address of bytes array\n // 2. Load 32-byte word from memory\n // 3. Apply 20-byte mask to obtain address\n result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff)\n }\n return result;\n }\n\n /// @dev Writes an address into a specific position in a byte array.\n /// @param b Byte array to insert address into.\n /// @param index Index in byte array of address.\n /// @param input Address to put into byte array.\n function writeAddress(\n bytes memory b,\n uint256 index,\n address input\n )\n internal\n pure\n {\n if (b.length < index + 20) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,\n b.length,\n index + 20 // 20 is length of address\n ));\n }\n\n // Add offset to index:\n // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)\n // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)\n index += 20;\n\n // Store address into array memory\n assembly {\n // The address occupies 20 bytes and mstore stores 32 bytes.\n // First fetch the 32-byte word where we'll be storing the address, then\n // apply a mask so we have only the bytes in the word that the address will not occupy.\n // Then combine these bytes with the address and store the 32 bytes back to memory with mstore.\n\n // 1. Add index to address of bytes array\n // 2. Load 32-byte word from memory\n // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address\n let neighbors := and(\n mload(add(b, index)),\n 0xffffffffffffffffffffffff0000000000000000000000000000000000000000\n )\n\n // Make sure input address is clean.\n // (Solidity does not guarantee this)\n input := and(input, 0xffffffffffffffffffffffffffffffffffffffff)\n\n // Store the neighbors and address into memory\n mstore(add(b, index), xor(input, neighbors))\n }\n }\n\n /// @dev Reads a bytes32 value from a position in a byte array.\n /// @param b Byte array containing a bytes32 value.\n /// @param index Index in byte array of bytes32 value.\n /// @return result bytes32 value from byte array.\n function readBytes32(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (bytes32 result)\n {\n if (b.length < index + 32) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,\n b.length,\n index + 32\n ));\n }\n\n // Arrays are prefixed by a 256 bit length parameter\n index += 32;\n\n // Read the bytes32 from array memory\n assembly {\n result := mload(add(b, index))\n }\n return result;\n }\n\n /// @dev Writes a bytes32 into a specific position in a byte array.\n /// @param b Byte array to insert <input> into.\n /// @param index Index in byte array of <input>.\n /// @param input bytes32 to put into byte array.\n function writeBytes32(\n bytes memory b,\n uint256 index,\n bytes32 input\n )\n internal\n pure\n {\n if (b.length < index + 32) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,\n b.length,\n index + 32\n ));\n }\n\n // Arrays are prefixed by a 256 bit length parameter\n index += 32;\n\n // Read the bytes32 from array memory\n assembly {\n mstore(add(b, index), input)\n }\n }\n\n /// @dev Reads a uint256 value from a position in a byte array.\n /// @param b Byte array containing a uint256 value.\n /// @param index Index in byte array of uint256 value.\n /// @return result uint256 value from byte array.\n function readUint256(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (uint256 result)\n {\n result = uint256(readBytes32(b, index));\n return result;\n }\n\n /// @dev Writes a uint256 into a specific position in a byte array.\n /// @param b Byte array to insert <input> into.\n /// @param index Index in byte array of <input>.\n /// @param input uint256 to put into byte array.\n function writeUint256(\n bytes memory b,\n uint256 index,\n uint256 input\n )\n internal\n pure\n {\n writeBytes32(b, index, bytes32(input));\n }\n\n /// @dev Reads an unpadded bytes4 value from a position in a byte array.\n /// @param b Byte array containing a bytes4 value.\n /// @param index Index in byte array of bytes4 value.\n /// @return result bytes4 value from byte array.\n function readBytes4(\n bytes memory b,\n uint256 index\n )\n internal\n pure\n returns (bytes4 result)\n {\n if (b.length < index + 4) {\n LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError(\n LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired,\n b.length,\n index + 4\n ));\n }\n\n // Arrays are prefixed by a 32 byte length field\n index += 32;\n\n // Read the bytes4 from array memory\n assembly {\n result := mload(add(b, index))\n // Solidity does not require us to clean the trailing bytes.\n // We do it anyway\n result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)\n }\n return result;\n }\n\n /// @dev Writes a new length to a byte array.\n /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array.\n /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array.\n /// @param b Bytes array to write new length to.\n /// @param length New length of byte array.\n function writeLength(bytes memory b, uint256 length)\n internal\n pure\n {\n assembly {\n mstore(b, length)\n }\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibBytesRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibBytesRichErrorsV06 {\n\n enum InvalidByteOperationErrorCodes {\n FromLessThanOrEqualsToRequired,\n ToLessThanOrEqualsLengthRequired,\n LengthGreaterThanZeroRequired,\n LengthGreaterThanOrEqualsFourRequired,\n LengthGreaterThanOrEqualsTwentyRequired,\n LengthGreaterThanOrEqualsThirtyTwoRequired,\n LengthGreaterThanOrEqualsNestedBytesLengthRequired,\n DestinationLengthGreaterThanOrEqualSourceLengthRequired\n }\n\n // bytes4(keccak256(\"InvalidByteOperationError(uint8,uint256,uint256)\"))\n bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR =\n 0x28006595;\n\n // solhint-disable func-name-mixedcase\n function InvalidByteOperationError(\n InvalidByteOperationErrorCodes errorCode,\n uint256 offset,\n uint256 required\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n INVALID_BYTE_OPERATION_ERROR_SELECTOR,\n errorCode,\n offset,\n required\n );\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibRichErrorsV06 {\n\n // bytes4(keccak256(\"Error(string)\"))\n bytes4 internal constant STANDARD_ERROR_SELECTOR = 0x08c379a0;\n\n // solhint-disable func-name-mixedcase\n /// @dev ABI encode a standard, string revert error payload.\n /// This is the same payload that would be included by a `revert(string)`\n /// solidity statement. It has the function signature `Error(string)`.\n /// @param message The error string.\n /// @return The ABI encoded error.\n function StandardError(string memory message)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n STANDARD_ERROR_SELECTOR,\n bytes(message)\n );\n }\n // solhint-enable func-name-mixedcase\n\n /// @dev Reverts an encoded rich revert reason `errorData`.\n /// @param errorData ABI encoded error data.\n function rrevert(bytes memory errorData)\n internal\n pure\n {\n assembly {\n revert(add(errorData, 0x20), mload(errorData))\n }\n }\n}\n",
"./LibBootstrap.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibProxyRichErrors.sol\";\n\n\nlibrary LibBootstrap {\n\n /// @dev Magic bytes returned by the bootstrapper to indicate success.\n /// This is `keccack('BOOTSTRAP_SUCCESS')`.\n bytes4 internal constant BOOTSTRAP_SUCCESS = 0xd150751b;\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Perform a delegatecall and ensure it returns the magic bytes.\n /// @param target The call target.\n /// @param data The call data.\n function delegatecallBootstrapFunction(\n address target,\n bytes memory data\n )\n internal\n {\n (bool success, bytes memory resultData) = target.delegatecall(data);\n if (!success ||\n resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != BOOTSTRAP_SUCCESS)\n {\n LibProxyRichErrors.BootstrapCallFailedError(target, resultData).rrevert();\n }\n }\n}\n",
"../errors/LibProxyRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibProxyRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function NotImplementedError(bytes4 selector)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NotImplementedError(bytes4)\")),\n selector\n );\n }\n\n function InvalidBootstrapCallerError(address actual, address expected)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidBootstrapCallerError(address,address)\")),\n actual,\n expected\n );\n }\n\n function InvalidDieCallerError(address actual, address expected)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidDieCallerError(address,address)\")),\n actual,\n expected\n );\n }\n\n function BootstrapCallFailedError(address target, bytes memory resultData)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"BootstrapCallFailedError(address,bytes)\")),\n target,\n resultData\n );\n }\n}\n",
"../features/BootstrapFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"../storage/LibProxyStorage.sol\";\nimport \"./interfaces/IBootstrapFeature.sol\";\n\n\n/// @dev Detachable `bootstrap()` feature.\ncontract BootstrapFeature is\n IBootstrapFeature\n{\n // solhint-disable state-visibility,indent\n /// @dev The ZeroEx contract.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _deployer;\n /// @dev The implementation address of this contract.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _implementation;\n /// @dev The deployer.\n /// This has to be immutable to persist across delegatecalls.\n address immutable private _bootstrapCaller;\n // solhint-enable state-visibility,indent\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Construct this contract and set the bootstrap migration contract.\n /// After constructing this contract, `bootstrap()` should be called\n /// to seed the initial feature set.\n /// @param bootstrapCaller The allowed caller of `bootstrap()`.\n constructor(address bootstrapCaller) public {\n _deployer = msg.sender;\n _implementation = address(this);\n _bootstrapCaller = bootstrapCaller;\n }\n\n /// @dev Bootstrap the initial feature set of this contract by delegatecalling\n /// into `target`. Before exiting the `bootstrap()` function will\n /// deregister itself from the proxy to prevent being called again.\n /// @param target The bootstrapper contract address.\n /// @param callData The call data to execute on `target`.\n function bootstrap(address target, bytes calldata callData) external override {\n // Only the bootstrap caller can call this function.\n if (msg.sender != _bootstrapCaller) {\n LibProxyRichErrors.InvalidBootstrapCallerError(\n msg.sender,\n _bootstrapCaller\n ).rrevert();\n }\n // Deregister.\n LibProxyStorage.getStorage().impls[this.bootstrap.selector] = address(0);\n // Self-destruct.\n BootstrapFeature(_implementation).die();\n // Call the bootstrapper.\n LibBootstrap.delegatecallBootstrapFunction(target, callData);\n }\n\n /// @dev Self-destructs this contract.\n /// Can only be called by the deployer.\n function die() external {\n assert(address(this) == _implementation);\n if (msg.sender != _deployer) {\n LibProxyRichErrors.InvalidDieCallerError(msg.sender, _deployer).rrevert();\n }\n selfdestruct(msg.sender);\n }\n}\n",
"../storage/LibProxyStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the proxy contract.\nlibrary LibProxyStorage {\n\n /// @dev Storage bucket for proxy contract.\n struct Storage {\n // Mapping of function selector -> function implementation\n mapping(bytes4 => address) impls;\n // The owner of the proxy contract.\n address owner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.Proxy\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../storage/LibStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Common storage helpers\nlibrary LibStorage {\n\n /// @dev What to bit-shift a storage ID by to get its slot.\n /// This gives us a maximum of 2**128 inline fields in each bucket.\n uint256 private constant STORAGE_SLOT_EXP = 128;\n\n /// @dev Storage IDs for feature storage buckets.\n /// WARNING: APPEND-ONLY.\n enum StorageId {\n Proxy,\n SimpleFunctionRegistry,\n Ownable,\n TokenSpender,\n TransformERC20,\n MetaTransactions,\n ReentrancyGuard,\n NativeOrders\n }\n\n /// @dev Get the storage slot given a storage ID. We assign unique, well-spaced\n /// slots to storage bucket variables to ensure they do not overlap.\n /// See: https://solidity.readthedocs.io/en/v0.6.6/assembly.html#access-to-external-variables-functions-and-libraries\n /// @param storageId An entry in `StorageId`\n /// @return slot The storage slot.\n function getStorageSlot(StorageId storageId)\n internal\n pure\n returns (uint256 slot)\n {\n // This should never overflow with a reasonable `STORAGE_SLOT_EXP`\n // because Solidity will do a range check on `storageId` during the cast.\n return (uint256(storageId) + 1) << STORAGE_SLOT_EXP;\n }\n}\n",
"../features/interfaces/IBootstrapFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Detachable `bootstrap()` feature.\ninterface IBootstrapFeature {\n\n /// @dev Bootstrap the initial feature set of this contract by delegatecalling\n /// into `target`. Before exiting the `bootstrap()` function will\n /// deregister itself from the proxy to prevent being called again.\n /// @param target The bootstrapper contract address.\n /// @param callData The call data to execute on `target`.\n function bootstrap(address target, bytes calldata callData) external;\n}\n",
"../features/interfaces/IOwnableFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol\";\n\n\n// solhint-disable no-empty-blocks\n/// @dev Owner management and migration features.\ninterface IOwnableFeature is\n IOwnableV06\n{\n /// @dev Emitted when `migrate()` is called.\n /// @param caller The caller of `migrate()`.\n /// @param migrator The migration contract.\n /// @param newOwner The address of the new owner.\n event Migrated(address caller, address migrator, address newOwner);\n\n /// @dev Execute a migration function in the context of the ZeroEx contract.\n /// The result of the function being called should be the magic bytes\n /// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.\n /// The owner will be temporarily set to `address(this)` inside the call.\n /// Before returning, the owner will be set to `newOwner`.\n /// @param target The migrator contract address.\n /// @param newOwner The address of the new owner.\n /// @param data The call data.\n function migrate(address target, bytes calldata data, address newOwner) external;\n}\n",
"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\ninterface IOwnableV06 {\n\n /// @dev Emitted by Ownable when ownership is transferred.\n /// @param previousOwner The previous owner of the contract.\n /// @param newOwner The new owner of the contract.\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /// @dev Transfers ownership of the contract to a new address.\n /// @param newOwner The address that will become the owner.\n function transferOwnership(address newOwner) external;\n\n /// @dev The owner of this contract.\n /// @return ownerAddress The owner address.\n function owner() external view returns (address ownerAddress);\n}\n",
"../features/TokenSpenderFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../external/IAllowanceTarget.sol\";\nimport \"../storage/LibTokenSpenderStorage.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ITokenSpenderFeature.sol\";\n\n\n/// @dev Feature that allows spending token allowances.\ncontract TokenSpenderFeature is\n IFeature,\n ITokenSpenderFeature,\n FixinCommon\n{\n // solhint-disable\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"TokenSpender\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n // solhint-enable\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initialize and register this feature. Should be delegatecalled\n /// into during a `Migrate.migrate()`.\n /// @param allowanceTarget An `allowanceTarget` instance, configured to have\n /// the ZeroeEx contract as an authority.\n /// @return success `MIGRATE_SUCCESS` on success.\n function migrate(IAllowanceTarget allowanceTarget)\n external\n returns (bytes4 success)\n {\n LibTokenSpenderStorage.getStorage().allowanceTarget = allowanceTarget;\n _registerFeatureFunction(this.getAllowanceTarget.selector);\n _registerFeatureFunction(this._spendERC20Tokens.selector);\n _registerFeatureFunction(this.getSpendableERC20BalanceOf.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`. Only callable from within.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _spendERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n external\n override\n onlySelf\n {\n IAllowanceTarget spender = LibTokenSpenderStorage.getStorage().allowanceTarget;\n // Have the allowance target execute an ERC20 `transferFrom()`.\n (bool didSucceed, bytes memory resultData) = address(spender).call(\n abi.encodeWithSelector(\n IAllowanceTarget.executeCall.selector,\n address(token),\n abi.encodeWithSelector(\n IERC20TokenV06.transferFrom.selector,\n owner,\n to,\n amount\n )\n )\n );\n if (didSucceed) {\n resultData = abi.decode(resultData, (bytes));\n }\n if (!didSucceed || !LibERC20TokenV06.isSuccessfulResult(resultData)) {\n LibSpenderRichErrors.SpenderERC20TransferFromFailedError(\n address(token),\n owner,\n to,\n amount,\n resultData\n ).rrevert();\n }\n }\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner` by the token spender.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function getSpendableERC20BalanceOf(IERC20TokenV06 token, address owner)\n external\n override\n view\n returns (uint256 amount)\n {\n return LibSafeMathV06.min256(\n token.allowance(owner, address(LibTokenSpenderStorage.getStorage().allowanceTarget)),\n token.balanceOf(owner)\n );\n }\n\n /// @dev Get the address of the allowance target.\n /// @return target The target of token allowances.\n function getAllowanceTarget()\n external\n override\n view\n returns (address target)\n {\n return address(LibTokenSpenderStorage.getStorage().allowanceTarget);\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibSafeMathRichErrorsV06.sol\";\n\n\nlibrary LibSafeMathV06 {\n\n function safeMul(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (a == 0) {\n return 0;\n }\n uint256 c = a * b;\n if (c / a != b) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function safeDiv(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (b == 0) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO,\n a,\n b\n ));\n }\n uint256 c = a / b;\n return c;\n }\n\n function safeSub(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n if (b > a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,\n a,\n b\n ));\n }\n return a - b;\n }\n\n function safeAdd(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n uint256 c = a + b;\n if (c < a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function max256(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n return a >= b ? a : b;\n }\n\n function min256(uint256 a, uint256 b)\n internal\n pure\n returns (uint256)\n {\n return a < b ? a : b;\n }\n\n function safeMul128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (a == 0) {\n return 0;\n }\n uint128 c = a * b;\n if (c / a != b) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function safeDiv128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (b == 0) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO,\n a,\n b\n ));\n }\n uint128 c = a / b;\n return c;\n }\n\n function safeSub128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n if (b > a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,\n a,\n b\n ));\n }\n return a - b;\n }\n\n function safeAdd128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n uint128 c = a + b;\n if (c < a) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError(\n LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW,\n a,\n b\n ));\n }\n return c;\n }\n\n function max128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n return a >= b ? a : b;\n }\n\n function min128(uint128 a, uint128 b)\n internal\n pure\n returns (uint128)\n {\n return a < b ? a : b;\n }\n\n function safeDowncastToUint128(uint256 a)\n internal\n pure\n returns (uint128)\n {\n if (a > type(uint128).max) {\n LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256DowncastError(\n LibSafeMathRichErrorsV06.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128,\n a\n ));\n }\n return uint128(a);\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibSafeMathRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSafeMathRichErrorsV06 {\n\n // bytes4(keccak256(\"Uint256BinOpError(uint8,uint256,uint256)\"))\n bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR =\n 0xe946c1bb;\n\n // bytes4(keccak256(\"Uint256DowncastError(uint8,uint256)\"))\n bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR =\n 0xc996af7b;\n\n enum BinOpErrorCodes {\n ADDITION_OVERFLOW,\n MULTIPLICATION_OVERFLOW,\n SUBTRACTION_UNDERFLOW,\n DIVISION_BY_ZERO\n }\n\n enum DowncastErrorCodes {\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96,\n VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128\n }\n\n // solhint-disable func-name-mixedcase\n function Uint256BinOpError(\n BinOpErrorCodes errorCode,\n uint256 a,\n uint256 b\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n UINT256_BINOP_ERROR_SELECTOR,\n errorCode,\n a,\n b\n );\n }\n\n function Uint256DowncastError(\n DowncastErrorCodes errorCode,\n uint256 a\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n UINT256_DOWNCAST_ERROR_SELECTOR,\n errorCode,\n a\n );\n }\n}\n",
"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\ninterface IERC20TokenV06 {\n\n // solhint-disable no-simple-event-func-name\n event Transfer(\n address indexed from,\n address indexed to,\n uint256 value\n );\n\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n\n /// @dev send `value` token to `to` from `msg.sender`\n /// @param to The address of the recipient\n /// @param value The amount of token to be transferred\n /// @return True if transfer was successful\n function transfer(address to, uint256 value)\n external\n returns (bool);\n\n /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`\n /// @param from The address of the sender\n /// @param to The address of the recipient\n /// @param value The amount of token to be transferred\n /// @return True if transfer was successful\n function transferFrom(\n address from,\n address to,\n uint256 value\n )\n external\n returns (bool);\n\n /// @dev `msg.sender` approves `spender` to spend `value` tokens\n /// @param spender The address of the account able to transfer the tokens\n /// @param value The amount of wei to be approved for transfer\n /// @return Always true if the call has enough gas to complete execution\n function approve(address spender, uint256 value)\n external\n returns (bool);\n\n /// @dev Query total supply of token\n /// @return Total supply of token\n function totalSupply()\n external\n view\n returns (uint256);\n\n /// @dev Get the balance of `owner`.\n /// @param owner The address from which the balance will be retrieved\n /// @return Balance of owner\n function balanceOf(address owner)\n external\n view\n returns (uint256);\n\n /// @dev Get the allowance for `spender` to spend from `owner`.\n /// @param owner The address of the account owning tokens\n /// @param spender The address of the account able to transfer the tokens\n /// @return Amount of remaining tokens allowed to spent\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /// @dev Get the number of decimals this token has.\n function decimals()\n external\n view\n returns (uint8);\n}\n",
"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"./IERC20TokenV06.sol\";\n\n\nlibrary LibERC20TokenV06 {\n bytes constant private DECIMALS_CALL_DATA = hex\"313ce567\";\n\n /// @dev Calls `IERC20TokenV06(token).approve()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param spender The address that receives an allowance.\n /// @param allowance The allowance to set.\n function compatApprove(\n IERC20TokenV06 token,\n address spender,\n uint256 allowance\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.approve.selector,\n spender,\n allowance\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Calls `IERC20TokenV06(token).approve()` and sets the allowance to the\n /// maximum if the current approval is not already >= an amount.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param spender The address that receives an allowance.\n /// @param amount The minimum allowance needed.\n function approveIfBelow(\n IERC20TokenV06 token,\n address spender,\n uint256 amount\n )\n internal\n {\n if (token.allowance(address(this), spender) < amount) {\n compatApprove(token, spender, uint256(-1));\n }\n }\n\n /// @dev Calls `IERC20TokenV06(token).transfer()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param to The address that receives the tokens\n /// @param amount Number of tokens to transfer.\n function compatTransfer(\n IERC20TokenV06 token,\n address to,\n uint256 amount\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.transfer.selector,\n to,\n amount\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Calls `IERC20TokenV06(token).transferFrom()`.\n /// Reverts if the result fails `isSuccessfulResult()` or the call reverts.\n /// @param token The address of the token contract.\n /// @param from The owner of the tokens.\n /// @param to The address that receives the tokens\n /// @param amount Number of tokens to transfer.\n function compatTransferFrom(\n IERC20TokenV06 token,\n address from,\n address to,\n uint256 amount\n )\n internal\n {\n bytes memory callData = abi.encodeWithSelector(\n token.transferFrom.selector,\n from,\n to,\n amount\n );\n _callWithOptionalBooleanResult(address(token), callData);\n }\n\n /// @dev Retrieves the number of decimals for a token.\n /// Returns `18` if the call reverts.\n /// @param token The address of the token contract.\n /// @return tokenDecimals The number of decimals places for the token.\n function compatDecimals(IERC20TokenV06 token)\n internal\n view\n returns (uint8 tokenDecimals)\n {\n tokenDecimals = 18;\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA);\n if (didSucceed && resultData.length >= 32) {\n tokenDecimals = uint8(LibBytesV06.readUint256(resultData, 0));\n }\n }\n\n /// @dev Retrieves the allowance for a token, owner, and spender.\n /// Returns `0` if the call reverts.\n /// @param token The address of the token contract.\n /// @param owner The owner of the tokens.\n /// @param spender The address the spender.\n /// @return allowance_ The allowance for a token, owner, and spender.\n function compatAllowance(IERC20TokenV06 token, address owner, address spender)\n internal\n view\n returns (uint256 allowance_)\n {\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(\n abi.encodeWithSelector(\n token.allowance.selector,\n owner,\n spender\n )\n );\n if (didSucceed && resultData.length >= 32) {\n allowance_ = LibBytesV06.readUint256(resultData, 0);\n }\n }\n\n /// @dev Retrieves the balance for a token owner.\n /// Returns `0` if the call reverts.\n /// @param token The address of the token contract.\n /// @param owner The owner of the tokens.\n /// @return balance The token balance of an owner.\n function compatBalanceOf(IERC20TokenV06 token, address owner)\n internal\n view\n returns (uint256 balance)\n {\n (bool didSucceed, bytes memory resultData) = address(token).staticcall(\n abi.encodeWithSelector(\n token.balanceOf.selector,\n owner\n )\n );\n if (didSucceed && resultData.length >= 32) {\n balance = LibBytesV06.readUint256(resultData, 0);\n }\n }\n\n /// @dev Check if the data returned by a non-static call to an ERC20 token\n /// is a successful result. Supported functions are `transfer()`,\n /// `transferFrom()`, and `approve()`.\n /// @param resultData The raw data returned by a non-static call to the ERC20 token.\n /// @return isSuccessful Whether the result data indicates success.\n function isSuccessfulResult(bytes memory resultData)\n internal\n pure\n returns (bool isSuccessful)\n {\n if (resultData.length == 0) {\n return true;\n }\n if (resultData.length >= 32) {\n uint256 result = LibBytesV06.readUint256(resultData, 0);\n if (result == 1) {\n return true;\n }\n }\n }\n\n /// @dev Executes a call on address `target` with calldata `callData`\n /// and asserts that either nothing was returned or a single boolean\n /// was returned equal to `true`.\n /// @param target The call target.\n /// @param callData The abi-encoded call data.\n function _callWithOptionalBooleanResult(\n address target,\n bytes memory callData\n )\n private\n {\n (bool didSucceed, bytes memory resultData) = target.call(callData);\n if (didSucceed && isSuccessfulResult(resultData)) {\n return;\n }\n LibRichErrorsV06.rrevert(resultData);\n }\n}\n",
"../errors/LibSpenderRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSpenderRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function SpenderERC20TransferFromFailedError(\n address token,\n address owner,\n address to,\n uint256 amount,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SpenderERC20TransferFromFailedError(address,address,address,uint256,bytes)\")),\n token,\n owner,\n to,\n amount,\n errorData\n );\n }\n}\n",
"../fixins/FixinCommon.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\nimport \"../features/interfaces/IOwnableFeature.sol\";\nimport \"../features/interfaces/ISimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Common feature utilities.\nabstract contract FixinCommon {\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev The implementation address of this feature.\n address internal immutable _implementation;\n\n /// @dev The caller must be this contract.\n modifier onlySelf() virtual {\n if (msg.sender != address(this)) {\n LibCommonRichErrors.OnlyCallableBySelfError(msg.sender).rrevert();\n }\n _;\n }\n\n /// @dev The caller of this function must be the owner.\n modifier onlyOwner() virtual {\n {\n address owner = IOwnableFeature(address(this)).owner();\n if (msg.sender != owner) {\n LibOwnableRichErrors.OnlyOwnerError(\n msg.sender,\n owner\n ).rrevert();\n }\n }\n _;\n }\n\n constructor() internal {\n // Remember this feature's original address.\n _implementation = address(this);\n }\n\n /// @dev Registers a function implemented by this feature at `_implementation`.\n /// Can and should only be called within a `migrate()`.\n /// @param selector The selector of the function whose implementation\n /// is at `_implementation`.\n function _registerFeatureFunction(bytes4 selector)\n internal\n {\n ISimpleFunctionRegistryFeature(address(this)).extend(selector, _implementation);\n }\n\n /// @dev Encode a feature version as a `uint256`.\n /// @param major The major version number of the feature.\n /// @param minor The minor version number of the feature.\n /// @param revision The revision number of the feature.\n /// @return encodedVersion The encoded version number.\n function _encodeVersion(uint32 major, uint32 minor, uint32 revision)\n internal\n pure\n returns (uint256 encodedVersion)\n {\n return (uint256(major) << 64) | (uint256(minor) << 32) | uint256(revision);\n }\n}\n",
"../errors/LibCommonRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibCommonRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function OnlyCallableBySelfError(address sender)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyCallableBySelfError(address)\")),\n sender\n );\n }\n\n function IllegalReentrancyError(bytes4 selector, uint256 reentrancyFlags)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IllegalReentrancyError(bytes4,uint256)\")),\n selector,\n reentrancyFlags\n );\n }\n}\n",
"../errors/LibOwnableRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibOwnableRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function OnlyOwnerError(\n address sender,\n address owner\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyOwnerError(address,address)\")),\n sender,\n owner\n );\n }\n\n function TransferOwnerToZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"TransferOwnerToZeroError()\"))\n );\n }\n\n function MigrateCallFailedError(address target, bytes memory resultData)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MigrateCallFailedError(address,bytes)\")),\n target,\n resultData\n );\n }\n}\n",
"../features/interfaces/ISimpleFunctionRegistryFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Basic registry management features.\ninterface ISimpleFunctionRegistryFeature {\n\n /// @dev A function implementation was updated via `extend()` or `rollback()`.\n /// @param selector The function selector.\n /// @param oldImpl The implementation contract address being replaced.\n /// @param newImpl The replacement implementation contract address.\n event ProxyFunctionUpdated(bytes4 indexed selector, address oldImpl, address newImpl);\n\n /// @dev Roll back to a prior implementation of a function.\n /// @param selector The function selector.\n /// @param targetImpl The address of an older implementation of the function.\n function rollback(bytes4 selector, address targetImpl) external;\n\n /// @dev Register or replace a function.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function extend(bytes4 selector, address impl) external;\n\n /// @dev Retrieve the length of the rollback history for a function.\n /// @param selector The function selector.\n /// @return rollbackLength The number of items in the rollback history for\n /// the function.\n function getRollbackLength(bytes4 selector)\n external\n view\n returns (uint256 rollbackLength);\n\n /// @dev Retrieve an entry in the rollback history for a function.\n /// @param selector The function selector.\n /// @param idx The index in the rollback history.\n /// @return impl An implementation address for the function at\n /// index `idx`.\n function getRollbackEntryAtIndex(bytes4 selector, uint256 idx)\n external\n view\n returns (address impl);\n}\n",
"./LibMigrate.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\n\n\nlibrary LibMigrate {\n\n /// @dev Magic bytes returned by a migrator to indicate success.\n /// This is `keccack('MIGRATE_SUCCESS')`.\n bytes4 internal constant MIGRATE_SUCCESS = 0x2c64c5ef;\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Perform a delegatecall and ensure it returns the magic bytes.\n /// @param target The call target.\n /// @param data The call data.\n function delegatecallMigrateFunction(\n address target,\n bytes memory data\n )\n internal\n {\n (bool success, bytes memory resultData) = target.delegatecall(data);\n if (!success ||\n resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != MIGRATE_SUCCESS)\n {\n LibOwnableRichErrors.MigrateCallFailedError(target, resultData).rrevert();\n }\n }\n}\n",
"../external/IAllowanceTarget.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IAuthorizableV06.sol\";\n\n\n/// @dev The allowance target for the TokenSpender feature.\ninterface IAllowanceTarget is\n IAuthorizableV06\n{\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData\n )\n external\n returns (bytes memory resultData);\n}\n",
"@0x/contracts-utils/contracts/src/v06/interfaces/IAuthorizableV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./IOwnableV06.sol\";\n\n\ninterface IAuthorizableV06 is\n IOwnableV06\n{\n // Event logged when a new address is authorized.\n event AuthorizedAddressAdded(\n address indexed target,\n address indexed caller\n );\n\n // Event logged when a currently authorized address is unauthorized.\n event AuthorizedAddressRemoved(\n address indexed target,\n address indexed caller\n );\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function addAuthorizedAddress(address target)\n external;\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n function removeAuthorizedAddress(address target)\n external;\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n external;\n\n /// @dev Gets all authorized addresses.\n /// @return authorizedAddresses Array of authorized addresses.\n function getAuthorizedAddresses()\n external\n view\n returns (address[] memory authorizedAddresses);\n\n /// @dev Whether an adderss is authorized to call privileged functions.\n /// @param addr Address to query.\n /// @return isAuthorized Whether the address is authorized.\n function authorized(address addr) external view returns (bool isAuthorized);\n\n /// @dev All addresseses authorized to call privileged functions.\n /// @param idx Index of authorized address.\n /// @return addr Authorized address.\n function authorities(uint256 idx) external view returns (address addr);\n\n}\n",
"../storage/LibTokenSpenderStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IAllowanceTarget.sol\";\n\n\n/// @dev Storage helpers for the `TokenSpender` feature.\nlibrary LibTokenSpenderStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Allowance target contract.\n IAllowanceTarget allowanceTarget;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.TokenSpender\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../features/interfaces/IFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Basic interface for a feature contract.\ninterface IFeature {\n\n // solhint-disable func-name-mixedcase\n\n /// @dev The name of this feature set.\n function FEATURE_NAME() external view returns (string memory name);\n\n /// @dev The version of this feature set.\n function FEATURE_VERSION() external view returns (uint256 version);\n}\n",
"../features/interfaces/ITokenSpenderFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\n\n\n/// @dev Feature that allows spending token allowances.\ninterface ITokenSpenderFeature {\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`.\n /// Only callable from within.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _spendERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n external;\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner`.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function getSpendableERC20BalanceOf(IERC20TokenV06 token, address owner)\n external\n view\n returns (uint256 amount);\n\n /// @dev Get the address of the allowance target.\n /// @return target The target of token allowances.\n function getAllowanceTarget() external view returns (address target);\n}\n",
"../features/TransformERC20Feature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../errors/LibTransformERC20RichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../fixins/FixinTokenSpender.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../external/IFlashWallet.sol\";\nimport \"../external/FlashWallet.sol\";\nimport \"../storage/LibTransformERC20Storage.sol\";\nimport \"../transformers/IERC20Transformer.sol\";\nimport \"../transformers/LibERC20Transformer.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ITransformERC20Feature.sol\";\n\n\n/// @dev Feature to composably transform between ERC20 tokens.\ncontract TransformERC20Feature is\n IFeature,\n ITransformERC20Feature,\n FixinCommon,\n FixinTokenSpender\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Stack vars for `_transformERC20Private()`.\n struct TransformERC20PrivateState {\n IFlashWallet wallet;\n address transformerDeployer;\n uint256 takerOutputTokenBalanceBefore;\n uint256 takerOutputTokenBalanceAfter;\n }\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"TransformERC20\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 3, 1);\n\n constructor(bytes32 greedyTokensBloomFilter)\n public\n FixinTokenSpender(greedyTokensBloomFilter)\n {}\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @param transformerDeployer The trusted deployer for transformers.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate(address transformerDeployer)\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.getTransformerDeployer.selector);\n _registerFeatureFunction(this.createTransformWallet.selector);\n _registerFeatureFunction(this.getTransformWallet.selector);\n _registerFeatureFunction(this.setTransformerDeployer.selector);\n _registerFeatureFunction(this.setQuoteSigner.selector);\n _registerFeatureFunction(this.getQuoteSigner.selector);\n _registerFeatureFunction(this.transformERC20.selector);\n _registerFeatureFunction(this._transformERC20.selector);\n if (this.getTransformWallet() == IFlashWallet(address(0))) {\n // Create the transform wallet if it doesn't exist.\n this.createTransformWallet();\n }\n LibTransformERC20Storage.getStorage().transformerDeployer = transformerDeployer;\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Replace the allowed deployer for transformers.\n /// Only callable by the owner.\n /// @param transformerDeployer The address of the trusted deployer for transformers.\n function setTransformerDeployer(address transformerDeployer)\n external\n override\n onlyOwner\n {\n LibTransformERC20Storage.getStorage().transformerDeployer = transformerDeployer;\n emit TransformerDeployerUpdated(transformerDeployer);\n }\n\n /// @dev Replace the optional signer for `transformERC20()` calldata.\n /// Only callable by the owner.\n /// @param quoteSigner The address of the new calldata signer.\n function setQuoteSigner(address quoteSigner)\n external\n override\n onlyOwner\n {\n LibTransformERC20Storage.getStorage().quoteSigner = quoteSigner;\n emit QuoteSignerUpdated(quoteSigner);\n }\n\n /// @dev Return the allowed deployer for transformers.\n /// @return deployer The transform deployer address.\n function getTransformerDeployer()\n public\n override\n view\n returns (address deployer)\n {\n return LibTransformERC20Storage.getStorage().transformerDeployer;\n }\n\n /// @dev Return the optional signer for `transformERC20()` calldata.\n /// @return signer The signer address.\n function getQuoteSigner()\n public\n override\n view\n returns (address signer)\n {\n return LibTransformERC20Storage.getStorage().quoteSigner;\n }\n\n /// @dev Deploy a new wallet instance and replace the current one with it.\n /// Useful if we somehow break the current wallet instance.\n /// Only callable by the owner.\n /// @return wallet The new wallet instance.\n function createTransformWallet()\n public\n override\n onlyOwner\n returns (IFlashWallet wallet)\n {\n wallet = new FlashWallet();\n LibTransformERC20Storage.getStorage().wallet = wallet;\n }\n\n /// @dev Executes a series of transformations to convert an ERC20 `inputToken`\n /// to an ERC20 `outputToken`.\n /// @param inputToken The token being provided by the sender.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the sender.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the sender.\n /// If set to `uint256(-1)`, the entire spendable balance of the taker\n /// will be solt.\n /// @param minOutputTokenAmount The minimum amount of `outputToken` the sender\n /// must receive for the entire transformation to succeed. If set to zero,\n /// the minimum output token transfer will not be asserted.\n /// @param transformations The transformations to execute on the token balance(s)\n /// in sequence.\n /// @return outputTokenAmount The amount of `outputToken` received by the sender.\n function transformERC20(\n IERC20TokenV06 inputToken,\n IERC20TokenV06 outputToken,\n uint256 inputTokenAmount,\n uint256 minOutputTokenAmount,\n Transformation[] memory transformations\n )\n public\n override\n payable\n returns (uint256 outputTokenAmount)\n {\n return _transformERC20Private(\n TransformERC20Args({\n taker: msg.sender,\n inputToken: inputToken,\n outputToken: outputToken,\n inputTokenAmount: inputTokenAmount,\n minOutputTokenAmount: minOutputTokenAmount,\n transformations: transformations\n })\n );\n }\n\n /// @dev Internal version of `transformERC20()`. Only callable from within.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20(TransformERC20Args memory args)\n public\n virtual\n override\n payable\n onlySelf\n returns (uint256 outputTokenAmount)\n {\n return _transformERC20Private(args);\n }\n\n /// @dev Private version of `transformERC20()`.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20Private(TransformERC20Args memory args)\n private\n returns (uint256 outputTokenAmount)\n {\n // If the input token amount is -1 and we are not selling ETH,\n // transform the taker's entire spendable balance.\n if (args.inputTokenAmount == uint256(-1)) {\n if (LibERC20Transformer.isTokenETH(args.inputToken)) {\n // We can't pull more ETH from the taker, so we just set the\n // input token amount to the value attached to the call.\n args.inputTokenAmount = msg.value;\n } else {\n args.inputTokenAmount = _getSpendableERC20BalanceOf(\n args.inputToken,\n args.taker\n );\n }\n }\n\n TransformERC20PrivateState memory state;\n state.wallet = getTransformWallet();\n state.transformerDeployer = getTransformerDeployer();\n\n // Remember the initial output token balance of the taker.\n state.takerOutputTokenBalanceBefore =\n LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker);\n\n // Pull input tokens from the taker to the wallet and transfer attached ETH.\n _transferInputTokensAndAttachedEth(\n args.inputToken,\n args.taker,\n address(state.wallet),\n args.inputTokenAmount\n );\n\n {\n // Perform transformations.\n for (uint256 i = 0; i < args.transformations.length; ++i) {\n _executeTransformation(\n state.wallet,\n args.transformations[i],\n state.transformerDeployer,\n args.taker\n );\n }\n }\n\n // Compute how much output token has been transferred to the taker.\n state.takerOutputTokenBalanceAfter =\n LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker);\n if (state.takerOutputTokenBalanceAfter < state.takerOutputTokenBalanceBefore) {\n LibTransformERC20RichErrors.NegativeTransformERC20OutputError(\n address(args.outputToken),\n state.takerOutputTokenBalanceBefore - state.takerOutputTokenBalanceAfter\n ).rrevert();\n }\n outputTokenAmount = state.takerOutputTokenBalanceAfter.safeSub(\n state.takerOutputTokenBalanceBefore\n );\n // Ensure enough output token has been sent to the taker.\n if (outputTokenAmount < args.minOutputTokenAmount) {\n LibTransformERC20RichErrors.IncompleteTransformERC20Error(\n address(args.outputToken),\n outputTokenAmount,\n args.minOutputTokenAmount\n ).rrevert();\n }\n\n // Emit an event.\n emit TransformedERC20(\n args.taker,\n address(args.inputToken),\n address(args.outputToken),\n args.inputTokenAmount,\n outputTokenAmount\n );\n }\n\n /// @dev Return the current wallet instance that will serve as the execution\n /// context for transformations.\n /// @return wallet The wallet instance.\n function getTransformWallet()\n public\n override\n view\n returns (IFlashWallet wallet)\n {\n return LibTransformERC20Storage.getStorage().wallet;\n }\n\n /// @dev Transfer input tokens from the taker and any attached ETH to `to`\n /// @param inputToken The token to pull from the taker.\n /// @param from The from (taker) address.\n /// @param to The recipient of tokens and ETH.\n /// @param amount Amount of `inputToken` tokens to transfer.\n function _transferInputTokensAndAttachedEth(\n IERC20TokenV06 inputToken,\n address from,\n address payable to,\n uint256 amount\n )\n private\n {\n // Transfer any attached ETH.\n if (msg.value != 0) {\n to.transfer(msg.value);\n }\n // Transfer input tokens.\n if (!LibERC20Transformer.isTokenETH(inputToken) && amount != 0) {\n // Token is not ETH, so pull ERC20 tokens.\n _transferERC20Tokens(\n inputToken,\n from,\n to,\n amount\n );\n } else if (msg.value < amount) {\n // Token is ETH, so the caller must attach enough ETH to the call.\n LibTransformERC20RichErrors.InsufficientEthAttachedError(\n msg.value,\n amount\n ).rrevert();\n }\n }\n\n /// @dev Executs a transformer in the context of `wallet`.\n /// @param wallet The wallet instance.\n /// @param transformation The transformation.\n /// @param transformerDeployer The address of the transformer deployer.\n /// @param taker The taker address.\n function _executeTransformation(\n IFlashWallet wallet,\n Transformation memory transformation,\n address transformerDeployer,\n address payable taker\n )\n private\n {\n // Derive the transformer address from the deployment nonce.\n address payable transformer = LibERC20Transformer.getDeployedAddress(\n transformerDeployer,\n transformation.deploymentNonce\n );\n // Call `transformer.transform()` as the wallet.\n bytes memory resultData = wallet.executeDelegateCall(\n // The call target.\n transformer,\n // Call data.\n abi.encodeWithSelector(\n IERC20Transformer.transform.selector,\n IERC20Transformer.TransformContext({\n sender: msg.sender,\n taker: taker,\n data: transformation.data\n })\n )\n );\n // Ensure the transformer returned the magic bytes.\n if (resultData.length != 32 ||\n abi.decode(resultData, (bytes4)) != LibERC20Transformer.TRANSFORMER_SUCCESS\n ) {\n LibTransformERC20RichErrors.TransformerFailedError(\n transformer,\n transformation.data,\n resultData\n ).rrevert();\n }\n }\n}\n",
"../errors/LibTransformERC20RichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibTransformERC20RichErrors {\n\n // solhint-disable func-name-mixedcase,separate-by-one-line-in-contract\n\n function InsufficientEthAttachedError(\n uint256 ethAttached,\n uint256 ethNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientEthAttachedError(uint256,uint256)\")),\n ethAttached,\n ethNeeded\n );\n }\n\n function IncompleteTransformERC20Error(\n address outputToken,\n uint256 outputTokenAmount,\n uint256 minOutputTokenAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteTransformERC20Error(address,uint256,uint256)\")),\n outputToken,\n outputTokenAmount,\n minOutputTokenAmount\n );\n }\n\n function NegativeTransformERC20OutputError(\n address outputToken,\n uint256 outputTokenLostAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NegativeTransformERC20OutputError(address,uint256)\")),\n outputToken,\n outputTokenLostAmount\n );\n }\n\n function TransformerFailedError(\n address transformer,\n bytes memory transformerData,\n bytes memory resultData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"TransformerFailedError(address,bytes,bytes)\")),\n transformer,\n transformerData,\n resultData\n );\n }\n\n // Common Transformer errors ///////////////////////////////////////////////\n\n function OnlyCallableByDeployerError(\n address caller,\n address deployer\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyCallableByDeployerError(address,address)\")),\n caller,\n deployer\n );\n }\n\n function InvalidExecutionContextError(\n address actualContext,\n address expectedContext\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidExecutionContextError(address,address)\")),\n actualContext,\n expectedContext\n );\n }\n\n enum InvalidTransformDataErrorCode {\n INVALID_TOKENS,\n INVALID_ARRAY_LENGTH\n }\n\n function InvalidTransformDataError(\n InvalidTransformDataErrorCode errorCode,\n bytes memory transformData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidTransformDataError(uint8,bytes)\")),\n errorCode,\n transformData\n );\n }\n\n // FillQuoteTransformer errors /////////////////////////////////////////////\n\n function IncompleteFillSellQuoteError(\n address sellToken,\n uint256 soldAmount,\n uint256 sellAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteFillSellQuoteError(address,uint256,uint256)\")),\n sellToken,\n soldAmount,\n sellAmount\n );\n }\n\n function IncompleteFillBuyQuoteError(\n address buyToken,\n uint256 boughtAmount,\n uint256 buyAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"IncompleteFillBuyQuoteError(address,uint256,uint256)\")),\n buyToken,\n boughtAmount,\n buyAmount\n );\n }\n\n function InsufficientTakerTokenError(\n uint256 tokenBalance,\n uint256 tokensNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientTakerTokenError(uint256,uint256)\")),\n tokenBalance,\n tokensNeeded\n );\n }\n\n function InsufficientProtocolFeeError(\n uint256 ethBalance,\n uint256 ethNeeded\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InsufficientProtocolFeeError(uint256,uint256)\")),\n ethBalance,\n ethNeeded\n );\n }\n\n function InvalidERC20AssetDataError(\n bytes memory assetData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidERC20AssetDataError(bytes)\")),\n assetData\n );\n }\n\n function InvalidTakerFeeTokenError(\n address token\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidTakerFeeTokenError(address)\")),\n token\n );\n }\n}\n",
"../fixins/FixinTokenSpender.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../features/interfaces/ITokenSpenderFeature.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"../external/FeeCollector.sol\";\nimport \"../vendor/v3/IStaking.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n\n/// @dev Helpers for moving tokens around.\nabstract contract FixinTokenSpender {\n using LibRichErrorsV06 for bytes;\n\n // Mask of the lower 20 bytes of a bytes32.\n uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;\n /// @dev A bloom filter for tokens that consume all gas when `transferFrom()` fails.\n bytes32 public immutable GREEDY_TOKENS_BLOOM_FILTER;\n\n /// @param greedyTokensBloomFilter The bloom filter for all greedy tokens.\n constructor(bytes32 greedyTokensBloomFilter)\n internal\n {\n GREEDY_TOKENS_BLOOM_FILTER = greedyTokensBloomFilter;\n }\n\n /// @dev Transfers ERC20 tokens from `owner` to `to`.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @param to The recipient of the tokens.\n /// @param amount The amount of `token` to transfer.\n function _transferERC20Tokens(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount\n )\n internal\n {\n bool success;\n bytes memory revertData;\n\n require(address(token) != address(this), \"FixinTokenSpender/CANNOT_INVOKE_SELF\");\n\n // If the token eats all gas when failing, we do not want to perform\n // optimistic fall through to the old AllowanceTarget contract if the\n // direct transferFrom() fails.\n if (_isTokenPossiblyGreedy(token)) {\n // If the token does not have a direct allowance on us then we use\n // the allowance target.\n if (token.allowance(owner, address(this)) < amount) {\n _transferFromLegacyAllowanceTarget(\n token,\n owner,\n to,\n amount,\n \"\"\n );\n return;\n }\n }\n\n assembly {\n let ptr := mload(0x40) // free memory pointer\n\n // selector for transferFrom(address,address,uint256)\n mstore(ptr, 0x23b872dd00000000000000000000000000000000000000000000000000000000)\n mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK))\n mstore(add(ptr, 0x24), and(to, ADDRESS_MASK))\n mstore(add(ptr, 0x44), amount)\n\n success := call(\n gas(),\n and(token, ADDRESS_MASK),\n 0,\n ptr,\n 0x64,\n 0,\n 0\n )\n\n let rdsize := returndatasize()\n\n returndatacopy(add(ptr, 0x20), 0, rdsize) // reuse memory\n\n // Check for ERC20 success. ERC20 tokens should return a boolean,\n // but some don't. We accept 0-length return data as success, or at\n // least 32 bytes that starts with a 32-byte boolean true.\n success := and(\n success, // call itself succeeded\n or(\n iszero(rdsize), // no return data, or\n and(\n iszero(lt(rdsize, 32)), // at least 32 bytes\n eq(mload(add(ptr, 0x20)), 1) // starts with uint256(1)\n )\n )\n )\n\n if iszero(success) {\n // revertData is a bytes, so length-prefixed data\n mstore(ptr, rdsize)\n revertData := ptr\n\n // update free memory pointer (ptr + 32-byte length + return data)\n mstore(0x40, add(add(ptr, 0x20), rdsize))\n }\n }\n\n if (!success) {\n _transferFromLegacyAllowanceTarget(\n token,\n owner,\n to,\n amount,\n revertData\n );\n }\n }\n\n /// @dev Gets the maximum amount of an ERC20 token `token` that can be\n /// pulled from `owner` by this address.\n /// @param token The token to spend.\n /// @param owner The owner of the tokens.\n /// @return amount The amount of tokens that can be pulled.\n function _getSpendableERC20BalanceOf(\n IERC20TokenV06 token,\n address owner\n )\n internal\n view\n returns (uint256)\n {\n return LibSafeMathV06.min256(\n token.allowance(owner, address(this)),\n token.balanceOf(owner)\n );\n }\n\n /// @dev Check if a token possibly belongs to the `GREEDY_TOKENS_BLOOM_FILTER`\n /// bloom filter.\n function _isTokenPossiblyGreedy(IERC20TokenV06 token)\n internal\n view\n returns (bool isPossiblyGreedy)\n {\n // The hash is given by:\n // (1 << (keccak256(token) % 256)) | (1 << (token % 256))\n bytes32 h;\n assembly {\n mstore(0, token)\n h := or(shl(mod(keccak256(0, 32), 256), 1), shl(mod(token, 256), 1))\n }\n return (h & GREEDY_TOKENS_BLOOM_FILTER) == h;\n }\n\n /// @dev Transfer tokens using the legacy allowance target instead of\n /// allowances directly set on the exchange proxy.\n function _transferFromLegacyAllowanceTarget(\n IERC20TokenV06 token,\n address owner,\n address to,\n uint256 amount,\n bytes memory initialRevertData\n )\n private\n {\n // Try the old AllowanceTarget.\n try ITokenSpenderFeature(address(this))._spendERC20Tokens(\n token,\n owner,\n to,\n amount\n ) {\n } catch (bytes memory revertData) {\n // Bubble up the first error message. (In general, the fallback to the\n // allowance target is opportunistic. We ignore the specific error\n // message if it fails.)\n LibSpenderRichErrors.SpenderERC20TransferFromFailedError(\n address(token),\n owner,\n to,\n amount,\n initialRevertData.length != 0 ? initialRevertData : revertData\n ).rrevert();\n }\n }\n}\n",
"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./IERC20TokenV06.sol\";\n\n\ninterface IEtherTokenV06 is\n IERC20TokenV06\n{\n /// @dev Wrap ether.\n function deposit() external payable;\n\n /// @dev Unwrap ether.\n function withdraw(uint256 amount) external;\n}\n",
"../external/FeeCollector.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n/// @dev The collector contract for protocol fees\ncontract FeeCollector is AuthorizableV06 {\n /// @dev Allow ether transfers to the collector.\n receive() external payable { }\n\n constructor() public {\n _addAuthorizedAddress(msg.sender);\n }\n\n /// @dev Approve the staking contract and join a pool. Only an authority\n /// can call this.\n /// @param weth The WETH contract.\n /// @param staking The staking contract.\n /// @param poolId The pool ID this contract is collecting fees for.\n function initialize(\n IEtherTokenV06 weth,\n IStaking staking,\n bytes32 poolId\n )\n external\n onlyAuthorized\n {\n weth.approve(address(staking), type(uint256).max);\n staking.joinStakingPoolAsMaker(poolId);\n }\n\n /// @dev Convert all held ether to WETH. Only an authority can call this.\n /// @param weth The WETH contract.\n function convertToWeth(\n IEtherTokenV06 weth\n )\n external\n onlyAuthorized\n {\n if (address(this).balance > 0) {\n weth.deposit{value: address(this).balance}();\n }\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./interfaces/IAuthorizableV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibAuthorizableRichErrorsV06.sol\";\nimport \"./OwnableV06.sol\";\n\n\n// solhint-disable no-empty-blocks\ncontract AuthorizableV06 is\n OwnableV06,\n IAuthorizableV06\n{\n /// @dev Only authorized addresses can invoke functions with this modifier.\n modifier onlyAuthorized {\n _assertSenderIsAuthorized();\n _;\n }\n\n // @dev Whether an address is authorized to call privileged functions.\n // @param 0 Address to query.\n // @return 0 Whether the address is authorized.\n mapping (address => bool) public override authorized;\n // @dev Whether an address is authorized to call privileged functions.\n // @param 0 Index of authorized address.\n // @return 0 Authorized address.\n address[] public override authorities;\n\n /// @dev Initializes the `owner` address.\n constructor()\n public\n OwnableV06()\n {}\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function addAuthorizedAddress(address target)\n external\n override\n onlyOwner\n {\n _addAuthorizedAddress(target);\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n function removeAuthorizedAddress(address target)\n external\n override\n onlyOwner\n {\n if (!authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));\n }\n for (uint256 i = 0; i < authorities.length; i++) {\n if (authorities[i] == target) {\n _removeAuthorizedAddressAtIndex(target, i);\n break;\n }\n }\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n external\n override\n onlyOwner\n {\n _removeAuthorizedAddressAtIndex(target, index);\n }\n\n /// @dev Gets all authorized addresses.\n /// @return Array of authorized addresses.\n function getAuthorizedAddresses()\n external\n override\n view\n returns (address[] memory)\n {\n return authorities;\n }\n\n /// @dev Reverts if msg.sender is not authorized.\n function _assertSenderIsAuthorized()\n internal\n view\n {\n if (!authorized[msg.sender]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.SenderNotAuthorizedError(msg.sender));\n }\n }\n\n /// @dev Authorizes an address.\n /// @param target Address to authorize.\n function _addAuthorizedAddress(address target)\n internal\n {\n // Ensure that the target is not the zero address.\n if (target == address(0)) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.ZeroCantBeAuthorizedError());\n }\n\n // Ensure that the target is not already authorized.\n if (authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetAlreadyAuthorizedError(target));\n }\n\n authorized[target] = true;\n authorities.push(target);\n emit AuthorizedAddressAdded(target, msg.sender);\n }\n\n /// @dev Removes authorizion of an address.\n /// @param target Address to remove authorization from.\n /// @param index Index of target in authorities array.\n function _removeAuthorizedAddressAtIndex(\n address target,\n uint256 index\n )\n internal\n {\n if (!authorized[target]) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));\n }\n if (index >= authorities.length) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.IndexOutOfBoundsError(\n index,\n authorities.length\n ));\n }\n if (authorities[index] != target) {\n LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.AuthorizedAddressMismatchError(\n authorities[index],\n target\n ));\n }\n\n delete authorized[target];\n authorities[index] = authorities[authorities.length - 1];\n authorities.pop();\n emit AuthorizedAddressRemoved(target, msg.sender);\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibAuthorizableRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibAuthorizableRichErrorsV06 {\n\n // bytes4(keccak256(\"AuthorizedAddressMismatchError(address,address)\"))\n bytes4 internal constant AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR =\n 0x140a84db;\n\n // bytes4(keccak256(\"IndexOutOfBoundsError(uint256,uint256)\"))\n bytes4 internal constant INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR =\n 0xe9f83771;\n\n // bytes4(keccak256(\"SenderNotAuthorizedError(address)\"))\n bytes4 internal constant SENDER_NOT_AUTHORIZED_ERROR_SELECTOR =\n 0xb65a25b9;\n\n // bytes4(keccak256(\"TargetAlreadyAuthorizedError(address)\"))\n bytes4 internal constant TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR =\n 0xde16f1a0;\n\n // bytes4(keccak256(\"TargetNotAuthorizedError(address)\"))\n bytes4 internal constant TARGET_NOT_AUTHORIZED_ERROR_SELECTOR =\n 0xeb5108a2;\n\n // bytes4(keccak256(\"ZeroCantBeAuthorizedError()\"))\n bytes internal constant ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES =\n hex\"57654fe4\";\n\n // solhint-disable func-name-mixedcase\n function AuthorizedAddressMismatchError(\n address authorized,\n address target\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR,\n authorized,\n target\n );\n }\n\n function IndexOutOfBoundsError(\n uint256 index,\n uint256 length\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR,\n index,\n length\n );\n }\n\n function SenderNotAuthorizedError(address sender)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n SENDER_NOT_AUTHORIZED_ERROR_SELECTOR,\n sender\n );\n }\n\n function TargetAlreadyAuthorizedError(address target)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR,\n target\n );\n }\n\n function TargetNotAuthorizedError(address target)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n TARGET_NOT_AUTHORIZED_ERROR_SELECTOR,\n target\n );\n }\n\n function ZeroCantBeAuthorizedError()\n internal\n pure\n returns (bytes memory)\n {\n return ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES;\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/OwnableV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2019 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./interfaces/IOwnableV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibOwnableRichErrorsV06.sol\";\n\n\ncontract OwnableV06 is\n IOwnableV06\n{\n /// @dev The owner of this contract.\n /// @return 0 The owner address.\n address public override owner;\n\n constructor() public {\n owner = msg.sender;\n }\n\n modifier onlyOwner() {\n _assertSenderIsOwner();\n _;\n }\n\n /// @dev Change the owner of this contract.\n /// @param newOwner New owner address.\n function transferOwnership(address newOwner)\n public\n override\n onlyOwner\n {\n if (newOwner == address(0)) {\n LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.TransferOwnerToZeroError());\n } else {\n owner = newOwner;\n emit OwnershipTransferred(msg.sender, newOwner);\n }\n }\n\n function _assertSenderIsOwner()\n internal\n view\n {\n if (msg.sender != owner) {\n LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.OnlyOwnerError(\n msg.sender,\n owner\n ));\n }\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibOwnableRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\npragma solidity ^0.6.5;\n\n\nlibrary LibOwnableRichErrorsV06 {\n\n // bytes4(keccak256(\"OnlyOwnerError(address,address)\"))\n bytes4 internal constant ONLY_OWNER_ERROR_SELECTOR =\n 0x1de45ad1;\n\n // bytes4(keccak256(\"TransferOwnerToZeroError()\"))\n bytes internal constant TRANSFER_OWNER_TO_ZERO_ERROR_BYTES =\n hex\"e69edc3e\";\n\n // solhint-disable func-name-mixedcase\n function OnlyOwnerError(\n address sender,\n address owner\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n ONLY_OWNER_ERROR_SELECTOR,\n sender,\n owner\n );\n }\n\n function TransferOwnerToZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return TRANSFER_OWNER_TO_ZERO_ERROR_BYTES;\n }\n}\n",
"../vendor/v3/IStaking.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\ninterface IStaking {\n function joinStakingPoolAsMaker(bytes32) external;\n function payProtocolFee(address, address, uint256) external payable;\n}\n",
"../external/IFlashWallet.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol\";\n\n\n/// @dev A contract that can execute arbitrary calls from its owner.\ninterface IFlashWallet {\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @param value Ether to attach to the call.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData,\n uint256 value\n )\n external\n payable\n returns (bytes memory resultData);\n\n /// @dev Execute an arbitrary delegatecall, in the context of this puppet.\n /// Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeDelegateCall(\n address payable target,\n bytes calldata callData\n )\n external\n payable\n returns (bytes memory resultData);\n\n /// @dev Allows the puppet to receive ETH.\n receive() external payable;\n\n /// @dev Fetch the immutable owner/deployer of this contract.\n /// @return owner_ The immutable owner/deployer/\n function owner() external view returns (address owner_);\n}\n",
"../external/FlashWallet.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibOwnableRichErrorsV06.sol\";\nimport \"../errors/LibWalletRichErrors.sol\";\nimport \"./IFlashWallet.sol\";\n\n\n/// @dev A contract that can execute arbitrary calls from its owner.\ncontract FlashWallet is\n IFlashWallet\n{\n // solhint-disable no-unused-vars,indent,no-empty-blocks\n using LibRichErrorsV06 for bytes;\n\n // solhint-disable\n /// @dev Store the owner/deployer as an immutable to make this contract stateless.\n address public override immutable owner;\n // solhint-enable\n\n constructor() public {\n // The deployer is the owner.\n owner = msg.sender;\n }\n\n /// @dev Allows only the (immutable) owner to call a function.\n modifier onlyOwner() virtual {\n if (msg.sender != owner) {\n LibOwnableRichErrorsV06.OnlyOwnerError(\n msg.sender,\n owner\n ).rrevert();\n }\n _;\n }\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @param value Ether to attach to the call.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData,\n uint256 value\n )\n external\n payable\n override\n onlyOwner\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.call{value: value}(callData);\n if (!success) {\n LibWalletRichErrors\n .WalletExecuteCallFailedError(\n address(this),\n target,\n callData,\n value,\n resultData\n )\n .rrevert();\n }\n }\n\n /// @dev Execute an arbitrary delegatecall, in the context of this puppet.\n /// Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeDelegateCall(\n address payable target,\n bytes calldata callData\n )\n external\n payable\n override\n onlyOwner\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.delegatecall(callData);\n if (!success) {\n LibWalletRichErrors\n .WalletExecuteDelegateCallFailedError(\n address(this),\n target,\n callData,\n resultData\n )\n .rrevert();\n }\n }\n\n // solhint-disable\n /// @dev Allows this contract to receive ether.\n receive() external override payable {}\n // solhint-enable\n\n /// @dev Signal support for receiving ERC1155 tokens.\n /// @param interfaceID The interface ID, as per ERC-165 rules.\n /// @return hasSupport `true` if this contract supports an ERC-165 interface.\n function supportsInterface(bytes4 interfaceID)\n external\n pure\n returns (bool hasSupport)\n {\n return interfaceID == this.supportsInterface.selector ||\n interfaceID == this.onERC1155Received.selector ^ this.onERC1155BatchReceived.selector ||\n interfaceID == this.tokenFallback.selector;\n }\n\n /// @dev Allow this contract to receive ERC1155 tokens.\n /// @return success `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n function onERC1155Received(\n address, // operator,\n address, // from,\n uint256, // id,\n uint256, // value,\n bytes calldata //data\n )\n external\n pure\n returns (bytes4 success)\n {\n return this.onERC1155Received.selector;\n }\n\n /// @dev Allow this contract to receive ERC1155 tokens.\n /// @return success `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n function onERC1155BatchReceived(\n address, // operator,\n address, // from,\n uint256[] calldata, // ids,\n uint256[] calldata, // values,\n bytes calldata // data\n )\n external\n pure\n returns (bytes4 success)\n {\n return this.onERC1155BatchReceived.selector;\n }\n\n /// @dev Allows this contract to receive ERC223 tokens.\n function tokenFallback(\n address, // from,\n uint256, // value,\n bytes calldata // value\n )\n external\n pure\n {}\n}\n",
"../errors/LibWalletRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibWalletRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function WalletExecuteCallFailedError(\n address wallet,\n address callTarget,\n bytes memory callData,\n uint256 callValue,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"WalletExecuteCallFailedError(address,address,bytes,uint256,bytes)\")),\n wallet,\n callTarget,\n callData,\n callValue,\n errorData\n );\n }\n\n function WalletExecuteDelegateCallFailedError(\n address wallet,\n address callTarget,\n bytes memory callData,\n bytes memory errorData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"WalletExecuteDelegateCallFailedError(address,address,bytes,bytes)\")),\n wallet,\n callTarget,\n callData,\n errorData\n );\n }\n}\n",
"../storage/LibTransformERC20Storage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IFlashWallet.sol\";\n\n\n/// @dev Storage helpers for the `TransformERC20` feature.\nlibrary LibTransformERC20Storage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The current wallet instance.\n IFlashWallet wallet;\n // The transformer deployer address.\n address transformerDeployer;\n // The optional signer for `transformERC20()` calldata.\n address quoteSigner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.TransformERC20\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../transformers/IERC20Transformer.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\n\n\n/// @dev A transformation callback used in `TransformERC20.transformERC20()`.\ninterface IERC20Transformer {\n\n /// @dev Context information to pass into `transform()` by `TransformERC20.transformERC20()`.\n struct TransformContext {\n // The caller of `TransformERC20.transformERC20()`.\n address payable sender;\n // taker The taker address, which may be distinct from `sender` in the case\n // meta-transactions.\n address payable taker;\n // Arbitrary data to pass to the transformer.\n bytes data;\n }\n\n /// @dev Called from `TransformERC20.transformERC20()`. This will be\n /// delegatecalled in the context of the FlashWallet instance being used.\n /// @param context Context information.\n /// @return success The success bytes (`LibERC20Transformer.TRANSFORMER_SUCCESS`).\n function transform(TransformContext calldata context)\n external\n returns (bytes4 success);\n}\n",
"../transformers/LibERC20Transformer.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol\";\n\n\nlibrary LibERC20Transformer {\n\n using LibERC20TokenV06 for IERC20TokenV06;\n\n /// @dev ETH pseudo-token address.\n address constant internal ETH_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n /// @dev ETH pseudo-token.\n IERC20TokenV06 constant internal ETH_TOKEN = IERC20TokenV06(ETH_TOKEN_ADDRESS);\n /// @dev Return value indicating success in `IERC20Transformer.transform()`.\n /// This is just `keccak256('TRANSFORMER_SUCCESS')`.\n bytes4 constant internal TRANSFORMER_SUCCESS = 0x13c9929e;\n\n /// @dev Transfer ERC20 tokens and ETH.\n /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`).\n /// @param to The recipient.\n /// @param amount The transfer amount.\n function transformerTransfer(\n IERC20TokenV06 token,\n address payable to,\n uint256 amount\n )\n internal\n {\n if (isTokenETH(token)) {\n to.transfer(amount);\n } else {\n token.compatTransfer(to, amount);\n }\n }\n\n /// @dev Check if a token is the ETH pseudo-token.\n /// @param token The token to check.\n /// @return isETH `true` if the token is the ETH pseudo-token.\n function isTokenETH(IERC20TokenV06 token)\n internal\n pure\n returns (bool isETH)\n {\n return address(token) == ETH_TOKEN_ADDRESS;\n }\n\n /// @dev Check the balance of an ERC20 token or ETH.\n /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`).\n /// @param owner Holder of the tokens.\n /// @return tokenBalance The balance of `owner`.\n function getTokenBalanceOf(IERC20TokenV06 token, address owner)\n internal\n view\n returns (uint256 tokenBalance)\n {\n if (isTokenETH(token)) {\n return owner.balance;\n }\n return token.balanceOf(owner);\n }\n\n /// @dev RLP-encode a 32-bit or less account nonce.\n /// @param nonce A positive integer in the range 0 <= nonce < 2^32.\n /// @return rlpNonce The RLP encoding.\n function rlpEncodeNonce(uint32 nonce)\n internal\n pure\n returns (bytes memory rlpNonce)\n {\n // See https://github.com/ethereum/wiki/wiki/RLP for RLP encoding rules.\n if (nonce == 0) {\n rlpNonce = new bytes(1);\n rlpNonce[0] = 0x80;\n } else if (nonce < 0x80) {\n rlpNonce = new bytes(1);\n rlpNonce[0] = byte(uint8(nonce));\n } else if (nonce <= 0xFF) {\n rlpNonce = new bytes(2);\n rlpNonce[0] = 0x81;\n rlpNonce[1] = byte(uint8(nonce));\n } else if (nonce <= 0xFFFF) {\n rlpNonce = new bytes(3);\n rlpNonce[0] = 0x82;\n rlpNonce[1] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[2] = byte(uint8(nonce));\n } else if (nonce <= 0xFFFFFF) {\n rlpNonce = new bytes(4);\n rlpNonce[0] = 0x83;\n rlpNonce[1] = byte(uint8((nonce & 0xFF0000) >> 16));\n rlpNonce[2] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[3] = byte(uint8(nonce));\n } else {\n rlpNonce = new bytes(5);\n rlpNonce[0] = 0x84;\n rlpNonce[1] = byte(uint8((nonce & 0xFF000000) >> 24));\n rlpNonce[2] = byte(uint8((nonce & 0xFF0000) >> 16));\n rlpNonce[3] = byte(uint8((nonce & 0xFF00) >> 8));\n rlpNonce[4] = byte(uint8(nonce));\n }\n }\n\n /// @dev Compute the expected deployment address by `deployer` at\n /// the nonce given by `deploymentNonce`.\n /// @param deployer The address of the deployer.\n /// @param deploymentNonce The nonce that the deployer had when deploying\n /// a contract.\n /// @return deploymentAddress The deployment address.\n function getDeployedAddress(address deployer, uint32 deploymentNonce)\n internal\n pure\n returns (address payable deploymentAddress)\n {\n // The address of if a deployed contract is the lower 20 bytes of the\n // hash of the RLP-encoded deployer's account address + account nonce.\n // See: https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed\n bytes memory rlpNonce = rlpEncodeNonce(deploymentNonce);\n return address(uint160(uint256(keccak256(abi.encodePacked(\n byte(uint8(0xC0 + 21 + rlpNonce.length)),\n byte(uint8(0x80 + 20)),\n deployer,\n rlpNonce\n )))));\n }\n}\n",
"../features/interfaces/ITransformERC20Feature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../../transformers/IERC20Transformer.sol\";\nimport \"../../external/IFlashWallet.sol\";\n\n\n/// @dev Feature to composably transform between ERC20 tokens.\ninterface ITransformERC20Feature {\n\n /// @dev Defines a transformation to run in `transformERC20()`.\n struct Transformation {\n // The deployment nonce for the transformer.\n // The address of the transformer contract will be derived from this\n // value.\n uint32 deploymentNonce;\n // Arbitrary data to pass to the transformer.\n bytes data;\n }\n\n /// @dev Arguments for `_transformERC20()`.\n struct TransformERC20Args {\n // The taker address.\n address payable taker;\n // The token being provided by the taker.\n // If `0xeee...`, ETH is implied and should be provided with the call.`\n IERC20TokenV06 inputToken;\n // The token to be acquired by the taker.\n // `0xeee...` implies ETH.\n IERC20TokenV06 outputToken;\n // The amount of `inputToken` to take from the taker.\n // If set to `uint256(-1)`, the entire spendable balance of the taker\n // will be solt.\n uint256 inputTokenAmount;\n // The minimum amount of `outputToken` the taker\n // must receive for the entire transformation to succeed. If set to zero,\n // the minimum output token transfer will not be asserted.\n uint256 minOutputTokenAmount;\n // The transformations to execute on the token balance(s)\n // in sequence.\n Transformation[] transformations;\n }\n\n /// @dev Raised upon a successful `transformERC20`.\n /// @param taker The taker (caller) address.\n /// @param inputToken The token being provided by the taker.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the taker.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the taker.\n /// @param outputTokenAmount The amount of `outputToken` received by the taker.\n event TransformedERC20(\n address indexed taker,\n address inputToken,\n address outputToken,\n uint256 inputTokenAmount,\n uint256 outputTokenAmount\n );\n\n /// @dev Raised when `setTransformerDeployer()` is called.\n /// @param transformerDeployer The new deployer address.\n event TransformerDeployerUpdated(address transformerDeployer);\n\n /// @dev Raised when `setQuoteSigner()` is called.\n /// @param quoteSigner The new quote signer.\n event QuoteSignerUpdated(address quoteSigner);\n\n /// @dev Replace the allowed deployer for transformers.\n /// Only callable by the owner.\n /// @param transformerDeployer The address of the new trusted deployer\n /// for transformers.\n function setTransformerDeployer(address transformerDeployer)\n external;\n\n /// @dev Replace the optional signer for `transformERC20()` calldata.\n /// Only callable by the owner.\n /// @param quoteSigner The address of the new calldata signer.\n function setQuoteSigner(address quoteSigner)\n external;\n\n /// @dev Deploy a new flash wallet instance and replace the current one with it.\n /// Useful if we somehow break the current wallet instance.\n /// Only callable by the owner.\n /// @return wallet The new wallet instance.\n function createTransformWallet()\n external\n returns (IFlashWallet wallet);\n\n /// @dev Executes a series of transformations to convert an ERC20 `inputToken`\n /// to an ERC20 `outputToken`.\n /// @param inputToken The token being provided by the sender.\n /// If `0xeee...`, ETH is implied and should be provided with the call.`\n /// @param outputToken The token to be acquired by the sender.\n /// `0xeee...` implies ETH.\n /// @param inputTokenAmount The amount of `inputToken` to take from the sender.\n /// @param minOutputTokenAmount The minimum amount of `outputToken` the sender\n /// must receive for the entire transformation to succeed.\n /// @param transformations The transformations to execute on the token balance(s)\n /// in sequence.\n /// @return outputTokenAmount The amount of `outputToken` received by the sender.\n function transformERC20(\n IERC20TokenV06 inputToken,\n IERC20TokenV06 outputToken,\n uint256 inputTokenAmount,\n uint256 minOutputTokenAmount,\n Transformation[] calldata transformations\n )\n external\n payable\n returns (uint256 outputTokenAmount);\n\n /// @dev Internal version of `transformERC20()`. Only callable from within.\n /// @param args A `TransformERC20Args` struct.\n /// @return outputTokenAmount The amount of `outputToken` received by the taker.\n function _transformERC20(TransformERC20Args calldata args)\n external\n payable\n returns (uint256 outputTokenAmount);\n\n /// @dev Return the current wallet instance that will serve as the execution\n /// context for transformations.\n /// @return wallet The wallet instance.\n function getTransformWallet()\n external\n view\n returns (IFlashWallet wallet);\n\n /// @dev Return the allowed deployer for transformers.\n /// @return deployer The transform deployer address.\n function getTransformerDeployer()\n external\n view\n returns (address deployer);\n\n /// @dev Return the optional signer for `transformERC20()` calldata.\n /// @return signer The transform deployer address.\n function getQuoteSigner()\n external\n view\n returns (address signer);\n}\n",
"../features/MetaTransactionsFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../errors/LibMetaTransactionsRichErrors.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../fixins/FixinReentrancyGuard.sol\";\nimport \"../fixins/FixinTokenSpender.sol\";\nimport \"../fixins/FixinEIP712.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"../storage/LibMetaTransactionsStorage.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/IMetaTransactionsFeature.sol\";\nimport \"./interfaces/INativeOrdersFeature.sol\";\nimport \"./interfaces/ITransformERC20Feature.sol\";\nimport \"./libs/LibSignature.sol\";\n\n/// @dev MetaTransactions feature.\ncontract MetaTransactionsFeature is\n IFeature,\n IMetaTransactionsFeature,\n FixinCommon,\n FixinReentrancyGuard,\n FixinEIP712,\n FixinTokenSpender\n{\n using LibBytesV06 for bytes;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Describes the state of a meta transaction.\n struct ExecuteState {\n // Sender of the meta-transaction.\n address sender;\n // Hash of the meta-transaction data.\n bytes32 hash;\n // The meta-transaction data.\n MetaTransactionData mtx;\n // The meta-transaction signature (by `mtx.signer`).\n LibSignature.Signature signature;\n // The selector of the function being called.\n bytes4 selector;\n // The ETH balance of this contract before performing the call.\n uint256 selfBalance;\n // The block number at which the meta-transaction was executed.\n uint256 executedBlockNumber;\n }\n\n /// @dev Arguments for a `TransformERC20.transformERC20()` call.\n struct ExternalTransformERC20Args {\n IERC20TokenV06 inputToken;\n IERC20TokenV06 outputToken;\n uint256 inputTokenAmount;\n uint256 minOutputTokenAmount;\n ITransformERC20Feature.Transformation[] transformations;\n }\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"MetaTransactions\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 1, 0);\n /// @dev EIP712 typehash of the `MetaTransactionData` struct.\n bytes32 public immutable MTX_EIP712_TYPEHASH = keccak256(\n \"MetaTransactionData(\"\n \"address signer,\"\n \"address sender,\"\n \"uint256 minGasPrice,\"\n \"uint256 maxGasPrice,\"\n \"uint256 expirationTimeSeconds,\"\n \"uint256 salt,\"\n \"bytes callData,\"\n \"uint256 value,\"\n \"address feeToken,\"\n \"uint256 feeAmount\"\n \")\"\n );\n\n /// @dev Refunds up to `msg.value` leftover ETH at the end of the call.\n modifier refundsAttachedEth() {\n _;\n uint256 remainingBalance =\n LibSafeMathV06.min256(msg.value, address(this).balance);\n if (remainingBalance > 0) {\n msg.sender.transfer(remainingBalance);\n }\n }\n\n constructor(address zeroExAddress, bytes32 greedyTokensBloomFilter)\n public\n FixinCommon()\n FixinEIP712(zeroExAddress)\n FixinTokenSpender(greedyTokensBloomFilter)\n {\n // solhint-disable-next-line no-empty-blocks\n }\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate()\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.executeMetaTransaction.selector);\n _registerFeatureFunction(this.batchExecuteMetaTransactions.selector);\n _registerFeatureFunction(this.getMetaTransactionExecutedBlock.selector);\n _registerFeatureFunction(this.getMetaTransactionHashExecutedBlock.selector);\n _registerFeatureFunction(this.getMetaTransactionHash.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n\n /// @dev Execute a single meta-transaction.\n /// @param mtx The meta-transaction.\n /// @param signature The signature by `mtx.signer`.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function executeMetaTransaction(\n MetaTransactionData memory mtx,\n LibSignature.Signature memory signature\n )\n public\n payable\n override\n nonReentrant(REENTRANCY_MTX)\n refundsAttachedEth\n returns (bytes memory returnResult)\n {\n ExecuteState memory state;\n state.sender = msg.sender;\n state.mtx = mtx;\n state.hash = getMetaTransactionHash(mtx);\n state.signature = signature;\n\n returnResult = _executeMetaTransactionPrivate(state);\n }\n\n /// @dev Execute multiple meta-transactions.\n /// @param mtxs The meta-transactions.\n /// @param signatures The signature by each respective `mtx.signer`.\n /// @return returnResults The ABI-encoded results of the underlying calls.\n function batchExecuteMetaTransactions(\n MetaTransactionData[] memory mtxs,\n LibSignature.Signature[] memory signatures\n )\n public\n payable\n override\n nonReentrant(REENTRANCY_MTX)\n refundsAttachedEth\n returns (bytes[] memory returnResults)\n {\n if (mtxs.length != signatures.length) {\n LibMetaTransactionsRichErrors.InvalidMetaTransactionsArrayLengthsError(\n mtxs.length,\n signatures.length\n ).rrevert();\n }\n returnResults = new bytes[](mtxs.length);\n for (uint256 i = 0; i < mtxs.length; ++i) {\n ExecuteState memory state;\n state.sender = msg.sender;\n state.mtx = mtxs[i];\n state.hash = getMetaTransactionHash(mtxs[i]);\n state.signature = signatures[i];\n\n returnResults[i] = _executeMetaTransactionPrivate(state);\n }\n }\n\n /// @dev Get the block at which a meta-transaction has been executed.\n /// @param mtx The meta-transaction.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionExecutedBlock(MetaTransactionData memory mtx)\n public\n override\n view\n returns (uint256 blockNumber)\n {\n return getMetaTransactionHashExecutedBlock(getMetaTransactionHash(mtx));\n }\n\n /// @dev Get the block at which a meta-transaction hash has been executed.\n /// @param mtxHash The meta-transaction hash.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionHashExecutedBlock(bytes32 mtxHash)\n public\n override\n view\n returns (uint256 blockNumber)\n {\n return LibMetaTransactionsStorage.getStorage().mtxHashToExecutedBlockNumber[mtxHash];\n }\n\n /// @dev Get the EIP712 hash of a meta-transaction.\n /// @param mtx The meta-transaction.\n /// @return mtxHash The EIP712 hash of `mtx`.\n function getMetaTransactionHash(MetaTransactionData memory mtx)\n public\n override\n view\n returns (bytes32 mtxHash)\n {\n return _getEIP712Hash(keccak256(abi.encode(\n MTX_EIP712_TYPEHASH,\n mtx.signer,\n mtx.sender,\n mtx.minGasPrice,\n mtx.maxGasPrice,\n mtx.expirationTimeSeconds,\n mtx.salt,\n keccak256(mtx.callData),\n mtx.value,\n mtx.feeToken,\n mtx.feeAmount\n )));\n }\n\n /// @dev Execute a meta-transaction by `sender`. Low-level, hidden variant.\n /// @param state The `ExecuteState` for this metatransaction, with `sender`,\n /// `hash`, `mtx`, and `signature` fields filled.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function _executeMetaTransactionPrivate(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n _validateMetaTransaction(state);\n\n // Mark the transaction executed by storing the block at which it was executed.\n // Currently the block number just indicates that the mtx was executed and\n // serves no other purpose from within this contract.\n LibMetaTransactionsStorage.getStorage()\n .mtxHashToExecutedBlockNumber[state.hash] = block.number;\n\n // Pay the fee to the sender.\n if (state.mtx.feeAmount > 0) {\n _transferERC20Tokens(\n state.mtx.feeToken,\n state.mtx.signer,\n state.sender,\n state.mtx.feeAmount\n );\n }\n\n // Execute the call based on the selector.\n state.selector = state.mtx.callData.readBytes4(0);\n if (state.selector == ITransformERC20Feature.transformERC20.selector) {\n returnResult = _executeTransformERC20Call(state);\n } else if (state.selector == INativeOrdersFeature.fillLimitOrder.selector) {\n returnResult = _executeFillLimitOrderCall(state);\n } else if (state.selector == INativeOrdersFeature.fillRfqOrder.selector) {\n returnResult = _executeFillRfqOrderCall(state);\n } else {\n LibMetaTransactionsRichErrors\n .MetaTransactionUnsupportedFunctionError(state.hash, state.selector)\n .rrevert();\n }\n emit MetaTransactionExecuted(\n state.hash,\n state.selector,\n state.mtx.signer,\n state.mtx.sender\n );\n }\n\n /// @dev Validate that a meta-transaction is executable.\n function _validateMetaTransaction(ExecuteState memory state)\n private\n view\n {\n // Must be from the required sender, if set.\n if (state.mtx.sender != address(0) && state.mtx.sender != state.sender) {\n LibMetaTransactionsRichErrors\n .MetaTransactionWrongSenderError(\n state.hash,\n state.sender,\n state.mtx.sender\n ).rrevert();\n }\n // Must not be expired.\n if (state.mtx.expirationTimeSeconds <= block.timestamp) {\n LibMetaTransactionsRichErrors\n .MetaTransactionExpiredError(\n state.hash,\n block.timestamp,\n state.mtx.expirationTimeSeconds\n ).rrevert();\n }\n // Must have a valid gas price.\n if (state.mtx.minGasPrice > tx.gasprice || state.mtx.maxGasPrice < tx.gasprice) {\n LibMetaTransactionsRichErrors\n .MetaTransactionGasPriceError(\n state.hash,\n tx.gasprice,\n state.mtx.minGasPrice,\n state.mtx.maxGasPrice\n ).rrevert();\n }\n // Must have enough ETH.\n state.selfBalance = address(this).balance;\n if (state.mtx.value > state.selfBalance) {\n LibMetaTransactionsRichErrors\n .MetaTransactionInsufficientEthError(\n state.hash,\n state.selfBalance,\n state.mtx.value\n ).rrevert();\n }\n\n if (LibSignature.getSignerOfHash(state.hash, state.signature) !=\n state.mtx.signer) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.WRONG_SIGNER,\n state.hash,\n state.mtx.signer,\n // TODO: Remove this field from SignatureValidationError\n // when rich reverts are part of the protocol repo.\n \"\"\n ).rrevert();\n }\n // Transaction must not have been already executed.\n state.executedBlockNumber = LibMetaTransactionsStorage\n .getStorage().mtxHashToExecutedBlockNumber[state.hash];\n if (state.executedBlockNumber != 0) {\n LibMetaTransactionsRichErrors\n .MetaTransactionAlreadyExecutedError(\n state.hash,\n state.executedBlockNumber\n ).rrevert();\n }\n }\n\n /// @dev Execute a `ITransformERC20Feature.transformERC20()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `ITransformERC20Feature._transformERC20()` variant, where we can override\n /// the taker address.\n function _executeTransformERC20Call(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n // HACK(dorothy-zbornak): `abi.decode()` with the individual args\n // will cause a stack overflow. But we can prefix the call data with an\n // offset to transform it into the encoding for the equivalent single struct arg,\n // since decoding a single struct arg consumes far less stack space than\n // decoding multiple struct args.\n\n // Where the encoding for multiple args (with the selector ommitted)\n // would typically look like:\n // | argument | offset |\n // |--------------------------|---------|\n // | inputToken | 0 |\n // | outputToken | 32 |\n // | inputTokenAmount | 64 |\n // | minOutputTokenAmount | 96 |\n // | transformations (offset) | 128 | = 32\n // | transformations (data) | 160 |\n\n // We will ABI-decode a single struct arg copy with the layout:\n // | argument | offset |\n // |--------------------------|---------|\n // | (arg 1 offset) | 0 | = 32\n // | inputToken | 32 |\n // | outputToken | 64 |\n // | inputTokenAmount | 96 |\n // | minOutputTokenAmount | 128 |\n // | transformations (offset) | 160 | = 32\n // | transformations (data) | 192 |\n\n ExternalTransformERC20Args memory args;\n {\n bytes memory encodedStructArgs = new bytes(state.mtx.callData.length - 4 + 32);\n // Copy the args data from the original, after the new struct offset prefix.\n bytes memory fromCallData = state.mtx.callData;\n assert(fromCallData.length >= 160);\n uint256 fromMem;\n uint256 toMem;\n assembly {\n // Prefix the calldata with a struct offset,\n // which points to just one word over.\n mstore(add(encodedStructArgs, 32), 32)\n // Copy everything after the selector.\n fromMem := add(fromCallData, 36)\n // Start copying after the struct offset.\n toMem := add(encodedStructArgs, 64)\n }\n LibBytesV06.memCopy(toMem, fromMem, fromCallData.length - 4);\n // Decode call args for `ITransformERC20Feature.transformERC20()` as a struct.\n args = abi.decode(encodedStructArgs, (ExternalTransformERC20Args));\n }\n // Call `ITransformERC20Feature._transformERC20()` (internal variant).\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n ITransformERC20Feature._transformERC20.selector,\n ITransformERC20Feature.TransformERC20Args({\n taker: state.mtx.signer, // taker is mtx signer\n inputToken: args.inputToken,\n outputToken: args.outputToken,\n inputTokenAmount: args.inputTokenAmount,\n minOutputTokenAmount: args.minOutputTokenAmount,\n transformations: args.transformations\n })\n ),\n state.mtx.value\n );\n }\n\n /// @dev Extract arguments from call data by copying everything after the\n /// 4-byte selector into a new byte array.\n /// @param callData The call data from which arguments are to be extracted.\n /// @return args The extracted arguments as a byte array.\n function _extractArgumentsFromCallData(\n bytes memory callData\n )\n private\n pure\n returns (bytes memory args)\n {\n args = new bytes(callData.length - 4);\n uint256 fromMem;\n uint256 toMem;\n\n assembly {\n fromMem := add(callData, 36) // skip length and 4-byte selector\n toMem := add(args, 32) // write after length prefix\n }\n\n LibBytesV06.memCopy(toMem, fromMem, args.length);\n\n return args;\n }\n\n /// @dev Execute a `INativeOrdersFeature.fillLimitOrder()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `INativeOrdersFeature._fillLimitOrder()` variant, where we can override\n /// the taker address.\n function _executeFillLimitOrderCall(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n LibNativeOrder.LimitOrder memory order;\n LibSignature.Signature memory signature;\n uint128 takerTokenFillAmount;\n\n bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);\n (order, signature, takerTokenFillAmount) = abi.decode(args, (LibNativeOrder.LimitOrder, LibSignature.Signature, uint128));\n\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n INativeOrdersFeature._fillLimitOrder.selector,\n order,\n signature,\n takerTokenFillAmount,\n state.mtx.signer, // taker is mtx signer\n msg.sender\n ),\n state.mtx.value\n );\n }\n\n /// @dev Execute a `INativeOrdersFeature.fillRfqOrder()` meta-transaction call\n /// by decoding the call args and translating the call to the internal\n /// `INativeOrdersFeature._fillRfqOrder()` variant, where we can overrideunimpleme\n /// the taker address.\n function _executeFillRfqOrderCall(ExecuteState memory state)\n private\n returns (bytes memory returnResult)\n {\n LibNativeOrder.RfqOrder memory order;\n LibSignature.Signature memory signature;\n uint128 takerTokenFillAmount;\n\n bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);\n (order, signature, takerTokenFillAmount) = abi.decode(args, (LibNativeOrder.RfqOrder, LibSignature.Signature, uint128));\n\n return _callSelf(\n state.hash,\n abi.encodeWithSelector(\n INativeOrdersFeature._fillRfqOrder.selector,\n order,\n signature,\n takerTokenFillAmount,\n state.mtx.signer // taker is mtx signer\n ),\n state.mtx.value\n );\n }\n\n /// @dev Make an arbitrary internal, meta-transaction call.\n /// Warning: Do not let unadulterated `callData` into this function.\n function _callSelf(bytes32 hash, bytes memory callData, uint256 value)\n private\n returns (bytes memory returnResult)\n {\n bool success;\n (success, returnResult) = address(this).call{value: value}(callData);\n if (!success) {\n LibMetaTransactionsRichErrors.MetaTransactionCallFailedError(\n hash,\n callData,\n returnResult\n ).rrevert();\n }\n }\n}\n",
"../errors/LibMetaTransactionsRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibMetaTransactionsRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function InvalidMetaTransactionsArrayLengthsError(\n uint256 mtxCount,\n uint256 signatureCount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"InvalidMetaTransactionsArrayLengthsError(uint256,uint256)\")),\n mtxCount,\n signatureCount\n );\n }\n\n function MetaTransactionUnsupportedFunctionError(\n bytes32 mtxHash,\n bytes4 selector\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionUnsupportedFunctionError(bytes32,bytes4)\")),\n mtxHash,\n selector\n );\n }\n\n function MetaTransactionWrongSenderError(\n bytes32 mtxHash,\n address sender,\n address expectedSender\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionWrongSenderError(bytes32,address,address)\")),\n mtxHash,\n sender,\n expectedSender\n );\n }\n\n function MetaTransactionExpiredError(\n bytes32 mtxHash,\n uint256 time,\n uint256 expirationTime\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionExpiredError(bytes32,uint256,uint256)\")),\n mtxHash,\n time,\n expirationTime\n );\n }\n\n function MetaTransactionGasPriceError(\n bytes32 mtxHash,\n uint256 gasPrice,\n uint256 minGasPrice,\n uint256 maxGasPrice\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionGasPriceError(bytes32,uint256,uint256,uint256)\")),\n mtxHash,\n gasPrice,\n minGasPrice,\n maxGasPrice\n );\n }\n\n function MetaTransactionInsufficientEthError(\n bytes32 mtxHash,\n uint256 ethBalance,\n uint256 ethRequired\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionInsufficientEthError(bytes32,uint256,uint256)\")),\n mtxHash,\n ethBalance,\n ethRequired\n );\n }\n\n function MetaTransactionInvalidSignatureError(\n bytes32 mtxHash,\n bytes memory signature,\n bytes memory errData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionInvalidSignatureError(bytes32,bytes,bytes)\")),\n mtxHash,\n signature,\n errData\n );\n }\n\n function MetaTransactionAlreadyExecutedError(\n bytes32 mtxHash,\n uint256 executedBlockNumber\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionAlreadyExecutedError(bytes32,uint256)\")),\n mtxHash,\n executedBlockNumber\n );\n }\n\n function MetaTransactionCallFailedError(\n bytes32 mtxHash,\n bytes memory callData,\n bytes memory returnData\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"MetaTransactionCallFailedError(bytes32,bytes,bytes)\")),\n mtxHash,\n callData,\n returnData\n );\n }\n}\n",
"../fixins/FixinReentrancyGuard.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../storage/LibReentrancyGuardStorage.sol\";\n\n\n/// @dev Common feature utilities.\nabstract contract FixinReentrancyGuard {\n\n using LibRichErrorsV06 for bytes;\n using LibBytesV06 for bytes;\n\n // Combinable reentrancy flags.\n /// @dev Reentrancy guard flag for meta-transaction functions.\n uint256 constant internal REENTRANCY_MTX = 0x1;\n\n /// @dev Cannot reenter a function with the same reentrancy guard flags.\n modifier nonReentrant(uint256 reentrancyFlags) virtual {\n LibReentrancyGuardStorage.Storage storage stor =\n LibReentrancyGuardStorage.getStorage();\n {\n uint256 currentFlags = stor.reentrancyFlags;\n // Revert if any bits in `reentrancyFlags` has already been set.\n if ((currentFlags & reentrancyFlags) != 0) {\n LibCommonRichErrors.IllegalReentrancyError(\n msg.data.readBytes4(0),\n reentrancyFlags\n ).rrevert();\n }\n // Update reentrancy flags.\n stor.reentrancyFlags = currentFlags | reentrancyFlags;\n }\n\n _;\n\n // Clear reentrancy flags.\n stor.reentrancyFlags = stor.reentrancyFlags & (~reentrancyFlags);\n }\n}\n",
"../storage/LibReentrancyGuardStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\nimport \"../external/IFlashWallet.sol\";\n\n\n/// @dev Storage helpers for the `FixinReentrancyGuard` mixin.\nlibrary LibReentrancyGuardStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Reentrancy flags set whenever a non-reentrant function is entered\n // and cleared when it is exited.\n uint256 reentrancyFlags;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.ReentrancyGuard\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../fixins/FixinEIP712.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../errors/LibCommonRichErrors.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\n\n\n/// @dev EIP712 helpers for features.\nabstract contract FixinEIP712 {\n\n /// @dev The domain hash separator for the entire exchange proxy.\n bytes32 public immutable EIP712_DOMAIN_SEPARATOR;\n\n constructor(address zeroExAddress) internal {\n // Compute `EIP712_DOMAIN_SEPARATOR`\n {\n uint256 chainId;\n assembly { chainId := chainid() }\n EIP712_DOMAIN_SEPARATOR = keccak256(\n abi.encode(\n keccak256(\n \"EIP712Domain(\"\n \"string name,\"\n \"string version,\"\n \"uint256 chainId,\"\n \"address verifyingContract\"\n \")\"\n ),\n keccak256(\"ZeroEx\"),\n keccak256(\"1.0.0\"),\n chainId,\n zeroExAddress\n )\n );\n }\n }\n\n function _getEIP712Hash(bytes32 structHash)\n internal\n view\n returns (bytes32 eip712Hash)\n {\n return keccak256(abi.encodePacked(\n hex\"1901\",\n EIP712_DOMAIN_SEPARATOR,\n structHash\n ));\n }\n}\n",
"../storage/LibMetaTransactionsStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `MetaTransactions` feature.\nlibrary LibMetaTransactionsStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The block number when a hash was executed.\n mapping (bytes32 => uint256) mtxHashToExecutedBlockNumber;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.MetaTransactions\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../features/interfaces/IMetaTransactionsFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\n\n/// @dev Meta-transactions feature.\ninterface IMetaTransactionsFeature {\n /// @dev Describes an exchange proxy meta transaction.\n struct MetaTransactionData {\n // Signer of meta-transaction. On whose behalf to execute the MTX.\n address payable signer;\n // Required sender, or NULL for anyone.\n address sender;\n // Minimum gas price.\n uint256 minGasPrice;\n // Maximum gas price.\n uint256 maxGasPrice;\n // MTX is invalid after this time.\n uint256 expirationTimeSeconds;\n // Nonce to make this MTX unique.\n uint256 salt;\n // Encoded call data to a function on the exchange proxy.\n bytes callData;\n // Amount of ETH to attach to the call.\n uint256 value;\n // ERC20 fee `signer` pays `sender`.\n IERC20TokenV06 feeToken;\n // ERC20 fee amount.\n uint256 feeAmount;\n }\n\n /// @dev Emitted whenever a meta-transaction is executed via\n /// `executeMetaTransaction()` or `executeMetaTransactions()`.\n /// @param hash The meta-transaction hash.\n /// @param selector The selector of the function being executed.\n /// @param signer Who to execute the meta-transaction on behalf of.\n /// @param sender Who executed the meta-transaction.\n event MetaTransactionExecuted(\n bytes32 hash,\n bytes4 indexed selector,\n address signer,\n address sender\n );\n\n /// @dev Execute a single meta-transaction.\n /// @param mtx The meta-transaction.\n /// @param signature The signature by `mtx.signer`.\n /// @return returnResult The ABI-encoded result of the underlying call.\n function executeMetaTransaction(\n MetaTransactionData calldata mtx,\n LibSignature.Signature calldata signature\n )\n external\n payable\n returns (bytes memory returnResult);\n\n /// @dev Execute multiple meta-transactions.\n /// @param mtxs The meta-transactions.\n /// @param signatures The signature by each respective `mtx.signer`.\n /// @return returnResults The ABI-encoded results of the underlying calls.\n function batchExecuteMetaTransactions(\n MetaTransactionData[] calldata mtxs,\n LibSignature.Signature[] calldata signatures\n )\n external\n payable\n returns (bytes[] memory returnResults);\n\n /// @dev Get the block at which a meta-transaction has been executed.\n /// @param mtx The meta-transaction.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionExecutedBlock(MetaTransactionData calldata mtx)\n external\n view\n returns (uint256 blockNumber);\n\n /// @dev Get the block at which a meta-transaction hash has been executed.\n /// @param mtxHash The meta-transaction hash.\n /// @return blockNumber The block height when the meta-transactioin was executed.\n function getMetaTransactionHashExecutedBlock(bytes32 mtxHash)\n external\n view\n returns (uint256 blockNumber);\n\n /// @dev Get the EIP712 hash of a meta-transaction.\n /// @param mtx The meta-transaction.\n /// @return mtxHash The EIP712 hash of `mtx`.\n function getMetaTransactionHash(MetaTransactionData calldata mtx)\n external\n view\n returns (bytes32 mtxHash);\n}\n",
"../features/libs/LibSignature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../../errors/LibSignatureRichErrors.sol\";\n\n\n/// @dev A library for validating signatures.\nlibrary LibSignature {\n using LibRichErrorsV06 for bytes;\n\n // '\\x19Ethereum Signed Message:\\n32\\x00\\x00\\x00\\x00' in a word.\n uint256 private constant ETH_SIGN_HASH_PREFIX =\n 0x19457468657265756d205369676e6564204d6573736167653a0a333200000000;\n /// @dev Exclusive upper limit on ECDSA signatures 'R' values.\n /// The valid range is given by fig (282) of the yellow paper.\n uint256 private constant ECDSA_SIGNATURE_R_LIMIT =\n uint256(0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141);\n /// @dev Exclusive upper limit on ECDSA signatures 'S' values.\n /// The valid range is given by fig (283) of the yellow paper.\n uint256 private constant ECDSA_SIGNATURE_S_LIMIT = ECDSA_SIGNATURE_R_LIMIT / 2 + 1;\n\n /// @dev Allowed signature types.\n enum SignatureType {\n ILLEGAL,\n INVALID,\n EIP712,\n ETHSIGN\n }\n\n /// @dev Encoded EC signature.\n struct Signature {\n // How to validate the signature.\n SignatureType signatureType;\n // EC Signature data.\n uint8 v;\n // EC Signature data.\n bytes32 r;\n // EC Signature data.\n bytes32 s;\n }\n\n /// @dev Retrieve the signer of a signature.\n /// Throws if the signature can't be validated.\n /// @param hash The hash that was signed.\n /// @param signature The signature.\n /// @return recovered The recovered signer address.\n function getSignerOfHash(\n bytes32 hash,\n Signature memory signature\n )\n internal\n pure\n returns (address recovered)\n {\n // Ensure this is a signature type that can be validated against a hash.\n _validateHashCompatibleSignature(hash, signature);\n\n if (signature.signatureType == SignatureType.EIP712) {\n // Signed using EIP712\n recovered = ecrecover(\n hash,\n signature.v,\n signature.r,\n signature.s\n );\n } else if (signature.signatureType == SignatureType.ETHSIGN) {\n // Signed using `eth_sign`\n // Need to hash `hash` with \"\\x19Ethereum Signed Message:\\n32\" prefix\n // in packed encoding.\n bytes32 ethSignHash;\n assembly {\n // Use scratch space\n mstore(0, ETH_SIGN_HASH_PREFIX) // length of 28 bytes\n mstore(28, hash) // length of 32 bytes\n ethSignHash := keccak256(0, 60)\n }\n recovered = ecrecover(\n ethSignHash,\n signature.v,\n signature.r,\n signature.s\n );\n }\n // `recovered` can be null if the signature values are out of range.\n if (recovered == address(0)) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,\n hash\n ).rrevert();\n }\n }\n\n /// @dev Validates that a signature is compatible with a hash signee.\n /// @param hash The hash that was signed.\n /// @param signature The signature.\n function _validateHashCompatibleSignature(\n bytes32 hash,\n Signature memory signature\n )\n private\n pure\n {\n // Ensure the r and s are within malleability limits.\n if (uint256(signature.r) >= ECDSA_SIGNATURE_R_LIMIT ||\n uint256(signature.s) >= ECDSA_SIGNATURE_S_LIMIT)\n {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,\n hash\n ).rrevert();\n }\n\n // Always illegal signature.\n if (signature.signatureType == SignatureType.ILLEGAL) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.ILLEGAL,\n hash\n ).rrevert();\n }\n\n // Always invalid.\n if (signature.signatureType == SignatureType.INVALID) {\n LibSignatureRichErrors.SignatureValidationError(\n LibSignatureRichErrors.SignatureValidationErrorCodes.ALWAYS_INVALID,\n hash\n ).rrevert();\n }\n\n // Solidity should check that the signature type is within enum range for us\n // when abi-decoding.\n }\n}\n",
"../errors/LibSignatureRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSignatureRichErrors {\n\n enum SignatureValidationErrorCodes {\n ALWAYS_INVALID,\n INVALID_LENGTH,\n UNSUPPORTED,\n ILLEGAL,\n WRONG_SIGNER,\n BAD_SIGNATURE_DATA\n }\n\n // solhint-disable func-name-mixedcase\n\n function SignatureValidationError(\n SignatureValidationErrorCodes code,\n bytes32 hash,\n address signerAddress,\n bytes memory signature\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SignatureValidationError(uint8,bytes32,address,bytes)\")),\n code,\n hash,\n signerAddress,\n signature\n );\n }\n\n function SignatureValidationError(\n SignatureValidationErrorCodes code,\n bytes32 hash\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"SignatureValidationError(uint8,bytes32)\")),\n code,\n hash\n );\n }\n}\n",
"../features/interfaces/INativeOrdersFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./INativeOrdersEvents.sol\";\n\n\n/// @dev Feature for interacting with limit orders.\ninterface INativeOrdersFeature is\n INativeOrdersEvents\n{\n\n /// @dev Transfers protocol fees from the `FeeCollector` pools into\n /// the staking contract.\n /// @param poolIds Staking pool IDs\n function transferProtocolFeesForPools(bytes32[] calldata poolIds)\n external;\n\n /// @dev Fill a limit order. The taker and sender will be the caller.\n /// @param order The limit order. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n payable\n returns (uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount\n )\n external\n returns (uint128 makerTokenFilledAmount);\n\n /// @dev Fill a limit order. Internal variant. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// `msg.sender` (not `sender`).\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @param sender The order sender.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillLimitOrder(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount,\n address taker,\n address sender\n )\n external\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Fill an RFQ order. Internal variant.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillRfqOrder(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n external\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);\n\n /// @dev Cancel a single limit order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The limit order.\n function cancelLimitOrder(LibNativeOrder.LimitOrder calldata order)\n external;\n\n /// @dev Cancel a single RFQ order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The RFQ order.\n function cancelRfqOrder(LibNativeOrder.RfqOrder calldata order)\n external;\n\n /// @dev Mark what tx.origin addresses are allowed to fill an order that\n /// specifies the message sender as its txOrigin.\n /// @param origins An array of origin addresses to update.\n /// @param allowed True to register, false to unregister.\n function registerAllowedRfqOrigins(address[] memory origins, bool allowed)\n external;\n\n /// @dev Cancel multiple limit orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The limit orders.\n function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] calldata orders)\n external;\n\n /// @dev Cancel multiple RFQ orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The RFQ orders.\n function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] calldata orders)\n external;\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairLimitOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n external;\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairLimitOrders(\n IERC20TokenV06[] calldata makerTokens,\n IERC20TokenV06[] calldata takerTokens,\n uint256[] calldata minValidSalts\n )\n external;\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairRfqOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n external;\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairRfqOrders(\n IERC20TokenV06[] calldata makerTokens,\n IERC20TokenV06[] calldata takerTokens,\n uint256[] calldata minValidSalts\n )\n external;\n\n /// @dev Get the order info for a limit order.\n /// @param order The limit order.\n /// @return orderInfo Info about the order.\n function getLimitOrderInfo(LibNativeOrder.LimitOrder calldata order)\n external\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo);\n\n /// @dev Get the order info for an RFQ order.\n /// @param order The RFQ order.\n /// @return orderInfo Info about the order.\n function getRfqOrderInfo(LibNativeOrder.RfqOrder calldata order)\n external\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo);\n\n /// @dev Get the canonical hash of a limit order.\n /// @param order The limit order.\n /// @return orderHash The order hash.\n function getLimitOrderHash(LibNativeOrder.LimitOrder calldata order)\n external\n view\n returns (bytes32 orderHash);\n\n /// @dev Get the canonical hash of an RFQ order.\n /// @param order The RFQ order.\n /// @return orderHash The order hash.\n function getRfqOrderHash(LibNativeOrder.RfqOrder calldata order)\n external\n view\n returns (bytes32 orderHash);\n\n /// @dev Get the protocol fee multiplier. This should be multiplied by the\n /// gas price to arrive at the required protocol fee to fill a native order.\n /// @return multiplier The protocol fee multiplier.\n function getProtocolFeeMultiplier()\n external\n view\n returns (uint32 multiplier);\n\n /// @dev Get order info, fillable amount, and signature validity for a limit order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getLimitOrderRelevantState(\n LibNativeOrder.LimitOrder calldata order,\n LibSignature.Signature calldata signature\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n );\n\n /// @dev Get order info, fillable amount, and signature validity for an RFQ order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getRfqOrderRelevantState(\n LibNativeOrder.RfqOrder calldata order,\n LibSignature.Signature calldata signature\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n );\n\n /// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getLimitOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The limit orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetLimitOrderRelevantStates(\n LibNativeOrder.LimitOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n );\n\n /// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getRfqOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The RFQ orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetRfqOrderRelevantStates(\n LibNativeOrder.RfqOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n );\n}\n",
"../features/libs/LibNativeOrder.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\n\n\n/// @dev A library for common native order operations.\nlibrary LibNativeOrder {\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n enum OrderStatus {\n INVALID,\n FILLABLE,\n FILLED,\n CANCELLED,\n EXPIRED\n }\n\n /// @dev A standard OTC or OO limit order.\n struct LimitOrder {\n IERC20TokenV06 makerToken;\n IERC20TokenV06 takerToken;\n uint128 makerAmount;\n uint128 takerAmount;\n uint128 takerTokenFeeAmount;\n address maker;\n address taker;\n address sender;\n address feeRecipient;\n bytes32 pool;\n uint64 expiry;\n uint256 salt;\n }\n\n /// @dev An RFQ limit order.\n struct RfqOrder {\n IERC20TokenV06 makerToken;\n IERC20TokenV06 takerToken;\n uint128 makerAmount;\n uint128 takerAmount;\n address maker;\n address taker;\n address txOrigin;\n bytes32 pool;\n uint64 expiry;\n uint256 salt;\n }\n\n /// @dev Info on a limit or RFQ order.\n struct OrderInfo {\n bytes32 orderHash;\n OrderStatus status;\n uint128 takerTokenFilledAmount;\n }\n\n uint256 private constant UINT_128_MASK = (1 << 128) - 1;\n uint256 private constant UINT_64_MASK = (1 << 64) - 1;\n uint256 private constant ADDRESS_MASK = (1 << 160) - 1;\n\n // The type hash for limit orders, which is:\n // keccak256(abi.encodePacked(\n // \"LimitOrder(\",\n // \"address makerToken,\",\n // \"address takerToken,\",\n // \"uint128 makerAmount,\",\n // \"uint128 takerAmount,\",\n // \"uint128 takerTokenFeeAmount,\",\n // \"address maker,\",\n // \"address taker,\",\n // \"address sender,\",\n // \"address feeRecipient,\",\n // \"bytes32 pool,\",\n // \"uint64 expiry,\",\n // \"uint256 salt\"\n // \")\"\n // ))\n uint256 private constant _LIMIT_ORDER_TYPEHASH =\n 0xce918627cb55462ddbb85e73de69a8b322f2bc88f4507c52fcad6d4c33c29d49;\n\n // The type hash for RFQ orders, which is:\n // keccak256(abi.encodePacked(\n // \"RfqOrder(\",\n // \"address makerToken,\",\n // \"address takerToken,\",\n // \"uint128 makerAmount,\",\n // \"uint128 takerAmount,\",\n // \"address maker,\",\n // \"address taker,\",\n // \"address txOrigin,\",\n // \"bytes32 pool,\",\n // \"uint64 expiry,\",\n // \"uint256 salt\"\n // \")\"\n // ))\n uint256 private constant _RFQ_ORDER_TYPEHASH =\n 0xe593d3fdfa8b60e5e17a1b2204662ecbe15c23f2084b9ad5bae40359540a7da9;\n\n /// @dev Get the struct hash of a limit order.\n /// @param order The limit order.\n /// @return structHash The struct hash of the order.\n function getLimitOrderStructHash(LimitOrder memory order)\n internal\n pure\n returns (bytes32 structHash)\n {\n // The struct hash is:\n // keccak256(abi.encode(\n // TYPE_HASH,\n // order.makerToken,\n // order.takerToken,\n // order.makerAmount,\n // order.takerAmount,\n // order.takerTokenFeeAmount,\n // order.maker,\n // order.taker,\n // order.sender,\n // order.feeRecipient,\n // order.pool,\n // order.expiry,\n // order.salt,\n // ))\n assembly {\n let mem := mload(0x40)\n mstore(mem, _LIMIT_ORDER_TYPEHASH)\n // order.makerToken;\n mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))\n // order.takerToken;\n mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))\n // order.makerAmount;\n mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))\n // order.takerAmount;\n mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))\n // order.takerTokenFeeAmount;\n mstore(add(mem, 0xA0), and(UINT_128_MASK, mload(add(order, 0x80))))\n // order.maker;\n mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))\n // order.taker;\n mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))\n // order.sender;\n mstore(add(mem, 0x100), and(ADDRESS_MASK, mload(add(order, 0xE0))))\n // order.feeRecipient;\n mstore(add(mem, 0x120), and(ADDRESS_MASK, mload(add(order, 0x100))))\n // order.pool;\n mstore(add(mem, 0x140), mload(add(order, 0x120)))\n // order.expiry;\n mstore(add(mem, 0x160), and(UINT_64_MASK, mload(add(order, 0x140))))\n // order.salt;\n mstore(add(mem, 0x180), mload(add(order, 0x160)))\n structHash := keccak256(mem, 0x1A0)\n }\n }\n\n /// @dev Get the struct hash of a RFQ order.\n /// @param order The RFQ order.\n /// @return structHash The struct hash of the order.\n function getRfqOrderStructHash(RfqOrder memory order)\n internal\n pure\n returns (bytes32 structHash)\n {\n // The struct hash is:\n // keccak256(abi.encode(\n // TYPE_HASH,\n // order.makerToken,\n // order.takerToken,\n // order.makerAmount,\n // order.takerAmount,\n // order.maker,\n // order.taker,\n // order.txOrigin,\n // order.pool,\n // order.expiry,\n // order.salt,\n // ))\n assembly {\n let mem := mload(0x40)\n mstore(mem, _RFQ_ORDER_TYPEHASH)\n // order.makerToken;\n mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))\n // order.takerToken;\n mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))\n // order.makerAmount;\n mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))\n // order.takerAmount;\n mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))\n // order.maker;\n mstore(add(mem, 0xA0), and(ADDRESS_MASK, mload(add(order, 0x80))))\n // order.taker;\n mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))\n // order.txOrigin;\n mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))\n // order.pool;\n mstore(add(mem, 0x100), mload(add(order, 0xE0)))\n // order.expiry;\n mstore(add(mem, 0x120), and(UINT_64_MASK, mload(add(order, 0x100))))\n // order.salt;\n mstore(add(mem, 0x140), mload(add(order, 0x120)))\n structHash := keccak256(mem, 0x160)\n }\n }\n\n /// @dev Refund any leftover protocol fees in `msg.value` to `msg.sender`.\n /// @param ethProtocolFeePaid How much ETH was paid in protocol fees.\n function refundExcessProtocolFeeToSender(uint256 ethProtocolFeePaid)\n internal\n {\n if (msg.value > ethProtocolFeePaid && msg.sender != address(this)) {\n uint256 refundAmount = msg.value.safeSub(ethProtocolFeePaid);\n (bool success,) = msg\n .sender\n .call{value: refundAmount}(\"\");\n if (!success) {\n LibNativeOrdersRichErrors.ProtocolFeeRefundFailed(\n msg.sender,\n refundAmount\n ).rrevert();\n }\n }\n }\n}\n",
"../errors/LibNativeOrdersRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibNativeOrdersRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function ProtocolFeeRefundFailed(\n address receiver,\n uint256 refundAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"ProtocolFeeRefundFailed(address,uint256)\")),\n receiver,\n refundAmount\n );\n }\n\n function OrderNotFillableByOriginError(\n bytes32 orderHash,\n address txOrigin,\n address orderTxOrigin\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableByOriginError(bytes32,address,address)\")),\n orderHash,\n txOrigin,\n orderTxOrigin\n );\n }\n\n function OrderNotFillableError(\n bytes32 orderHash,\n uint8 orderStatus\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableError(bytes32,uint8)\")),\n orderHash,\n orderStatus\n );\n }\n\n function OrderNotSignedByMakerError(\n bytes32 orderHash,\n address signer,\n address maker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotSignedByMakerError(bytes32,address,address)\")),\n orderHash,\n signer,\n maker\n );\n }\n\n function OrderNotFillableBySenderError(\n bytes32 orderHash,\n address sender,\n address orderSender\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableBySenderError(bytes32,address,address)\")),\n orderHash,\n sender,\n orderSender\n );\n }\n\n function OrderNotFillableByTakerError(\n bytes32 orderHash,\n address taker,\n address orderTaker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OrderNotFillableByTakerError(bytes32,address,address)\")),\n orderHash,\n taker,\n orderTaker\n );\n }\n\n function CancelSaltTooLowError(\n uint256 minValidSalt,\n uint256 oldMinValidSalt\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"CancelSaltTooLowError(uint256,uint256)\")),\n minValidSalt,\n oldMinValidSalt\n );\n }\n\n function FillOrKillFailedError(\n bytes32 orderHash,\n uint256 takerTokenFilledAmount,\n uint256 takerTokenFillAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"FillOrKillFailedError(bytes32,uint256,uint256)\")),\n orderHash,\n takerTokenFilledAmount,\n takerTokenFillAmount\n );\n }\n\n function OnlyOrderMakerAllowed(\n bytes32 orderHash,\n address sender,\n address maker\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"OnlyOrderMakerAllowed(bytes32,address,address)\")),\n orderHash,\n sender,\n maker\n );\n }\n\n function BatchFillIncompleteError(\n bytes32 orderHash,\n uint256 takerTokenFilledAmount,\n uint256 takerTokenFillAmount\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"BatchFillIncompleteError(bytes32,uint256,uint256)\")),\n orderHash,\n takerTokenFilledAmount,\n takerTokenFillAmount\n );\n }\n}\n",
"../features/interfaces/INativeOrdersEvents.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\n\n\n/// @dev Events emitted by NativeOrdersFeature.\ninterface INativeOrdersEvents {\n\n /// @dev Emitted whenever a `LimitOrder` is filled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The maker of the order.\n /// @param taker The taker of the order.\n /// @param feeRecipient Fee recipient of the order.\n /// @param takerTokenFilledAmount How much taker token was filled.\n /// @param makerTokenFilledAmount How much maker token was filled.\n /// @param protocolFeePaid How much protocol fee was paid.\n /// @param pool The fee pool associated with this order.\n event LimitOrderFilled(\n bytes32 orderHash,\n address maker,\n address taker,\n address feeRecipient,\n address makerToken,\n address takerToken,\n uint128 takerTokenFilledAmount,\n uint128 makerTokenFilledAmount,\n uint128 takerTokenFeeFilledAmount,\n uint256 protocolFeePaid,\n bytes32 pool\n );\n\n /// @dev Emitted whenever an `RfqOrder` is filled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The maker of the order.\n /// @param taker The taker of the order.\n /// @param takerTokenFilledAmount How much taker token was filled.\n /// @param makerTokenFilledAmount How much maker token was filled.\n /// @param pool The fee pool associated with this order.\n event RfqOrderFilled(\n bytes32 orderHash,\n address maker,\n address taker,\n address makerToken,\n address takerToken,\n uint128 takerTokenFilledAmount,\n uint128 makerTokenFilledAmount,\n bytes32 pool\n );\n\n /// @dev Emitted whenever a limit or RFQ order is cancelled.\n /// @param orderHash The canonical hash of the order.\n /// @param maker The order maker.\n event OrderCancelled(\n bytes32 orderHash,\n address maker\n );\n\n /// @dev Emitted whenever Limit orders are cancelled by pair by a maker.\n /// @param maker The maker of the order.\n /// @param makerToken The maker token in a pair for the orders cancelled.\n /// @param takerToken The taker token in a pair for the orders cancelled.\n /// @param minValidSalt The new minimum valid salt an order with this pair must\n /// have.\n event PairCancelledLimitOrders(\n address maker,\n address makerToken,\n address takerToken,\n uint256 minValidSalt\n );\n\n /// @dev Emitted whenever RFQ orders are cancelled by pair by a maker.\n /// @param maker The maker of the order.\n /// @param makerToken The maker token in a pair for the orders cancelled.\n /// @param takerToken The taker token in a pair for the orders cancelled.\n /// @param minValidSalt The new minimum valid salt an order with this pair must\n /// have.\n event PairCancelledRfqOrders(\n address maker,\n address makerToken,\n address takerToken,\n uint256 minValidSalt\n );\n\n /// @dev Emitted when new addresses are allowed or disallowed to fill\n /// orders with a given txOrigin.\n /// @param origin The address doing the allowing.\n /// @param addrs The address being allowed/disallowed.\n /// @param allowed Indicates whether the address should be allowed.\n event RfqOrderOriginsAllowed(\n address origin,\n address[] addrs,\n bool allowed\n );\n}\n",
"../features/NativeOrdersFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../migrations/LibMigrate.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/INativeOrdersFeature.sol\";\nimport \"./native_orders/NativeOrdersSettlement.sol\";\n\n\n/// @dev Feature for interacting with limit and RFQ orders.\ncontract NativeOrdersFeature is\n IFeature,\n NativeOrdersSettlement\n{\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"LimitOrders\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 1);\n\n constructor(\n address zeroExAddress,\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier,\n bytes32 greedyTokensBloomFilter\n )\n public\n NativeOrdersSettlement(\n zeroExAddress,\n weth,\n staking,\n feeCollectorController,\n protocolFeeMultiplier,\n greedyTokensBloomFilter\n )\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Initialize and register this feature.\n /// Should be delegatecalled by `Migrate.migrate()`.\n /// @return success `LibMigrate.SUCCESS` on success.\n function migrate()\n external\n returns (bytes4 success)\n {\n _registerFeatureFunction(this.transferProtocolFeesForPools.selector);\n _registerFeatureFunction(this.fillLimitOrder.selector);\n _registerFeatureFunction(this.fillRfqOrder.selector);\n _registerFeatureFunction(this.fillOrKillLimitOrder.selector);\n _registerFeatureFunction(this.fillOrKillRfqOrder.selector);\n _registerFeatureFunction(this._fillLimitOrder.selector);\n _registerFeatureFunction(this._fillRfqOrder.selector);\n _registerFeatureFunction(this.cancelLimitOrder.selector);\n _registerFeatureFunction(this.cancelRfqOrder.selector);\n _registerFeatureFunction(this.batchCancelLimitOrders.selector);\n _registerFeatureFunction(this.batchCancelRfqOrders.selector);\n _registerFeatureFunction(this.cancelPairLimitOrders.selector);\n _registerFeatureFunction(this.batchCancelPairLimitOrders.selector);\n _registerFeatureFunction(this.cancelPairRfqOrders.selector);\n _registerFeatureFunction(this.batchCancelPairRfqOrders.selector);\n _registerFeatureFunction(this.getLimitOrderInfo.selector);\n _registerFeatureFunction(this.getRfqOrderInfo.selector);\n _registerFeatureFunction(this.getLimitOrderHash.selector);\n _registerFeatureFunction(this.getRfqOrderHash.selector);\n _registerFeatureFunction(this.getProtocolFeeMultiplier.selector);\n _registerFeatureFunction(this.registerAllowedRfqOrigins.selector);\n _registerFeatureFunction(this.getLimitOrderRelevantState.selector);\n _registerFeatureFunction(this.getRfqOrderRelevantState.selector);\n _registerFeatureFunction(this.batchGetLimitOrderRelevantStates.selector);\n _registerFeatureFunction(this.batchGetRfqOrderRelevantStates.selector);\n return LibMigrate.MIGRATE_SUCCESS;\n }\n}\n",
"../features/native_orders/NativeOrdersSettlement.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../fixins/FixinCommon.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../../vendor/v3/IStaking.sol\";\nimport \"../interfaces/INativeOrdersEvents.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./NativeOrdersCancellation.sol\";\nimport \"./NativeOrdersProtocolFees.sol\";\n\n\n/// @dev Mixin for settling limit and RFQ orders.\nabstract contract NativeOrdersSettlement is\n INativeOrdersEvents,\n NativeOrdersCancellation,\n NativeOrdersProtocolFees,\n FixinCommon\n{\n using LibSafeMathV06 for uint128;\n using LibRichErrorsV06 for bytes;\n\n /// @dev Params for `_settleOrder()`.\n struct SettleOrderInfo {\n // Order hash.\n bytes32 orderHash;\n // Maker of the order.\n address maker;\n // Taker of the order.\n address taker;\n // Maker token.\n IERC20TokenV06 makerToken;\n // Taker token.\n IERC20TokenV06 takerToken;\n // Maker token amount.\n uint128 makerAmount;\n // Taker token amount.\n uint128 takerAmount;\n // Maximum taker token amount to fill.\n uint128 takerTokenFillAmount;\n // How much taker token amount has already been filled in this order.\n uint128 takerTokenFilledAmount;\n }\n\n /// @dev Params for `_fillLimitOrderPrivate()`\n struct FillLimitOrderPrivateParams {\n // The limit order.\n LibNativeOrder.LimitOrder order;\n // The order signature.\n LibSignature.Signature signature;\n // Maximum taker token to fill this order with.\n uint128 takerTokenFillAmount;\n // The order taker.\n address taker;\n // The order sender.\n address sender;\n }\n\n // @dev Fill results returned by `_fillLimitOrderPrivate()` and\n /// `_fillRfqOrderPrivate()`.\n struct FillNativeOrderResults {\n uint256 ethProtocolFeePaid;\n uint128 takerTokenFilledAmount;\n uint128 makerTokenFilledAmount;\n uint128 takerTokenFeeFilledAmount;\n }\n\n constructor(\n address zeroExAddress,\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier,\n bytes32 greedyTokensBloomFilter\n )\n public\n NativeOrdersCancellation(zeroExAddress, greedyTokensBloomFilter)\n NativeOrdersProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Fill a limit order. The taker and sender will be the caller.\n /// @param order The limit order. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n payable\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: msg.sender,\n sender: msg.sender\n }));\n LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH should be attached to pay the\n /// protocol fee.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token amount to fill this order with.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n msg.sender\n );\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n payable\n returns (uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: msg.sender,\n sender: msg.sender\n }));\n // Must have filled exactly the amount requested.\n if (results.takerTokenFilledAmount < takerTokenFillAmount) {\n LibNativeOrdersRichErrors.FillOrKillFailedError(\n getLimitOrderHash(order),\n results.takerTokenFilledAmount,\n takerTokenFillAmount\n ).rrevert();\n }\n LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);\n makerTokenFilledAmount = results.makerTokenFilledAmount;\n }\n\n /// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.\n /// The taker will be the caller. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// the caller.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount How much taker token to fill this order with.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function fillOrKillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount\n )\n public\n returns (uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n msg.sender\n );\n // Must have filled exactly the amount requested.\n if (results.takerTokenFilledAmount < takerTokenFillAmount) {\n LibNativeOrdersRichErrors.FillOrKillFailedError(\n getRfqOrderHash(order),\n results.takerTokenFilledAmount,\n takerTokenFillAmount\n ).rrevert();\n }\n makerTokenFilledAmount = results.makerTokenFilledAmount;\n }\n\n /// @dev Fill a limit order. Internal variant. ETH protocol fees can be\n /// attached to this call.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @param sender The order sender.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillLimitOrder(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker,\n address sender\n )\n public\n virtual\n payable\n onlySelf\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillLimitOrderPrivate(FillLimitOrderPrivateParams({\n order: order,\n signature: signature,\n takerTokenFillAmount: takerTokenFillAmount,\n taker: taker,\n sender: sender\n }));\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Fill an RFQ order. Internal variant. ETH protocol fees can be\n /// attached to this call. Any unspent ETH will be refunded to\n /// `msg.sender` (not `sender`).\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return takerTokenFilledAmount How much maker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _fillRfqOrder(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n public\n virtual\n onlySelf\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n FillNativeOrderResults memory results =\n _fillRfqOrderPrivate(\n order,\n signature,\n takerTokenFillAmount,\n taker\n );\n (takerTokenFilledAmount, makerTokenFilledAmount) = (\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount\n );\n }\n\n /// @dev Mark what tx.origin addresses are allowed to fill an order that\n /// specifies the message sender as its txOrigin.\n /// @param origins An array of origin addresses to update.\n /// @param allowed True to register, false to unregister.\n function registerAllowedRfqOrigins(\n address[] memory origins,\n bool allowed\n )\n external\n {\n require(msg.sender == tx.origin,\n \"NativeOrdersFeature/NO_CONTRACT_ORIGINS\");\n\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n for (uint256 i = 0; i < origins.length; i++) {\n stor.originRegistry[msg.sender][origins[i]] = allowed;\n }\n\n emit RfqOrderOriginsAllowed(msg.sender, origins, allowed);\n }\n\n /// @dev Fill a limit order. Private variant. Does not refund protocol fees.\n /// @param params Function params.\n /// @return results Results of the fill.\n function _fillLimitOrderPrivate(FillLimitOrderPrivateParams memory params)\n private\n returns (FillNativeOrderResults memory results)\n {\n LibNativeOrder.OrderInfo memory orderInfo = getLimitOrderInfo(params.order);\n\n // Must be fillable.\n if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n LibNativeOrdersRichErrors.OrderNotFillableError(\n orderInfo.orderHash,\n uint8(orderInfo.status)\n ).rrevert();\n }\n\n // Must be fillable by the taker.\n if (params.order.taker != address(0) && params.order.taker != params.taker) {\n LibNativeOrdersRichErrors.OrderNotFillableByTakerError(\n orderInfo.orderHash,\n params.taker,\n params.order.taker\n ).rrevert();\n }\n\n // Must be fillable by the sender.\n if (params.order.sender != address(0) && params.order.sender != params.sender) {\n LibNativeOrdersRichErrors.OrderNotFillableBySenderError(\n orderInfo.orderHash,\n params.sender,\n params.order.sender\n ).rrevert();\n }\n\n // Signature must be valid for the order.\n {\n address signer = LibSignature.getSignerOfHash(\n orderInfo.orderHash,\n params.signature\n );\n if (signer != params.order.maker) {\n LibNativeOrdersRichErrors.OrderNotSignedByMakerError(\n orderInfo.orderHash,\n signer,\n params.order.maker\n ).rrevert();\n }\n }\n\n // Pay the protocol fee.\n results.ethProtocolFeePaid = _collectProtocolFee(params.order.pool);\n\n // Settle between the maker and taker.\n (results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(\n SettleOrderInfo({\n orderHash: orderInfo.orderHash,\n maker: params.order.maker,\n taker: params.taker,\n makerToken: IERC20TokenV06(params.order.makerToken),\n takerToken: IERC20TokenV06(params.order.takerToken),\n makerAmount: params.order.makerAmount,\n takerAmount: params.order.takerAmount,\n takerTokenFillAmount: params.takerTokenFillAmount,\n takerTokenFilledAmount: orderInfo.takerTokenFilledAmount\n })\n );\n\n // Pay the fee recipient.\n if (params.order.takerTokenFeeAmount > 0) {\n results.takerTokenFeeFilledAmount = uint128(LibMathV06.getPartialAmountFloor(\n results.takerTokenFilledAmount,\n params.order.takerAmount,\n params.order.takerTokenFeeAmount\n ));\n _transferERC20Tokens(\n params.order.takerToken,\n params.taker,\n params.order.feeRecipient,\n uint256(results.takerTokenFeeFilledAmount)\n );\n }\n\n emit LimitOrderFilled(\n orderInfo.orderHash,\n params.order.maker,\n params.taker,\n params.order.feeRecipient,\n address(params.order.makerToken),\n address(params.order.takerToken),\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount,\n results.takerTokenFeeFilledAmount,\n results.ethProtocolFeePaid,\n params.order.pool\n );\n }\n\n /// @dev Fill an RFQ order. Private variant. Does not refund protocol fees.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @param takerTokenFillAmount Maximum taker token to fill this order with.\n /// @param taker The order taker.\n /// @return results Results of the fill.\n function _fillRfqOrderPrivate(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature,\n uint128 takerTokenFillAmount,\n address taker\n )\n private\n returns (FillNativeOrderResults memory results)\n {\n LibNativeOrder.OrderInfo memory orderInfo = getRfqOrderInfo(order);\n\n // Must be fillable.\n if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n LibNativeOrdersRichErrors.OrderNotFillableError(\n orderInfo.orderHash,\n uint8(orderInfo.status)\n ).rrevert();\n }\n\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n // Must be fillable by the tx.origin.\n if (order.txOrigin != tx.origin && !stor.originRegistry[order.txOrigin][tx.origin]) {\n LibNativeOrdersRichErrors.OrderNotFillableByOriginError(\n orderInfo.orderHash,\n tx.origin,\n order.txOrigin\n ).rrevert();\n }\n }\n\n // Must be fillable by the taker.\n if (order.taker != address(0) && order.taker != taker) {\n LibNativeOrdersRichErrors.OrderNotFillableByTakerError(\n orderInfo.orderHash,\n taker,\n order.taker\n ).rrevert();\n }\n\n // Signature must be valid for the order.\n {\n address signer = LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n if (signer != order.maker) {\n LibNativeOrdersRichErrors.OrderNotSignedByMakerError(\n orderInfo.orderHash,\n signer,\n order.maker\n ).rrevert();\n }\n }\n\n // Settle between the maker and taker.\n (results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(\n SettleOrderInfo({\n orderHash: orderInfo.orderHash,\n maker: order.maker,\n taker: taker,\n makerToken: IERC20TokenV06(order.makerToken),\n takerToken: IERC20TokenV06(order.takerToken),\n makerAmount: order.makerAmount,\n takerAmount: order.takerAmount,\n takerTokenFillAmount: takerTokenFillAmount,\n takerTokenFilledAmount: orderInfo.takerTokenFilledAmount\n })\n );\n\n emit RfqOrderFilled(\n orderInfo.orderHash,\n order.maker,\n taker,\n address(order.makerToken),\n address(order.takerToken),\n results.takerTokenFilledAmount,\n results.makerTokenFilledAmount,\n order.pool\n );\n }\n\n /// @dev Settle the trade between an order's maker and taker.\n /// @param settleInfo Information needed to execute the settlement.\n /// @return takerTokenFilledAmount How much taker token was filled.\n /// @return makerTokenFilledAmount How much maker token was filled.\n function _settleOrder(SettleOrderInfo memory settleInfo)\n private\n returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)\n {\n // Clamp the taker token fill amount to the fillable amount.\n takerTokenFilledAmount = LibSafeMathV06.min128(\n settleInfo.takerTokenFillAmount,\n settleInfo.takerAmount.safeSub128(settleInfo.takerTokenFilledAmount)\n );\n // Compute the maker token amount.\n // This should never overflow because the values are all clamped to\n // (2^128-1).\n makerTokenFilledAmount = uint128(LibMathV06.getPartialAmountFloor(\n uint256(takerTokenFilledAmount),\n uint256(settleInfo.takerAmount),\n uint256(settleInfo.makerAmount)\n ));\n\n if (takerTokenFilledAmount == 0 || makerTokenFilledAmount == 0) {\n // Nothing to do.\n return (0, 0);\n }\n\n // Update filled state for the order.\n LibNativeOrdersStorage\n .getStorage()\n .orderHashToTakerTokenFilledAmount[settleInfo.orderHash] =\n // OK to overwrite the whole word because we shouldn't get to this\n // function if the order is cancelled.\n settleInfo.takerTokenFilledAmount.safeAdd128(takerTokenFilledAmount);\n\n // Transfer taker -> maker.\n _transferERC20Tokens(\n settleInfo.takerToken,\n settleInfo.taker,\n settleInfo.maker,\n takerTokenFilledAmount\n );\n\n // Transfer maker -> taker.\n _transferERC20Tokens(\n settleInfo.makerToken,\n settleInfo.maker,\n settleInfo.taker,\n makerTokenFilledAmount\n );\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2019 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\nimport \"./LibSafeMathV06.sol\";\nimport \"./errors/LibRichErrorsV06.sol\";\nimport \"./errors/LibMathRichErrorsV06.sol\";\n\n\nlibrary LibMathV06 {\n\n using LibSafeMathV06 for uint256;\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// Reverts if rounding error is >= 0.1%\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded down.\n function safeGetPartialAmountFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n if (isRoundingErrorFloor(\n numerator,\n denominator,\n target\n )) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(\n numerator,\n denominator,\n target\n ));\n }\n\n partialAmount = numerator.safeMul(target).safeDiv(denominator);\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// Reverts if rounding error is >= 0.1%\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded up.\n function safeGetPartialAmountCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n if (isRoundingErrorCeil(\n numerator,\n denominator,\n target\n )) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(\n numerator,\n denominator,\n target\n ));\n }\n\n // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):\n // ceil(a / b) = floor((a + b - 1) / b)\n // To implement `ceil(a / b)` using safeDiv.\n partialAmount = numerator.safeMul(target)\n .safeAdd(denominator.safeSub(1))\n .safeDiv(denominator);\n\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded down.\n function getPartialAmountFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n partialAmount = numerator.safeMul(target).safeDiv(denominator);\n return partialAmount;\n }\n\n /// @dev Calculates partial value given a numerator and denominator rounded down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to calculate partial of.\n /// @return partialAmount Partial value of target rounded up.\n function getPartialAmountCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (uint256 partialAmount)\n {\n // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):\n // ceil(a / b) = floor((a + b - 1) / b)\n // To implement `ceil(a / b)` using safeDiv.\n partialAmount = numerator.safeMul(target)\n .safeAdd(denominator.safeSub(1))\n .safeDiv(denominator);\n\n return partialAmount;\n }\n\n /// @dev Checks if rounding error >= 0.1% when rounding down.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to multiply with numerator/denominator.\n /// @return isError Rounding error is present.\n function isRoundingErrorFloor(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bool isError)\n {\n if (denominator == 0) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());\n }\n\n // The absolute rounding error is the difference between the rounded\n // value and the ideal value. The relative rounding error is the\n // absolute rounding error divided by the absolute value of the\n // ideal value. This is undefined when the ideal value is zero.\n //\n // The ideal value is `numerator * target / denominator`.\n // Let's call `numerator * target % denominator` the remainder.\n // The absolute error is `remainder / denominator`.\n //\n // When the ideal value is zero, we require the absolute error to\n // be zero. Fortunately, this is always the case. The ideal value is\n // zero iff `numerator == 0` and/or `target == 0`. In this case the\n // remainder and absolute error are also zero.\n if (target == 0 || numerator == 0) {\n return false;\n }\n\n // Otherwise, we want the relative rounding error to be strictly\n // less than 0.1%.\n // The relative error is `remainder / (numerator * target)`.\n // We want the relative error less than 1 / 1000:\n // remainder / (numerator * denominator) < 1 / 1000\n // or equivalently:\n // 1000 * remainder < numerator * target\n // so we have a rounding error iff:\n // 1000 * remainder >= numerator * target\n uint256 remainder = mulmod(\n target,\n numerator,\n denominator\n );\n isError = remainder.safeMul(1000) >= numerator.safeMul(target);\n return isError;\n }\n\n /// @dev Checks if rounding error >= 0.1% when rounding up.\n /// @param numerator Numerator.\n /// @param denominator Denominator.\n /// @param target Value to multiply with numerator/denominator.\n /// @return isError Rounding error is present.\n function isRoundingErrorCeil(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bool isError)\n {\n if (denominator == 0) {\n LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());\n }\n\n // See the comments in `isRoundingError`.\n if (target == 0 || numerator == 0) {\n // When either is zero, the ideal value and rounded value are zero\n // and there is no rounding error. (Although the relative error\n // is undefined.)\n return false;\n }\n // Compute remainder as before\n uint256 remainder = mulmod(\n target,\n numerator,\n denominator\n );\n remainder = denominator.safeSub(remainder) % denominator;\n isError = remainder.safeMul(1000) >= numerator.safeMul(target);\n return isError;\n }\n}\n",
"@0x/contracts-utils/contracts/src/v06/errors/LibMathRichErrorsV06.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibMathRichErrorsV06 {\n\n // bytes4(keccak256(\"DivisionByZeroError()\"))\n bytes internal constant DIVISION_BY_ZERO_ERROR =\n hex\"a791837c\";\n\n // bytes4(keccak256(\"RoundingError(uint256,uint256,uint256)\"))\n bytes4 internal constant ROUNDING_ERROR_SELECTOR =\n 0x339f3de2;\n\n // solhint-disable func-name-mixedcase\n function DivisionByZeroError()\n internal\n pure\n returns (bytes memory)\n {\n return DIVISION_BY_ZERO_ERROR;\n }\n\n function RoundingError(\n uint256 numerator,\n uint256 denominator,\n uint256 target\n )\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n ROUNDING_ERROR_SELECTOR,\n numerator,\n denominator,\n target\n );\n }\n}\n",
"../storage/LibNativeOrdersStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for `NativeOrdersFeature`.\nlibrary LibNativeOrdersStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // How much taker token has been filled in order.\n // The lower `uint128` is the taker token fill amount.\n // The high bit will be `1` if the order was directly cancelled.\n mapping(bytes32 => uint256) orderHashToTakerTokenFilledAmount;\n // The minimum valid order salt for a given maker and order pair (maker, taker)\n // for limit orders.\n mapping(address => mapping(address => mapping(address => uint256)))\n limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;\n // The minimum valid order salt for a given maker and order pair (maker, taker)\n // for RFQ orders.\n mapping(address => mapping(address => mapping(address => uint256)))\n rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;\n // For a given order origin, which tx.origin addresses are allowed to\n // fill the order.\n mapping(address => mapping(address => bool)) originRegistry;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.NativeOrders\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../features/native_orders/NativeOrdersCancellation.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../interfaces/INativeOrdersEvents.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\nimport \"./NativeOrdersInfo.sol\";\n\n/// @dev Feature for cancelling limit and RFQ orders.\nabstract contract NativeOrdersCancellation is\n INativeOrdersEvents,\n NativeOrdersInfo\n{\n using LibRichErrorsV06 for bytes;\n\n /// @dev Highest bit of a uint256, used to flag cancelled orders.\n uint256 private constant HIGH_BIT = 1 << 255;\n\n constructor(\n address zeroExAddress,\n bytes32 greedyTokensBloomFilter\n )\n internal\n NativeOrdersInfo(zeroExAddress, greedyTokensBloomFilter)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Cancel a single limit order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The limit order.\n function cancelLimitOrder(LibNativeOrder.LimitOrder memory order)\n public\n {\n bytes32 orderHash = getLimitOrderHash(order);\n if (msg.sender != order.maker) {\n LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(\n orderHash,\n msg.sender,\n order.maker\n ).rrevert();\n }\n _cancelOrderHash(orderHash, order.maker);\n }\n\n /// @dev Cancel a single RFQ order. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param order The RFQ order.\n function cancelRfqOrder(LibNativeOrder.RfqOrder memory order)\n public\n {\n bytes32 orderHash = getRfqOrderHash(order);\n if (msg.sender != order.maker) {\n LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(\n orderHash,\n msg.sender,\n order.maker\n ).rrevert();\n }\n _cancelOrderHash(orderHash, order.maker);\n }\n\n /// @dev Cancel multiple limit orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The limit orders.\n function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] memory orders)\n public\n {\n for (uint256 i = 0; i < orders.length; ++i) {\n cancelLimitOrder(orders[i]);\n }\n }\n\n /// @dev Cancel multiple RFQ orders. The caller must be the maker.\n /// Silently succeeds if the order has already been cancelled.\n /// @param orders The RFQ orders.\n function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] memory orders)\n public\n {\n for (uint256 i = 0; i < orders.length; ++i) {\n cancelRfqOrder(orders[i]);\n }\n }\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairLimitOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n public\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n uint256 oldMinValidSalt =\n stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)];\n\n // New min salt must >= the old one.\n if (oldMinValidSalt > minValidSalt) {\n LibNativeOrdersRichErrors.\n CancelSaltTooLowError(minValidSalt, oldMinValidSalt)\n .rrevert();\n }\n\n stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)] = minValidSalt;\n\n emit PairCancelledLimitOrders(\n msg.sender,\n address(makerToken),\n address(takerToken),\n minValidSalt\n );\n }\n\n /// @dev Cancel all limit orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairLimitOrders(\n IERC20TokenV06[] memory makerTokens,\n IERC20TokenV06[] memory takerTokens,\n uint256[] memory minValidSalts\n )\n public\n {\n require(\n makerTokens.length == takerTokens.length &&\n makerTokens.length == minValidSalts.length,\n \"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS\"\n );\n\n for (uint256 i = 0; i < makerTokens.length; ++i) {\n cancelPairLimitOrders(\n makerTokens[i],\n takerTokens[i],\n minValidSalts[i]\n );\n }\n }\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerToken The maker token.\n /// @param takerToken The taker token.\n /// @param minValidSalt The new minimum valid salt.\n function cancelPairRfqOrders(\n IERC20TokenV06 makerToken,\n IERC20TokenV06 takerToken,\n uint256 minValidSalt\n )\n public\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n uint256 oldMinValidSalt =\n stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)];\n\n // New min salt must >= the old one.\n if (oldMinValidSalt > minValidSalt) {\n LibNativeOrdersRichErrors.\n CancelSaltTooLowError(minValidSalt, oldMinValidSalt)\n .rrevert();\n }\n\n stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [msg.sender]\n [address(makerToken)]\n [address(takerToken)] = minValidSalt;\n\n emit PairCancelledRfqOrders(\n msg.sender,\n address(makerToken),\n address(takerToken),\n minValidSalt\n );\n }\n\n /// @dev Cancel all RFQ orders for a given maker and pair with a salt less\n /// than the value provided. The caller must be the maker. Subsequent\n /// calls to this function with the same caller and pair require the\n /// new salt to be >= the old salt.\n /// @param makerTokens The maker tokens.\n /// @param takerTokens The taker tokens.\n /// @param minValidSalts The new minimum valid salts.\n function batchCancelPairRfqOrders(\n IERC20TokenV06[] memory makerTokens,\n IERC20TokenV06[] memory takerTokens,\n uint256[] memory minValidSalts\n )\n public\n {\n require(\n makerTokens.length == takerTokens.length &&\n makerTokens.length == minValidSalts.length,\n \"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS\"\n );\n\n for (uint256 i = 0; i < makerTokens.length; ++i) {\n cancelPairRfqOrders(\n makerTokens[i],\n takerTokens[i],\n minValidSalts[i]\n );\n }\n }\n\n /// @dev Cancel a limit or RFQ order directly by its order hash.\n /// @param orderHash The order's order hash.\n /// @param maker The order's maker.\n function _cancelOrderHash(bytes32 orderHash, address maker)\n private\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n // Set the high bit on the raw taker token fill amount to indicate\n // a cancel. It's OK to cancel twice.\n stor.orderHashToTakerTokenFilledAmount[orderHash] |= HIGH_BIT;\n\n emit OrderCancelled(orderHash, maker);\n }\n}\n",
"../features/native_orders/NativeOrdersInfo.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibMathV06.sol\";\nimport \"../../fixins/FixinEIP712.sol\";\nimport \"../../fixins/FixinTokenSpender.sol\";\nimport \"../../storage/LibNativeOrdersStorage.sol\";\nimport \"../libs/LibSignature.sol\";\nimport \"../libs/LibNativeOrder.sol\";\n\n\n/// @dev Feature for getting info about limit and RFQ orders.\nabstract contract NativeOrdersInfo is\n FixinEIP712,\n FixinTokenSpender\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n // @dev Params for `_getActualFillableTakerTokenAmount()`.\n struct GetActualFillableTakerTokenAmountParams {\n address maker;\n IERC20TokenV06 makerToken;\n uint128 orderMakerAmount;\n uint128 orderTakerAmount;\n LibNativeOrder.OrderInfo orderInfo;\n }\n\n /// @dev Highest bit of a uint256, used to flag cancelled orders.\n uint256 private constant HIGH_BIT = 1 << 255;\n\n constructor(\n address zeroExAddress,\n bytes32 greedyTokensBloomFilter\n )\n internal\n FixinEIP712(zeroExAddress)\n FixinTokenSpender(greedyTokensBloomFilter)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Get the order info for a limit order.\n /// @param order The limit order.\n /// @return orderInfo Info about the order.\n function getLimitOrderInfo(LibNativeOrder.LimitOrder memory order)\n public\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo)\n {\n // Recover maker and compute order hash.\n orderInfo.orderHash = getLimitOrderHash(order);\n uint256 minValidSalt = LibNativeOrdersStorage.getStorage()\n .limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [order.maker]\n [address(order.makerToken)]\n [address(order.takerToken)];\n _populateCommonOrderInfoFields(\n orderInfo,\n order.takerAmount,\n order.expiry,\n order.salt,\n minValidSalt\n );\n }\n\n /// @dev Get the order info for an RFQ order.\n /// @param order The RFQ order.\n /// @return orderInfo Info about the order.\n function getRfqOrderInfo(LibNativeOrder.RfqOrder memory order)\n public\n view\n returns (LibNativeOrder.OrderInfo memory orderInfo)\n {\n // Recover maker and compute order hash.\n orderInfo.orderHash = getRfqOrderHash(order);\n uint256 minValidSalt = LibNativeOrdersStorage.getStorage()\n .rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt\n [order.maker]\n [address(order.makerToken)]\n [address(order.takerToken)];\n _populateCommonOrderInfoFields(\n orderInfo,\n order.takerAmount,\n order.expiry,\n order.salt,\n minValidSalt\n );\n\n // Check for missing txOrigin.\n if (order.txOrigin == address(0)) {\n orderInfo.status = LibNativeOrder.OrderStatus.INVALID;\n }\n }\n\n /// @dev Get the canonical hash of a limit order.\n /// @param order The limit order.\n /// @return orderHash The order hash.\n function getLimitOrderHash(LibNativeOrder.LimitOrder memory order)\n public\n view\n returns (bytes32 orderHash)\n {\n return _getEIP712Hash(\n LibNativeOrder.getLimitOrderStructHash(order)\n );\n }\n\n /// @dev Get the canonical hash of an RFQ order.\n /// @param order The RFQ order.\n /// @return orderHash The order hash.\n function getRfqOrderHash(LibNativeOrder.RfqOrder memory order)\n public\n view\n returns (bytes32 orderHash)\n {\n return _getEIP712Hash(\n LibNativeOrder.getRfqOrderStructHash(order)\n );\n }\n\n /// @dev Get order info, fillable amount, and signature validity for a limit order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The limit order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getLimitOrderRelevantState(\n LibNativeOrder.LimitOrder memory order,\n LibSignature.Signature calldata signature\n )\n public\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfo = getLimitOrderInfo(order);\n actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams({\n maker: order.maker,\n makerToken: order.makerToken,\n orderMakerAmount: order.makerAmount,\n orderTakerAmount: order.takerAmount,\n orderInfo: orderInfo\n })\n );\n isSignatureValid = order.maker ==\n LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n }\n\n /// @dev Get order info, fillable amount, and signature validity for an RFQ order.\n /// Fillable amount is determined using balances and allowances of the maker.\n /// @param order The RFQ order.\n /// @param signature The order signature.\n /// @return orderInfo Info about the order.\n /// @return actualFillableTakerTokenAmount How much of the order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValid Whether the signature is valid.\n function getRfqOrderRelevantState(\n LibNativeOrder.RfqOrder memory order,\n LibSignature.Signature memory signature\n )\n public\n view\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfo = getRfqOrderInfo(order);\n actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams({\n maker: order.maker,\n makerToken: order.makerToken,\n orderMakerAmount: order.makerAmount,\n orderTakerAmount: order.takerAmount,\n orderInfo: orderInfo\n })\n );\n isSignatureValid = order.maker ==\n LibSignature.getSignerOfHash(orderInfo.orderHash, signature);\n }\n\n /// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getLimitOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The limit orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetLimitOrderRelevantStates(\n LibNativeOrder.LimitOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n )\n {\n require(\n orders.length == signatures.length,\n \"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS\"\n );\n orderInfos = new LibNativeOrder.OrderInfo[](orders.length);\n actualFillableTakerTokenAmounts = new uint128[](orders.length);\n isSignatureValids = new bool[](orders.length);\n for (uint256 i = 0; i < orders.length; ++i) {\n try\n this.getLimitOrderRelevantState(orders[i], signatures[i])\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfos[i] = orderInfo;\n actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;\n isSignatureValids[i] = isSignatureValid;\n }\n catch {}\n }\n }\n\n /// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.\n /// Orders that would normally cause `getRfqOrderRelevantState()`\n /// to revert will have empty results.\n /// @param orders The RFQ orders.\n /// @param signatures The order signatures.\n /// @return orderInfos Info about the orders.\n /// @return actualFillableTakerTokenAmounts How much of each order is fillable\n /// based on maker funds, in taker tokens.\n /// @return isSignatureValids Whether each signature is valid for the order.\n function batchGetRfqOrderRelevantStates(\n LibNativeOrder.RfqOrder[] calldata orders,\n LibSignature.Signature[] calldata signatures\n )\n external\n view\n returns (\n LibNativeOrder.OrderInfo[] memory orderInfos,\n uint128[] memory actualFillableTakerTokenAmounts,\n bool[] memory isSignatureValids\n )\n {\n require(\n orders.length == signatures.length,\n \"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS\"\n );\n orderInfos = new LibNativeOrder.OrderInfo[](orders.length);\n actualFillableTakerTokenAmounts = new uint128[](orders.length);\n isSignatureValids = new bool[](orders.length);\n for (uint256 i = 0; i < orders.length; ++i) {\n try\n this.getRfqOrderRelevantState(orders[i], signatures[i])\n returns (\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 actualFillableTakerTokenAmount,\n bool isSignatureValid\n )\n {\n orderInfos[i] = orderInfo;\n actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;\n isSignatureValids[i] = isSignatureValid;\n }\n catch {}\n }\n }\n\n /// @dev Populate `status` and `takerTokenFilledAmount` fields in\n /// `orderInfo`, which use the same code path for both limit and\n /// RFQ orders.\n /// @param orderInfo `OrderInfo` with `orderHash` and `maker` filled.\n /// @param takerAmount The order's taker token amount..\n /// @param expiry The order's expiry.\n /// @param salt The order's salt.\n /// @param salt The minimum valid salt for the maker and pair combination.\n function _populateCommonOrderInfoFields(\n LibNativeOrder.OrderInfo memory orderInfo,\n uint128 takerAmount,\n uint64 expiry,\n uint256 salt,\n uint256 minValidSalt\n )\n private\n view\n {\n LibNativeOrdersStorage.Storage storage stor =\n LibNativeOrdersStorage.getStorage();\n\n // Get the filled and direct cancel state.\n {\n // The high bit of the raw taker token filled amount will be set\n // if the order was cancelled.\n uint256 rawTakerTokenFilledAmount =\n stor.orderHashToTakerTokenFilledAmount[orderInfo.orderHash];\n orderInfo.takerTokenFilledAmount = uint128(rawTakerTokenFilledAmount);\n if (orderInfo.takerTokenFilledAmount >= takerAmount) {\n orderInfo.status = LibNativeOrder.OrderStatus.FILLED;\n return;\n }\n if (rawTakerTokenFilledAmount & HIGH_BIT != 0) {\n orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;\n return;\n }\n }\n\n // Check for expiration.\n if (expiry <= uint64(block.timestamp)) {\n orderInfo.status = LibNativeOrder.OrderStatus.EXPIRED;\n return;\n }\n\n // Check if the order was cancelled by salt.\n if (minValidSalt > salt) {\n orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;\n return;\n }\n orderInfo.status = LibNativeOrder.OrderStatus.FILLABLE;\n }\n\n /// @dev Calculate the actual fillable taker token amount of an order\n /// based on maker allowance and balances.\n function _getActualFillableTakerTokenAmount(\n GetActualFillableTakerTokenAmountParams memory params\n )\n private\n view\n returns (uint128 actualFillableTakerTokenAmount)\n {\n if (params.orderMakerAmount == 0 || params.orderTakerAmount == 0) {\n // Empty order.\n return 0;\n }\n if (params.orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {\n // Not fillable.\n return 0;\n }\n\n // Get the fillable maker amount based on the order quantities and\n // previously filled amount\n uint256 fillableMakerTokenAmount = LibMathV06.getPartialAmountFloor(\n uint256(\n params.orderTakerAmount\n - params.orderInfo.takerTokenFilledAmount\n ),\n uint256(params.orderTakerAmount),\n uint256(params.orderMakerAmount)\n );\n // Clamp it to the amount of maker tokens we can spend on behalf of the\n // maker.\n fillableMakerTokenAmount = LibSafeMathV06.min256(\n fillableMakerTokenAmount,\n _getSpendableERC20BalanceOf(params.makerToken, params.maker)\n );\n // Convert to taker token amount.\n return LibMathV06.getPartialAmountCeil(\n fillableMakerTokenAmount,\n uint256(params.orderMakerAmount),\n uint256(params.orderTakerAmount)\n ).safeDowncastToUint128();\n }\n}\n",
"../features/native_orders/NativeOrdersProtocolFees.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2021 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol\";\nimport \"../../fixins/FixinProtocolFees.sol\";\nimport \"../../errors/LibNativeOrdersRichErrors.sol\";\nimport \"../../vendor/v3/IStaking.sol\";\n\n\n/// @dev Mixin for protocol fee utility functions.\nabstract contract NativeOrdersProtocolFees is\n FixinProtocolFees\n{\n using LibSafeMathV06 for uint256;\n using LibRichErrorsV06 for bytes;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier\n )\n internal\n FixinProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)\n {\n // solhint-disable no-empty-blocks\n }\n\n /// @dev Transfers protocol fees from the `FeeCollector` pools into\n /// the staking contract.\n /// @param poolIds Staking pool IDs\n function transferProtocolFeesForPools(bytes32[] calldata poolIds)\n external\n {\n for (uint256 i = 0; i < poolIds.length; ++i) {\n _transferFeesForPool(poolIds[i]);\n }\n }\n\n /// @dev Get the protocol fee multiplier. This should be multiplied by the\n /// gas price to arrive at the required protocol fee to fill a native order.\n /// @return multiplier The protocol fee multiplier.\n function getProtocolFeeMultiplier()\n external\n view\n returns (uint32 multiplier)\n {\n return PROTOCOL_FEE_MULTIPLIER;\n }\n}\n",
"../fixins/FixinProtocolFees.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"../external/FeeCollector.sol\";\nimport \"../external/FeeCollectorController.sol\";\nimport \"../external/LibFeeCollector.sol\";\nimport \"../vendor/v3/IStaking.sol\";\n\n\n/// @dev Helpers for collecting protocol fees.\nabstract contract FixinProtocolFees {\n\n /// @dev The protocol fee multiplier.\n uint32 public immutable PROTOCOL_FEE_MULTIPLIER;\n /// @dev The `FeeCollectorController` contract.\n FeeCollectorController private immutable FEE_COLLECTOR_CONTROLLER;\n /// @dev Hash of the fee collector init code.\n bytes32 private immutable FEE_COLLECTOR_INIT_CODE_HASH;\n /// @dev The WETH token contract.\n IEtherTokenV06 private immutable WETH;\n /// @dev The staking contract.\n IStaking private immutable STAKING;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking,\n FeeCollectorController feeCollectorController,\n uint32 protocolFeeMultiplier\n )\n internal\n {\n FEE_COLLECTOR_CONTROLLER = feeCollectorController;\n FEE_COLLECTOR_INIT_CODE_HASH =\n feeCollectorController.FEE_COLLECTOR_INIT_CODE_HASH();\n WETH = weth;\n STAKING = staking;\n PROTOCOL_FEE_MULTIPLIER = protocolFeeMultiplier;\n }\n\n /// @dev Collect the specified protocol fee in ETH.\n /// The fee is stored in a per-pool fee collector contract.\n /// @param poolId The pool ID for which a fee is being collected.\n /// @return ethProtocolFeePaid How much protocol fee was collected in ETH.\n function _collectProtocolFee(bytes32 poolId)\n internal\n returns (uint256 ethProtocolFeePaid)\n {\n uint256 protocolFeePaid = _getSingleProtocolFee();\n if (protocolFeePaid == 0) {\n // Nothing to do.\n return 0;\n }\n FeeCollector feeCollector = _getFeeCollector(poolId);\n (bool success,) = address(feeCollector).call{value: protocolFeePaid}(\"\");\n require(success, \"FixinProtocolFees/ETHER_TRANSFER_FALIED\");\n return protocolFeePaid;\n }\n\n /// @dev Transfer fees for a given pool to the staking contract.\n /// @param poolId Identifies the pool whose fees are being paid.\n function _transferFeesForPool(bytes32 poolId)\n internal\n {\n // This will create a FeeCollector contract (if necessary) and wrap\n // fees for the pool ID.\n FeeCollector feeCollector =\n FEE_COLLECTOR_CONTROLLER.prepareFeeCollectorToPayFees(poolId);\n // All fees in the fee collector should be in WETH now.\n uint256 bal = WETH.balanceOf(address(feeCollector));\n if (bal > 1) {\n // Leave 1 wei behind to avoid high SSTORE cost of zero-->non-zero.\n STAKING.payProtocolFee(\n address(feeCollector),\n address(feeCollector),\n bal - 1);\n }\n }\n\n /// @dev Compute the CREATE2 address for a fee collector.\n /// @param poolId The fee collector's pool ID.\n function _getFeeCollector(bytes32 poolId)\n internal\n view\n returns (FeeCollector)\n {\n return FeeCollector(LibFeeCollector.getFeeCollectorAddress(\n address(FEE_COLLECTOR_CONTROLLER),\n FEE_COLLECTOR_INIT_CODE_HASH,\n poolId\n ));\n }\n\n /// @dev Get the cost of a single protocol fee.\n /// @return protocolFeeAmount The protocol fee amount, in ETH/WETH.\n function _getSingleProtocolFee()\n internal\n view\n returns (uint256 protocolFeeAmount)\n {\n return uint256(PROTOCOL_FEE_MULTIPLIER) * tx.gasprice;\n }\n}\n",
"../external/FeeCollectorController.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol\";\nimport \"../vendor/v3/IStaking.sol\";\nimport \"./FeeCollector.sol\";\nimport \"./LibFeeCollector.sol\";\n\n\n/// @dev A contract that manages `FeeCollector` contracts.\ncontract FeeCollectorController {\n\n /// @dev Hash of the fee collector init code.\n bytes32 public immutable FEE_COLLECTOR_INIT_CODE_HASH;\n /// @dev The WETH contract.\n IEtherTokenV06 private immutable WETH;\n /// @dev The staking contract.\n IStaking private immutable STAKING;\n\n constructor(\n IEtherTokenV06 weth,\n IStaking staking\n )\n public\n {\n FEE_COLLECTOR_INIT_CODE_HASH = keccak256(type(FeeCollector).creationCode);\n WETH = weth;\n STAKING = staking;\n }\n\n /// @dev Deploy (if needed) a `FeeCollector` contract for `poolId`\n /// and wrap its ETH into WETH. Anyone may call this.\n /// @param poolId The pool ID associated with the staking pool.\n /// @return feeCollector The `FeeCollector` contract instance.\n function prepareFeeCollectorToPayFees(bytes32 poolId)\n external\n returns (FeeCollector feeCollector)\n {\n feeCollector = getFeeCollector(poolId);\n uint256 codeSize;\n assembly {\n codeSize := extcodesize(feeCollector)\n }\n\n if (codeSize == 0) {\n // Create and initialize the contract if necessary.\n new FeeCollector{salt: bytes32(poolId)}();\n feeCollector.initialize(WETH, STAKING, poolId);\n }\n\n if (address(feeCollector).balance > 1) {\n feeCollector.convertToWeth(WETH);\n }\n\n return feeCollector;\n }\n\n /// @dev Get the `FeeCollector` contract for a given pool ID. The contract\n /// will not actually exist until `prepareFeeCollectorToPayFees()`\n /// has been called once.\n /// @param poolId The pool ID associated with the staking pool.\n /// @return feeCollector The `FeeCollector` contract instance.\n function getFeeCollector(bytes32 poolId)\n public\n view\n returns (FeeCollector feeCollector)\n {\n return FeeCollector(LibFeeCollector.getFeeCollectorAddress(\n address(this),\n FEE_COLLECTOR_INIT_CODE_HASH,\n poolId\n ));\n }\n}\n",
"../external/LibFeeCollector.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\n\n/// @dev Helpers for computing `FeeCollector` contract addresses.\nlibrary LibFeeCollector {\n\n /// @dev Compute the CREATE2 address for a fee collector.\n /// @param controller The address of the `FeeCollectorController` contract.\n /// @param initCodeHash The init code hash of the `FeeCollector` contract.\n /// @param poolId The fee collector's pool ID.\n function getFeeCollectorAddress(address controller, bytes32 initCodeHash, bytes32 poolId)\n internal\n pure\n returns (address payable feeCollectorAddress)\n {\n // Compute the CREATE2 address for the fee collector.\n return address(uint256(keccak256(abi.encodePacked(\n byte(0xff),\n controller,\n poolId, // pool ID is salt\n initCodeHash\n ))));\n }\n}\n",
"../external/AllowanceTarget.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol\";\nimport \"../errors/LibSpenderRichErrors.sol\";\nimport \"./IAllowanceTarget.sol\";\n\n\n/// @dev The allowance target for the TokenSpender feature.\ncontract AllowanceTarget is\n IAllowanceTarget,\n AuthorizableV06\n{\n // solhint-disable no-unused-vars,indent,no-empty-blocks\n using LibRichErrorsV06 for bytes;\n\n /// @dev Execute an arbitrary call. Only an authority can call this.\n /// @param target The call target.\n /// @param callData The call data.\n /// @return resultData The data returned by the call.\n function executeCall(\n address payable target,\n bytes calldata callData\n )\n external\n override\n onlyAuthorized\n returns (bytes memory resultData)\n {\n bool success;\n (success, resultData) = target.call(callData);\n if (!success) {\n resultData.rrevert();\n }\n }\n}\n",
"./InitialMigration.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"../ZeroEx.sol\";\nimport \"../features/interfaces/IBootstrapFeature.sol\";\nimport \"../features/SimpleFunctionRegistryFeature.sol\";\nimport \"../features/OwnableFeature.sol\";\nimport \"./LibBootstrap.sol\";\n\n\n/// @dev A contract for deploying and configuring a minimal ZeroEx contract.\ncontract InitialMigration {\n\n /// @dev Features to bootstrap into the the proxy contract.\n struct BootstrapFeatures {\n SimpleFunctionRegistryFeature registry;\n OwnableFeature ownable;\n }\n\n /// @dev The allowed caller of `initializeZeroEx()`. In production, this would be\n /// the governor.\n address public immutable initializeCaller;\n /// @dev The real address of this contract.\n address private immutable _implementation;\n\n /// @dev Instantiate this contract and set the allowed caller of `initializeZeroEx()`\n /// to `initializeCaller_`.\n /// @param initializeCaller_ The allowed caller of `initializeZeroEx()`.\n constructor(address initializeCaller_) public {\n initializeCaller = initializeCaller_;\n _implementation = address(this);\n }\n\n /// @dev Initialize the `ZeroEx` contract with the minimum feature set,\n /// transfers ownership to `owner`, then self-destructs.\n /// Only callable by `initializeCaller` set in the contstructor.\n /// @param owner The owner of the contract.\n /// @param zeroEx The instance of the ZeroEx contract. ZeroEx should\n /// been constructed with this contract as the bootstrapper.\n /// @param features Features to bootstrap into the proxy.\n /// @return _zeroEx The configured ZeroEx contract. Same as the `zeroEx` parameter.\n function initializeZeroEx(\n address payable owner,\n ZeroEx zeroEx,\n BootstrapFeatures memory features\n )\n public\n virtual\n returns (ZeroEx _zeroEx)\n {\n // Must be called by the allowed initializeCaller.\n require(msg.sender == initializeCaller, \"InitialMigration/INVALID_SENDER\");\n\n // Bootstrap the initial feature set.\n IBootstrapFeature(address(zeroEx)).bootstrap(\n address(this),\n abi.encodeWithSelector(this.bootstrap.selector, owner, features)\n );\n\n // Self-destruct. This contract should not hold any funds but we send\n // them to the owner just in case.\n this.die(owner);\n\n return zeroEx;\n }\n\n /// @dev Sets up the initial state of the `ZeroEx` contract.\n /// The `ZeroEx` contract will delegatecall into this function.\n /// @param owner The new owner of the ZeroEx contract.\n /// @param features Features to bootstrap into the proxy.\n /// @return success Magic bytes if successful.\n function bootstrap(address owner, BootstrapFeatures memory features)\n public\n virtual\n returns (bytes4 success)\n {\n // Deploy and migrate the initial features.\n // Order matters here.\n\n // Initialize Registry.\n LibBootstrap.delegatecallBootstrapFunction(\n address(features.registry),\n abi.encodeWithSelector(\n SimpleFunctionRegistryFeature.bootstrap.selector\n )\n );\n\n // Initialize OwnableFeature.\n LibBootstrap.delegatecallBootstrapFunction(\n address(features.ownable),\n abi.encodeWithSelector(\n OwnableFeature.bootstrap.selector\n )\n );\n\n // De-register `SimpleFunctionRegistryFeature._extendSelf`.\n SimpleFunctionRegistryFeature(address(this)).rollback(\n SimpleFunctionRegistryFeature._extendSelf.selector,\n address(0)\n );\n\n // Transfer ownership to the real owner.\n OwnableFeature(address(this)).transferOwnership(owner);\n\n success = LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Self-destructs this contract. Only callable by this contract.\n /// @param ethRecipient Who to transfer outstanding ETH to.\n function die(address payable ethRecipient) public virtual {\n require(msg.sender == _implementation, \"InitialMigration/INVALID_SENDER\");\n selfdestruct(ethRecipient);\n }\n}\n",
"../features/SimpleFunctionRegistryFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../storage/LibProxyStorage.sol\";\nimport \"../storage/LibSimpleFunctionRegistryStorage.sol\";\nimport \"../errors/LibSimpleFunctionRegistryRichErrors.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/ISimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Basic registry management features.\ncontract SimpleFunctionRegistryFeature is\n IFeature,\n ISimpleFunctionRegistryFeature,\n FixinCommon\n{\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"SimpleFunctionRegistry\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initializes this feature, registering its own functions.\n /// @return success Magic bytes if successful.\n function bootstrap()\n external\n returns (bytes4 success)\n {\n // Register the registration functions (inception vibes).\n _extend(this.extend.selector, _implementation);\n _extend(this._extendSelf.selector, _implementation);\n // Register the rollback function.\n _extend(this.rollback.selector, _implementation);\n // Register getters.\n _extend(this.getRollbackLength.selector, _implementation);\n _extend(this.getRollbackEntryAtIndex.selector, _implementation);\n return LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Roll back to a prior implementation of a function.\n /// Only directly callable by an authority.\n /// @param selector The function selector.\n /// @param targetImpl The address of an older implementation of the function.\n function rollback(bytes4 selector, address targetImpl)\n external\n override\n onlyOwner\n {\n (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n ) = _getStorages();\n\n address currentImpl = proxyStor.impls[selector];\n if (currentImpl == targetImpl) {\n // Do nothing if already at targetImpl.\n return;\n }\n // Walk history backwards until we find the target implementation.\n address[] storage history = stor.implHistory[selector];\n uint256 i = history.length;\n for (; i > 0; --i) {\n address impl = history[i - 1];\n history.pop();\n if (impl == targetImpl) {\n break;\n }\n }\n if (i == 0) {\n LibSimpleFunctionRegistryRichErrors.NotInRollbackHistoryError(\n selector,\n targetImpl\n ).rrevert();\n }\n proxyStor.impls[selector] = targetImpl;\n emit ProxyFunctionUpdated(selector, currentImpl, targetImpl);\n }\n\n /// @dev Register or replace a function.\n /// Only directly callable by an authority.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function extend(bytes4 selector, address impl)\n external\n override\n onlyOwner\n {\n _extend(selector, impl);\n }\n\n /// @dev Register or replace a function.\n /// Only callable from within.\n /// This function is only used during the bootstrap process and\n /// should be deregistered by the deployer after bootstrapping is\n /// complete.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function _extendSelf(bytes4 selector, address impl)\n external\n onlySelf\n {\n _extend(selector, impl);\n }\n\n /// @dev Retrieve the length of the rollback history for a function.\n /// @param selector The function selector.\n /// @return rollbackLength The number of items in the rollback history for\n /// the function.\n function getRollbackLength(bytes4 selector)\n external\n override\n view\n returns (uint256 rollbackLength)\n {\n return LibSimpleFunctionRegistryStorage.getStorage().implHistory[selector].length;\n }\n\n /// @dev Retrieve an entry in the rollback history for a function.\n /// @param selector The function selector.\n /// @param idx The index in the rollback history.\n /// @return impl An implementation address for the function at\n /// index `idx`.\n function getRollbackEntryAtIndex(bytes4 selector, uint256 idx)\n external\n override\n view\n returns (address impl)\n {\n return LibSimpleFunctionRegistryStorage.getStorage().implHistory[selector][idx];\n }\n\n /// @dev Register or replace a function.\n /// @param selector The function selector.\n /// @param impl The implementation contract for the function.\n function _extend(bytes4 selector, address impl)\n private\n {\n (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n ) = _getStorages();\n\n address oldImpl = proxyStor.impls[selector];\n address[] storage history = stor.implHistory[selector];\n history.push(oldImpl);\n proxyStor.impls[selector] = impl;\n emit ProxyFunctionUpdated(selector, oldImpl, impl);\n }\n\n /// @dev Get the storage buckets for this feature and the proxy.\n /// @return stor Storage bucket for this feature.\n /// @return proxyStor age bucket for the proxy.\n function _getStorages()\n private\n pure\n returns (\n LibSimpleFunctionRegistryStorage.Storage storage stor,\n LibProxyStorage.Storage storage proxyStor\n )\n {\n return (\n LibSimpleFunctionRegistryStorage.getStorage(),\n LibProxyStorage.getStorage()\n );\n }\n}\n",
"../storage/LibSimpleFunctionRegistryStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `SimpleFunctionRegistry` feature.\nlibrary LibSimpleFunctionRegistryStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // Mapping of function selector -> implementation history.\n mapping(bytes4 => address[]) implHistory;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.SimpleFunctionRegistry\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n",
"../errors/LibSimpleFunctionRegistryRichErrors.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\n\n\nlibrary LibSimpleFunctionRegistryRichErrors {\n\n // solhint-disable func-name-mixedcase\n\n function NotInRollbackHistoryError(bytes4 selector, address targetImpl)\n internal\n pure\n returns (bytes memory)\n {\n return abi.encodeWithSelector(\n bytes4(keccak256(\"NotInRollbackHistoryError(bytes4,address)\")),\n selector,\n targetImpl\n );\n }\n}\n",
"../features/OwnableFeature.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol\";\nimport \"../fixins/FixinCommon.sol\";\nimport \"../errors/LibOwnableRichErrors.sol\";\nimport \"../storage/LibOwnableStorage.sol\";\nimport \"../migrations/LibBootstrap.sol\";\nimport \"../migrations/LibMigrate.sol\";\nimport \"./interfaces/IFeature.sol\";\nimport \"./interfaces/IOwnableFeature.sol\";\nimport \"./SimpleFunctionRegistryFeature.sol\";\n\n\n/// @dev Owner management features.\ncontract OwnableFeature is\n IFeature,\n IOwnableFeature,\n FixinCommon\n{\n\n /// @dev Name of this feature.\n string public constant override FEATURE_NAME = \"Ownable\";\n /// @dev Version of this feature.\n uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);\n\n using LibRichErrorsV06 for bytes;\n\n /// @dev Initializes this feature. The intial owner will be set to this (ZeroEx)\n /// to allow the bootstrappers to call `extend()`. Ownership should be\n /// transferred to the real owner by the bootstrapper after\n /// bootstrapping is complete.\n /// @return success Magic bytes if successful.\n function bootstrap() external returns (bytes4 success) {\n // Set the owner to ourselves to allow bootstrappers to call `extend()`.\n LibOwnableStorage.getStorage().owner = address(this);\n\n // Register feature functions.\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.transferOwnership.selector, _implementation);\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.owner.selector, _implementation);\n SimpleFunctionRegistryFeature(address(this))._extendSelf(this.migrate.selector, _implementation);\n return LibBootstrap.BOOTSTRAP_SUCCESS;\n }\n\n /// @dev Change the owner of this contract.\n /// Only directly callable by the owner.\n /// @param newOwner New owner address.\n function transferOwnership(address newOwner)\n external\n override\n onlyOwner\n {\n LibOwnableStorage.Storage storage proxyStor = LibOwnableStorage.getStorage();\n\n if (newOwner == address(0)) {\n LibOwnableRichErrors.TransferOwnerToZeroError().rrevert();\n } else {\n proxyStor.owner = newOwner;\n emit OwnershipTransferred(msg.sender, newOwner);\n }\n }\n\n /// @dev Execute a migration function in the context of the ZeroEx contract.\n /// The result of the function being called should be the magic bytes\n /// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.\n /// Temporarily sets the owner to ourselves so we can perform admin functions.\n /// Before returning, the owner will be set to `newOwner`.\n /// @param target The migrator contract address.\n /// @param data The call data.\n /// @param newOwner The address of the new owner.\n function migrate(address target, bytes calldata data, address newOwner)\n external\n override\n onlyOwner\n {\n if (newOwner == address(0)) {\n LibOwnableRichErrors.TransferOwnerToZeroError().rrevert();\n }\n\n LibOwnableStorage.Storage storage stor = LibOwnableStorage.getStorage();\n // The owner will be temporarily set to `address(this)` inside the call.\n stor.owner = address(this);\n\n // Perform the migration.\n LibMigrate.delegatecallMigrateFunction(target, data);\n\n // Update the owner.\n stor.owner = newOwner;\n\n emit Migrated(msg.sender, target, newOwner);\n }\n\n /// @dev Get the owner of this contract.\n /// @return owner_ The owner of this contract.\n function owner() external override view returns (address owner_) {\n return LibOwnableStorage.getStorage().owner;\n }\n}\n",
"../storage/LibOwnableStorage.sol": "// SPDX-License-Identifier: Apache-2.0\n/*\n\n Copyright 2020 ZeroEx Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity ^0.6.5;\npragma experimental ABIEncoderV2;\n\nimport \"./LibStorage.sol\";\n\n\n/// @dev Storage helpers for the `Ownable` feature.\nlibrary LibOwnableStorage {\n\n /// @dev Storage bucket for this feature.\n struct Storage {\n // The owner of this contract.\n address owner;\n }\n\n /// @dev Get the storage bucket for this contract.\n function getStorage() internal pure returns (Storage storage stor) {\n uint256 storageSlot = LibStorage.getStorageSlot(\n LibStorage.StorageId.Ownable\n );\n // Dip into assembly to change the slot pointed to by the local\n // variable `stor`.\n // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries\n assembly { stor_slot := storageSlot }\n }\n}\n"
},
"compiler": {
"name": "solc",
"version": "0.6.12+commit.27d51765",
"settings": {
"remappings": [
"@0x/contracts-utils=/Users/michaelzhu/protocol/node_modules/@0x/contracts-utils",
"@0x/contracts-erc20=/Users/michaelzhu/protocol/contracts/zero-ex/node_modules/@0x/contracts-erc20"
],
"optimizer": {
"enabled": true,
"runs": 1000000,
"details": {
"yul": true,
"deduplicate": true,
"cse": true,
"constantOptimizer": true
}
},
"outputSelection": {
"*": {
"*": [
"abi",
"devdoc",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap",
"evm.methodIdentifiers"
]
}
},
"evmVersion": "istanbul"
}
},
"chains": {}
}