Address Contract Verified
Address
0xA1F473A8783ffeb8eedd57641f6Db69B5c8E7949
Balance
0 ETH
Nonce
1
Code Size
12752 bytes
Creator
0xF2d98377...4De2 at tx 0xbec6eef3...cc3ec5
Indexed Transactions
0
Contract Bytecode
12752 bytes
0x60806040526004361061004e5760003560e01c80633d471cd81461005a5780633e86ff701461008a5780638e0a8e9d146100ba578063ceba504d146100f7578063dd074ea01461012757610055565b3661005557005b600080fd5b610074600480360381019061006f9190610ec1565b610157565b6040516100819190611064565b60405180910390f35b6100a4600480360381019061009f9190611086565b610329565b6040516100b19190611064565b60405180910390f35b3480156100c657600080fd5b506100e160048036038101906100dc91906110ee565b61038f565b6040516100ee9190611064565b60405180910390f35b610111600480360381019061010c91906110ee565b6103b7565b60405161011e9190611064565b60405180910390f35b610141600480360381019061013c91906110ee565b6103df565b60405161014e9190611064565b60405180910390f35b61015f610e11565b610167610407565b60005a90506101ad8560000160208101906101829190611195565b86602001357f000000000000000000000000afd306005f5d1a8537be4960e6d23907b5b9383f610456565b60007f000000000000000000000000afd306005f5d1a8537be4960e6d23907b5b9383f73ffffffffffffffffffffffffffffffffffffffff1663f95641628780604001906101fb91906111d1565b89806060019061020b9190611234565b8b806080019061021b9190611297565b8c8e60e001602081019061022f9190611195565b8d6040518a63ffffffff1660e01b8152600401610254999897969594939291906120fe565b6000604051808303816000875af1158015610273573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061029c9190612354565b90508060200151836020018181525050806000015183600001819052508560a00135836020015111610303576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fa906123fa565b60405180910390fd5b5a8261030f9190612449565b8360400181815250505050610322610590565b9392505050565b610331610e11565b610339610407565b60005a905061037f8361034b906128a8565b6103798560c00160208101906103619190611195565b8660e00160208101906103749190611195565b61059a565b83610671565b91505061038a610590565b919050565b610397610e11565b61039f610407565b6103a8826108ce565b90506103b2610590565b919050565b6103bf610e11565b6103c7610407565b6103d0826108ce565b90506103da610590565b919050565b6103e7610e11565b6103ef610407565b6103f8826108ce565b9050610402610590565b919050565b60026000540361044c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161044390612907565b60405180910390fd5b6002600081905550565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161461049b5761049683338385610a6e565b61058b565b813410156104de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104d590612973565b60405180910390fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0836040518263ffffffff1660e01b81526004016000604051808303818588803b15801561054657600080fd5b505af115801561055a573d6000803e3d6000fd5b505050505061058a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28284610af7565b5b505050565b6001600081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614610650578273ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016106089190612993565b602060405180830381865afa158015610625573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061064991906129ae565b905061066b565b8173ffffffffffffffffffffffffffffffffffffffff163190505b92915050565b610679610e11565b60008460200151036106c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b790612a27565b60405180910390fd5b60008460a0015103610707576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106fe90612a93565b60405180910390fd5b61073a846000015185602001517f000000000000000000000000afd306005f5d1a8537be4960e6d23907b5b9383f610456565b7f000000000000000000000000afd306005f5d1a8537be4960e6d23907b5b9383f73ffffffffffffffffffffffffffffffffffffffff166308c4b4988560400151866060015187608001516040518463ffffffff1660e01b81526004016107a393929190612d05565b6000604051808303816000875af11580156107c2573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906107eb9190612da9565b600001518160000181905250600061080b8560c001518660e0015161059a565b905083811161084f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161084690612e3e565b60405180910390fd5b6000848261085d9190612449565b90508560a001518110156108a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161089d906123fa565b60405180910390fd5b808360200181815250505a846108bc9190612449565b83604001818152505050509392505050565b6108d6610e11565b60005a905060006040518061010001604052808560000160208101906108fc9190612e5e565b73ffffffffffffffffffffffffffffffffffffffff1681526020018560200135815260200185806040019061093191906111d1565b80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505081526020018580606001906109869190611234565b906109919190612e8b565b81526020018580608001906109a69190611297565b80806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f8201169050808301925050505050505081526020018560a0013581526020018560c0016020810190610a089190612e5e565b73ffffffffffffffffffffffffffffffffffffffff1681526020013373ffffffffffffffffffffffffffffffffffffffff168152509050610a6581610a5f8660c0016020810190610a599190612e5e565b3361059a565b84610671565b92505050919050565b610af1846323b872dd60e01b858585604051602401610a8f93929190612eaf565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610b7d565b50505050565b610b788363a9059cbb60e01b8484604051602401610b16929190612ee6565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610b7d565b505050565b6000610bdf826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610c449092919063ffffffff16565b9050600081511115610c3f5780806020019051810190610bff9190612f24565b610c3e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c3590612fc3565b60405180910390fd5b5b505050565b6060610c538484600085610c5c565b90509392505050565b606082471015610ca1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c9890613055565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051610cca91906130b1565b60006040518083038185875af1925050503d8060008114610d07576040519150601f19603f3d011682016040523d82523d6000602084013e610d0c565b606091505b5091509150610d1d87838387610d29565b92505050949350505050565b60608315610d8b576000835103610d8357610d4385610d9e565b610d82576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d7990613114565b60405180910390fd5b5b829050610d96565b610d958383610dc1565b5b949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b600082511115610dd45781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e089190613178565b60405180910390fd5b60405180606001604052806060815260200160008152602001600081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b60006101008284031215610e6257610e61610e46565b5b81905092915050565b60006101208284031215610e8257610e81610e46565b5b81905092915050565b6000819050919050565b610e9e81610e8b565b8114610ea957600080fd5b50565b600081359050610ebb81610e95565b92915050565b600080600060608486031215610eda57610ed9610e3c565b5b600084013567ffffffffffffffff811115610ef857610ef7610e41565b5b610f0486828701610e4b565b935050602084013567ffffffffffffffff811115610f2557610f24610e41565b5b610f3186828701610e6b565b9250506040610f4286828701610eac565b9150509250925092565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000819050919050565b610f8b81610f78565b82525050565b6000610f9d8383610f82565b60208301905092915050565b6000602082019050919050565b6000610fc182610f4c565b610fcb8185610f57565b9350610fd683610f68565b8060005b83811015611007578151610fee8882610f91565b9750610ff983610fa9565b925050600181019050610fda565b5085935050505092915050565b600060608301600083015184820360008601526110318282610fb6565b91505060208301516110466020860182610f82565b5060408301516110596040860182610f82565b508091505092915050565b6000602082019050818103600083015261107e8184611014565b905092915050565b60006020828403121561109c5761109b610e3c565b5b600082013567ffffffffffffffff8111156110ba576110b9610e41565b5b6110c684828501610e4b565b91505092915050565b600060e082840312156110e5576110e4610e46565b5b81905092915050565b60006020828403121561110457611103610e3c565b5b600082013567ffffffffffffffff81111561112257611121610e41565b5b61112e848285016110cf565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061116282611137565b9050919050565b61117281611157565b811461117d57600080fd5b50565b60008135905061118f81611169565b92915050565b6000602082840312156111ab576111aa610e3c565b5b60006111b984828501611180565b91505092915050565b600080fd5b600080fd5b600080fd5b600080833560016020038436030381126111ee576111ed6111c2565b5b80840192508235915067ffffffffffffffff8211156112105761120f6111c7565b5b60208301925060208202360383131561122c5761122b6111cc565b5b509250929050565b60008083356001602003843603038112611251576112506111c2565b5b80840192508235915067ffffffffffffffff821115611273576112726111c7565b5b60208301925060208202360383131561128f5761128e6111cc565b5b509250929050565b600080833560016020038436030381126112b4576112b36111c2565b5b80840192508235915067ffffffffffffffff8211156112d6576112d56111c7565b5b6020830192506020820236038313156112f2576112f16111cc565b5b509250929050565b600082825260208201905092915050565b600080fd5b82818337505050565b600061132583856112fa565b93507f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8311156113585761135761130b565b5b602083029250611369838584611310565b82840190509392505050565b600082825260208201905092915050565b6000819050919050565b600082825260208201905092915050565b82818337600083830152505050565b6000601f19601f8301169050919050565b60006113cd8385611390565b93506113da8385846113a1565b6113e3836113b0565b840190509392505050565b60006113fb8484846113c1565b90509392505050565b600080fd5b600080fd5b600080fd5b600080833560016020038436030381126114305761142f61140e565b5b83810192508235915060208301925067ffffffffffffffff82111561145857611457611404565b5b60018202360383131561146e5761146d611409565b5b509250929050565b6000602082019050919050565b600061148f8385611375565b9350836020840285016114a184611386565b8060005b878110156114e75784840389526114bc8284611413565b6114c78682846113ee565b95506114d284611476565b935060208b019a5050506001810190506114a5565b50829750879450505050509392505050565b600082825260208201905092915050565b6000819050919050565b6000819050919050565b600061153961153461152f84611137565b611514565b611137565b9050919050565b600061154b8261151e565b9050919050565b600061155d82611540565b9050919050565b61156d81611552565b82525050565b600061157f8383611564565b60208301905092915050565b600061159682611157565b9050919050565b6115a68161158b565b81146115b157600080fd5b50565b6000813590506115c38161159d565b92915050565b60006115d860208401846115b4565b905092915050565b6000602082019050919050565b60006115f983856114f9565b93506116048261150a565b8060005b8581101561163d5761161a82846115c9565b6116248882611573565b975061162f836115e0565b925050600181019050611608565b5085925050509392505050565b60006116596020840184611180565b905092915050565b61166a81611157565b82525050565b60008235600160a00383360303811261168c5761168b61140e565b5b82810191505092915050565b600080833560016020038436030381126116b5576116b461140e565b5b83810192508235915060208301925067ffffffffffffffff8211156116dd576116dc611404565b5b6001820236038313156116f3576116f2611409565b5b509250929050565b600082825260208201905092915050565b600061171883856116fb565b93506117258385846113a1565b61172e836113b0565b840190509392505050565b600080833560016020038436030381126117565761175561140e565b5b83810192508235915060208301925067ffffffffffffffff82111561177e5761177d611404565b5b60208202360383131561179457611793611409565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b60006117c38383611661565b60208301905092915050565b6000602082019050919050565b60006117e8838561179c565b93506117f3826117ad565b8060005b8581101561182c57611809828461164a565b61181388826117b7565b975061181e836117cf565b9250506001810190506117f7565b5085925050509392505050565b600080833560016020038436030381126118565761185561140e565b5b83810192508235915060208301925067ffffffffffffffff82111561187e5761187d611404565b5b60208202360383131561189457611893611409565b5b509250929050565b60006118a88385610f57565b93507f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8311156118db576118da61130b565b5b6020830292506118ec838584611310565b82840190509392505050565b61190181610f78565b811461190c57600080fd5b50565b60008135905061191e816118f8565b92915050565b6000611933602084018461190f565b905092915050565b600060a0830161194e6000840184611698565b858303600087015261196183828461170c565b925050506119726020840184611698565b858303602087015261198583828461170c565b925050506119966040840184611739565b85830360408701526119a98382846117dc565b925050506119ba6060840184611839565b85830360608701526119cd83828461189c565b925050506119de6080840184611924565b6119eb6080860182610f82565b508091505092915050565b60008235600160c003833603038112611a1257611a1161140e565b5b82810191505092915050565b60008083356001602003843603038112611a3b57611a3a61140e565b5b83810192508235915060208301925067ffffffffffffffff821115611a6357611a62611404565b5b604082023603831315611a7957611a78611409565b5b509250929050565b600082825260208201905092915050565b6000819050919050565b60006bffffffffffffffffffffffff82169050919050565b611abd81611a9c565b8114611ac857600080fd5b50565b600081359050611ada81611ab4565b92915050565b6000611aef6020840184611acb565b905092915050565b611b0081611a9c565b82525050565b60408201611b17600083018361164a565b611b246000850182611661565b50611b326020830183611ae0565b611b3f6020850182611af7565b50505050565b6000611b518383611b06565b60408301905092915050565b600082905092915050565b6000604082019050919050565b6000611b818385611a81565b9350611b8c82611a92565b8060005b85811015611bc557611ba28284611b5d565b611bac8882611b45565b9750611bb783611b68565b925050600181019050611b90565b5085925050509392505050565b600060c08301611be56000840184611924565b611bf26000860182610f82565b50611c006020840184611924565b611c0d6020860182610f82565b50611c1b6040840184611a1e565b8583036040870152611c2e838284611b75565b92505050611c3f6060840184611924565b611c4c6060860182610f82565b50611c5a6080840184611924565b611c676080860182610f82565b50611c7560a0840184611698565b85830360a0870152611c8883828461170c565b925050508091505092915050565b600082356001606003833603038112611cb257611cb161140e565b5b82810191505092915050565b600060608301611cd16000840184611739565b8583036000870152611ce48382846117dc565b92505050611cf56020840184611739565b8583036020870152611d088382846117dc565b92505050611d196040840184611739565b8583036040870152611d2c8382846117dc565b925050508091505092915050565b60008115159050919050565b611d4f81611d3a565b8114611d5a57600080fd5b50565b600081359050611d6c81611d46565b92915050565b6000611d816020840184611d5d565b905092915050565b611d9281611d3a565b82525050565b6000611da382611157565b9050919050565b611db381611d98565b8114611dbe57600080fd5b50565b600081359050611dd081611daa565b92915050565b6000611de56020840184611dc1565b905092915050565b6000611df882611540565b9050919050565b611e0881611ded565b82525050565b60008235600160c003833603038112611e2a57611e2961140e565b5b82810191505092915050565b600065ffffffffffff82169050919050565b611e5181611e36565b8114611e5c57600080fd5b50565b600081359050611e6e81611e48565b92915050565b6000611e836020840184611e5f565b905092915050565b611e9481611e36565b82525050565b600063ffffffff82169050919050565b611eb381611e9a565b8114611ebe57600080fd5b50565b600081359050611ed081611eaa565b92915050565b6000611ee56020840184611ec1565b905092915050565b611ef681611e9a565b82525050565b600060c08301611f0f6000840184611e74565b611f1c6000860182611e8b565b50611f2a6020840184611ed6565b611f376020860182611eed565b50611f456040840184611924565b611f526040860182610f82565b50611f606060840184611924565b611f6d6060860182610f82565b50611f7b6080840184611924565b611f886080860182610f82565b50611f9660a0840184611739565b85830360a0870152611fa98382846117dc565b925050508091505092915050565b60006101208301611fcb600084018461164a565b611fd86000860182611661565b50611fe66020840184611670565b8482036020860152611ff8828261193b565b91505061200860408401846119f6565b848203604086015261201a8282611bd2565b91505061202a6060840184611c96565b848203606086015261203c8282611cbe565b91505061204c6080840184611d72565b6120596080860182611d89565b5061206760a0840184611dd6565b61207460a0860182611dff565b5061208260c084018461164a565b61208f60c0860182611661565b5061209d60e0840184611e0e565b84820360e08601526120af8282611efc565b9150506120c0610100840184611e0e565b8482036101008601526120d38282611efc565b9150508091505092915050565b6120e981611157565b82525050565b6120f881610e8b565b82525050565b600060c0820190508181036000830152612119818b8d611319565b9050818103602083015261212e81898b611483565b905081810360408301526121438187896115ed565b905081810360608301526121578186611fb7565b905061216660808301856120e0565b61217360a08301846120ef565b9a9950505050505050505050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6121be826113b0565b810181811067ffffffffffffffff821117156121dd576121dc612186565b5b80604052505050565b60006121f0610e32565b90506121fc82826121b5565b919050565b600080fd5b600080fd5b600067ffffffffffffffff82111561222657612225612186565b5b602082029050602081019050919050565b600080fd5b60008151905061224b816118f8565b92915050565b600061226461225f8461220b565b6121e6565b9050808382526020820190506020840283018581111561228757612286612237565b5b835b818110156122b0578061229c888261223c565b845260208401935050602081019050612289565b5050509392505050565b600082601f8301126122cf576122ce612206565b5b81516122df848260208601612251565b91505092915050565b6000604082840312156122fe576122fd612181565b5b61230860406121e6565b9050600082015167ffffffffffffffff81111561232857612327612201565b5b612334848285016122ba565b60008301525060206123488482850161223c565b60208301525092915050565b60006020828403121561236a57612369610e3c565b5b600082015167ffffffffffffffff81111561238857612387610e41565b5b612394848285016122e8565b91505092915050565b600082825260208201905092915050565b7f494e53554646494349454e545f4f555400000000000000000000000000000000600082015250565b60006123e460108361239d565b91506123ef826123ae565b602082019050919050565b60006020820190508181036000830152612413816123d7565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061245482610f78565b915061245f83610f78565b92508282039050818111156124775761247661241a565b5b92915050565b600067ffffffffffffffff82111561249857612497612186565b5b602082029050602081019050919050565b60006124bc6124b78461247d565b6121e6565b905080838252602082019050602084028301858111156124df576124de612237565b5b835b8181101561250857806124f48882610eac565b8452602084019350506020810190506124e1565b5050509392505050565b600082601f83011261252757612526612206565b5b81356125378482602086016124a9565b91505092915050565b600067ffffffffffffffff82111561255b5761255a612186565b5b602082029050602081019050919050565b600080fd5b600067ffffffffffffffff82111561258c5761258b612186565b5b612595826113b0565b9050602081019050919050565b60006125b56125b084612571565b6121e6565b9050828152602081018484840111156125d1576125d061256c565b5b6125dc8482856113a1565b509392505050565b600082601f8301126125f9576125f8612206565b5b81356126098482602086016125a2565b91505092915050565b600061262561262084612540565b6121e6565b9050808382526020820190506020840283018581111561264857612647612237565b5b835b8181101561268f57803567ffffffffffffffff81111561266d5761266c612206565b5b80860161267a89826125e4565b8552602085019450505060208101905061264a565b5050509392505050565b600082601f8301126126ae576126ad612206565b5b81356126be848260208601612612565b91505092915050565b600067ffffffffffffffff8211156126e2576126e1612186565b5b602082029050602081019050919050565b6000612706612701846126c7565b6121e6565b9050808382526020820190506020840283018581111561272957612728612237565b5b835b81811015612752578061273e88826115b4565b84526020840193505060208101905061272b565b5050509392505050565b600082601f83011261277157612770612206565b5b81356127818482602086016126f3565b91505092915050565b600061010082840312156127a1576127a0612181565b5b6127ac6101006121e6565b905060006127bc84828501611180565b60008301525060206127d08482850161190f565b602083015250604082013567ffffffffffffffff8111156127f4576127f3612201565b5b61280084828501612512565b604083015250606082013567ffffffffffffffff81111561282457612823612201565b5b61283084828501612699565b606083015250608082013567ffffffffffffffff81111561285457612853612201565b5b6128608482850161275c565b60808301525060a06128748482850161190f565b60a08301525060c061288884828501611180565b60c08301525060e061289c84828501611180565b60e08301525092915050565b60006128b4368361278a565b9050919050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b60006128f1601f8361239d565b91506128fc826128bb565b602082019050919050565b60006020820190508181036000830152612920816128e4565b9050919050565b7f494e53554646494349454e545f45544800000000000000000000000000000000600082015250565b600061295d60108361239d565b915061296882612927565b602082019050919050565b6000602082019050818103600083015261298c81612950565b9050919050565b60006020820190506129a860008301846120e0565b92915050565b6000602082840312156129c4576129c3610e3c565b5b60006129d28482850161223c565b91505092915050565b7f494e56414c49445f494e5055545f414d4f554e54000000000000000000000000600082015250565b6000612a1160148361239d565b9150612a1c826129db565b602082019050919050565b60006020820190508181036000830152612a4081612a04565b9050919050565b7f494e56414c49445f4f55545055545f414d4f554e540000000000000000000000600082015250565b6000612a7d60158361239d565b9150612a8882612a47565b602082019050919050565b60006020820190508181036000830152612aac81612a70565b9050919050565b600081519050919050565b6000819050602082019050919050565b612ad781610e8b565b82525050565b6000612ae98383612ace565b60208301905092915050565b6000602082019050919050565b6000612b0d82612ab3565b612b1781856112fa565b9350612b2283612abe565b8060005b83811015612b53578151612b3a8882612add565b9750612b4583612af5565b925050600181019050612b26565b5085935050505092915050565b600081519050919050565b6000819050602082019050919050565b600081519050919050565b60005b83811015612ba4578082015181840152602081019050612b89565b60008484015250505050565b6000612bbb82612b7b565b612bc58185611390565b9350612bd5818560208601612b86565b612bde816113b0565b840191505092915050565b6000612bf58383612bb0565b905092915050565b6000602082019050919050565b6000612c1582612b60565b612c1f8185611375565b935083602082028501612c3185612b6b565b8060005b85811015612c6d5784840389528151612c4e8582612be9565b9450612c5983612bfd565b925060208a01995050600181019050612c35565b50829750879550505050505092915050565b600081519050919050565b6000819050602082019050919050565b6000602082019050919050565b6000612cb282612c7f565b612cbc81856114f9565b9350612cc783612c8a565b8060005b83811015612cf8578151612cdf8882611573565b9750612cea83612c9a565b925050600181019050612ccb565b5085935050505092915050565b60006060820190508181036000830152612d1f8186612b02565b90508181036020830152612d338185612c0a565b90508181036040830152612d478184612ca7565b9050949350505050565b600060208284031215612d6757612d66612181565b5b612d7160206121e6565b9050600082015167ffffffffffffffff811115612d9157612d90612201565b5b612d9d848285016122ba565b60008301525092915050565b600060208284031215612dbf57612dbe610e3c565b5b600082015167ffffffffffffffff811115612ddd57612ddc610e41565b5b612de984828501612d51565b91505092915050565b7f494e56414c49445f4e45575f42414c414e434500000000000000000000000000600082015250565b6000612e2860138361239d565b9150612e3382612df2565b602082019050919050565b60006020820190508181036000830152612e5781612e1b565b9050919050565b600060208284031215612e7457612e73610e3c565b5b6000612e82848285016115b4565b91505092915050565b6000612e98368484612612565b905092915050565b612ea981610f78565b82525050565b6000606082019050612ec460008301866120e0565b612ed160208301856120e0565b612ede6040830184612ea0565b949350505050565b6000604082019050612efb60008301856120e0565b612f086020830184612ea0565b9392505050565b600081519050612f1e81611d46565b92915050565b600060208284031215612f3a57612f39610e3c565b5b6000612f4884828501612f0f565b91505092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b6000612fad602a8361239d565b9150612fb882612f51565b604082019050919050565b60006020820190508181036000830152612fdc81612fa0565b9050919050565b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b600061303f60268361239d565b915061304a82612fe3565b604082019050919050565b6000602082019050818103600083015261306e81613032565b9050919050565b600081905092915050565b600061308b82612b7b565b6130958185613075565b93506130a5818560208601612b86565b80840191505092915050565b60006130bd8284613080565b915081905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b60006130fe601d8361239d565b9150613109826130c8565b602082019050919050565b6000602082019050818103600083015261312d816130f1565b9050919050565b600081519050919050565b600061314a82613134565b613154818561239d565b9350613164818560208601612b86565b61316d816113b0565b840191505092915050565b60006020820190508181036000830152613192818461313f565b90509291505056fea26469706673582212209a8964b1dedbc5501d39d742a92a0ba74d5029fe61b2c3b8d58a7ba7425c719b64736f6c63430008110033
Verified Source Code Full Match
Compiler: v0.8.17+commit.8df45f5f
EVM: london
Optimization: No
IVotes.sol 61 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.0;
/**
* @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
*
* _Available since v4.5._
*/
interface IVotes {
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/**
* @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).
*/
function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*/
function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) external view returns (address);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) external;
/**
* @dev Delegates votes from signer to `delegatee`.
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
ERC2771Context.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol)
pragma solidity ^0.8.9;
import "../utils/Context.sol";
/**
* @dev Context variant with ERC2771 support.
*/
abstract contract ERC2771Context is Context {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable _trustedForwarder;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address trustedForwarder) {
_trustedForwarder = trustedForwarder;
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == _trustedForwarder;
}
function _msgSender() internal view virtual override returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
/// @solidity memory-safe-assembly
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return super._msgSender();
}
}
function _msgData() internal view virtual override returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return super._msgData();
}
}
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
IFolio.sol 211 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IVotes } from "@openzeppelin/contracts/governance/utils/IVotes.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
interface IFolio is IERC20 {
// === Events ===
event AuctionApproved(uint256 indexed auctionId, address indexed from, address indexed to, Auction auction);
event AuctionOpened(uint256 indexed auctionId, Auction auction);
event AuctionBid(uint256 indexed auctionId, uint256 sellAmount, uint256 buyAmount);
event AuctionClosed(uint256 indexed auctionId);
event FolioFeePaid(address indexed recipient, uint256 amount);
event ProtocolFeePaid(address indexed recipient, uint256 amount);
event BasketTokenAdded(address indexed token);
event BasketTokenRemoved(address indexed token);
event TVLFeeSet(uint256 newFee, uint256 feeAnnually);
event MintFeeSet(uint256 newFee);
event FeeRecipientSet(address indexed recipient, uint96 portion);
event AuctionDelaySet(uint256 newAuctionDelay);
event AuctionLengthSet(uint256 newAuctionLength);
event MandateSet(string newMandate);
event FolioKilled();
// === Errors ===
error Folio__FolioKilled();
error Folio__Unauthorized();
error Folio__EmptyAssets();
error Folio__BasketModificationFailed();
error Folio__FeeRecipientInvalidAddress();
error Folio__FeeRecipientInvalidFeeShare();
error Folio__BadFeeTotal();
error Folio__TVLFeeTooHigh();
error Folio__TVLFeeTooLow();
error Folio__MintFeeTooHigh();
error Folio__ZeroInitialShares();
error Folio__InvalidAsset();
error Folio__InvalidAssetAmount(address asset);
error Folio__InvalidAuctionLength();
error Folio__InvalidSellLimit();
error Folio__InvalidBuyLimit();
error Folio__AuctionCannotBeOpened();
error Folio__AuctionCannotBeOpenedPermissionlesslyYet();
error Folio__AuctionNotOngoing();
error Folio__AuctionCollision();
error Folio__InvalidPrices();
error Folio__AuctionTimeout();
error Folio__SlippageExceeded();
error Folio__InsufficientBalance();
error Folio__InsufficientBid();
error Folio__ExcessiveBid();
error Folio__InvalidAuctionTokens();
error Folio__InvalidAuctionDelay();
error Folio__InvalidAuctionTTL();
error Folio__TooManyFeeRecipients();
error Folio__InvalidArrayLengths();
// === Structures ===
struct FolioBasicDetails {
string name;
string symbol;
address[] assets;
uint256[] amounts; // {tok}
uint256 initialShares; // {share}
}
struct FolioAdditionalDetails {
uint256 auctionDelay; // {s}
uint256 auctionLength; // {s}
FeeRecipient[] feeRecipients;
uint256 tvlFee; // D18{1/s}
uint256 mintFee; // D18{1}
string mandate;
}
struct FeeRecipient {
address recipient;
uint96 portion; // D18{1}
}
struct BasketRange {
uint256 spot; // D27{buyTok/share}
uint256 low; // D27{buyTok/share} inclusive
uint256 high; // D27{buyTok/share} inclusive
}
struct Prices {
uint256 start; // D27{buyTok/sellTok}
uint256 end; // D27{buyTok/sellTok}
}
/// Auction states:
/// - APPROVED: start == 0 && end == 0
/// - OPEN: block.timestamp >= start && block.timestamp <= end
/// - CLOSED: block.timestamp > end
struct Auction {
uint256 id;
IERC20 sell;
IERC20 buy;
BasketRange sellLimit; // D27{sellTok/share} min ratio of sell token in the basket, inclusive
BasketRange buyLimit; // D27{buyTok/share} max ratio of buy token in the basket, exclusive
Prices prices; // D27{buyTok/sellTok}
uint256 availableAt; // {s} inclusive
uint256 launchTimeout; // {s} inclusive
uint256 start; // {s} inclusive
uint256 end; // {s} inclusive
// === Gas optimization ===
uint256 k; // D18{1} price = startPrice * e ^ -kt
}
function distributeFees() external;
function folio() external view returns (address[] memory _assets, uint256[] memory _amounts);
function toAssets(uint256 shares, Math.Rounding rounding) external view returns (address[] memory _assets, uint256[] memory _amounts);
function AUCTION_APPROVER() external view returns (bytes32);
function AUCTION_LAUNCHER() external view returns (bytes32);
function BRAND_MANAGER() external view returns (bytes32);
function mint(uint256 shares, address receiver) external returns (address[] memory _assets, uint256[] memory _amounts);
function redeem(
uint256 shares,
address receiver,
address[] calldata assets,
uint256[] calldata minAmountsOut
) external returns (uint256[] memory _amounts);
}
interface IGovernanceDeployer {
struct GovParams {
// Basic Parameters
uint48 votingDelay; // {s}
uint32 votingPeriod; // {s}
uint256 proposalThreshold; // D18{1}
uint256 quorumPercent; // in percent, e.g 4 for 4%
uint256 timelockDelay; // {s}
// Roles
address[] guardians; // Canceller Role
}
function deployGovernanceWithTimelock(
IGovernanceDeployer.GovParams calldata govParams,
IVotes stToken
) external returns (address governor, address timelock);
}
struct GovRoles {
address[] existingTradeProposers;
address[] tradeLaunchers;
address[] vibesOfficers;
}
interface IFolioDeployer {
error FolioDeployer__LengthMismatch();
event FolioDeployed(address indexed folioOwner, address indexed folio, address folioAdmin);
event GovernedFolioDeployed(
address indexed stToken,
address indexed folio,
address ownerGovernor,
address ownerTimelock,
address tradingGovernor,
address tradingTimelock
);
function folioImplementation() external view returns (address);
function deployFolio(
IFolio.FolioBasicDetails calldata basicDetails,
IFolio.FolioAdditionalDetails calldata additionalDetails,
address owner,
address[] memory auctionApprovers,
address[] memory auctionLaunchers,
address[] memory brandManagers,
bytes32 deploymentNonce
) external returns (address folio, address proxyAdmin);
function deployGovernedFolio(
IVotes stToken,
IFolio.FolioBasicDetails calldata basicDetails,
IFolio.FolioAdditionalDetails calldata additionalDetails,
IGovernanceDeployer.GovParams calldata ownerGovParams,
IGovernanceDeployer.GovParams calldata tradingGovParams,
GovRoles calldata govRoles,
bytes32 deploymentNonce
)
external
returns (
address folio,
address proxyAdmin,
address ownerGovernor,
address ownerTimelock,
address tradingGovernor,
address tradingTimelock
);
}
IRTokenZapper.sol 47 lines
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct Call {
address to;
bytes data;
uint256 value;
}
struct ZapERC20Params {
// Token to zap
IERC20 tokenIn;
// Total amount to zap / pull from user
uint256 amountIn;
// Weiroll code to execute to produce 'amountOut' of 'tokenOut'
bytes32[] commands;
bytes[] state;
IERC20[] tokens;
// RTokens the user requested
uint256 amountOut;
// RToken to issue
IERC20 tokenOut;
}
struct ZapParams {
// Token to zap
address tokenIn;
// Total amount to zap / pull from user
uint256 amountIn;
// Weiroll code to execute to produce 'amountOut' of 'tokenOut'
bytes32[] commands;
bytes[] state;
IERC20[] tokens;
// RTokens the user requested
uint256 amountOut;
// RToken to issue
address tokenOut;
address recipient;
}
IWrappedNative.sol 9 lines
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
interface IWrappedNative {
function deposit() external payable;
function withdraw(uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
}
PreventTampering.sol 40 lines
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
abstract contract PreventTampering {
modifier revertOnCodeHashChange() {
bytes32 hashBefore;
assembly {
hashBefore := extcodehash(address())
}
_;
bytes32 hashPostExecution;
assembly {
hashPostExecution := extcodehash(address())
}
require(hashPostExecution == hashBefore, "PreventTampering: Code has changed");
}
}
contract SelfDestruct {
function destroy() external {
selfdestruct(payable(msg.sender));
}
function doNothing() external {}
}
contract TestPreventTampering is PreventTampering {
function shouldNotRevert() external {
SelfDestruct selfDestruct = new SelfDestruct();
address(selfDestruct).delegatecall(abi.encodeWithSelector(selfDestruct.destroy.selector));
}
function shouldRevert() revertOnCodeHashChange() external {
SelfDestruct selfDestruct = new SelfDestruct();
address(selfDestruct).delegatecall(abi.encodeWithSelector(selfDestruct.destroy.selector));
}
function markedRevertOnCodeHashChangeDontRevert() revertOnCodeHashChange() external {
SelfDestruct selfDestruct = new SelfDestruct();
address(selfDestruct).delegatecall(abi.encodeWithSelector(selfDestruct.doNothing.selector));
}
}
CommandBuilder.sol 190 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
library CommandBuilder {
uint256 constant IDX_VARIABLE_LENGTH = 0x80;
uint256 constant IDX_VALUE_MASK = 0x7f;
uint256 constant IDX_END_OF_ARGS = 0xff;
uint256 constant IDX_USE_STATE = 0xfe;
function buildInputs(
bytes[] memory state,
bytes4 selector,
bytes32 indices
) internal view returns (bytes memory ret) {
uint256 count; // Number of bytes in whole ABI encoded message
uint256 free; // Pointer to first free byte in tail part of message
bytes memory stateData; // Optionally encode the current state if the call requires it
uint256 idx;
// Determine the length of the encoded data
for (uint256 i; i < 32;) {
idx = uint8(indices[i]);
if (idx == IDX_END_OF_ARGS) break;
if (idx & IDX_VARIABLE_LENGTH != 0) {
if (idx == IDX_USE_STATE) {
if (stateData.length == 0) {
stateData = abi.encode(state);
}
count += stateData.length;
} else {
// Add the size of the value, rounded up to the next word boundary, plus space for pointer and length
uint256 arglen = state[idx & IDX_VALUE_MASK].length;
require(
arglen % 32 == 0,
"Dynamic state variables must be a multiple of 32 bytes"
);
count += arglen + 32;
}
} else {
require(
state[idx & IDX_VALUE_MASK].length == 32,
"Static state variables must be 32 bytes"
);
count += 32;
}
unchecked{free += 32;}
unchecked{++i;}
}
// Encode it
ret = new bytes(count + 4);
assembly {
mstore(add(ret, 32), selector)
}
count = 0;
for (uint256 i; i < 32;) {
idx = uint8(indices[i]);
if (idx == IDX_END_OF_ARGS) break;
if (idx & IDX_VARIABLE_LENGTH != 0) {
if (idx == IDX_USE_STATE) {
assembly {
mstore(add(add(ret, 36), count), free)
}
memcpy(stateData, 32, ret, free + 4, stateData.length - 32);
free += stateData.length - 32;
} else {
uint256 arglen = state[idx & IDX_VALUE_MASK].length;
// Variable length data; put a pointer in the slot and write the data at the end
assembly {
mstore(add(add(ret, 36), count), free)
}
memcpy(
state[idx & IDX_VALUE_MASK],
0,
ret,
free + 4,
arglen
);
free += arglen;
}
} else {
// Fixed length data; write it directly
bytes memory statevar = state[idx & IDX_VALUE_MASK];
assembly {
mstore(add(add(ret, 36), count), mload(add(statevar, 32)))
}
}
unchecked{count += 32;}
unchecked{++i;}
}
}
function writeOutputs(
bytes[] memory state,
bytes1 index,
bytes memory output
) internal view returns (bytes[] memory) {
uint256 idx = uint8(index);
if (idx == IDX_END_OF_ARGS) return state;
if (idx & IDX_VARIABLE_LENGTH != 0) {
if (idx == IDX_USE_STATE) {
state = abi.decode(output, (bytes[]));
} else {
// Check the first field is 0x20 (because we have only a single return value)
uint256 argptr;
assembly {
argptr := mload(add(output, 32))
}
require(
argptr == 32,
"Only one return value permitted (variable)"
);
assembly {
// Overwrite the first word of the return data with the length - 32
mstore(add(output, 32), sub(mload(output), 32))
// Insert a pointer to the return data, starting at the second word, into state
mstore(
add(add(state, 32), mul(and(idx, IDX_VALUE_MASK), 32)),
add(output, 32)
)
}
}
} else {
require(output.length >= 32, "Return at least 32 bytes");
// Single word
// require(
// output.length == 32,
// "Only one return value permitted (static)"
// );
// There are rare instances of contracts whoes ABI indicate a single word return returning more than 1 word
// returndata buffers containing a single word of data.
if (output.length > 32) {
// Truncate returndata to proper size
bytes memory newOutput = new bytes(32);
memcpy(output, 0, newOutput, 0, output.length);
output = newOutput;
}
state[idx & IDX_VALUE_MASK] = output;
}
return state;
}
function writeTuple(
bytes[] memory state,
bytes1 index,
bytes memory output
) internal view {
uint256 idx = uint256(uint8(index));
if (idx == IDX_END_OF_ARGS) return;
bytes memory entry = state[idx] = new bytes(output.length + 32);
memcpy(output, 0, entry, 32, output.length);
assembly {
let l := mload(output)
mstore(add(entry, 32), l)
}
}
function memcpy(
bytes memory src,
uint256 srcidx,
bytes memory dest,
uint256 destidx,
uint256 len
) internal view {
assembly {
pop(
staticcall(
gas(),
4,
add(add(src, 32), srcidx),
len,
add(add(dest, 32), destidx),
len
)
)
}
}
}
VM.sol 128 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./CommandBuilder.sol";
abstract contract VM {
using CommandBuilder for bytes[];
uint256 constant FLAG_CT_DELEGATECALL = 0x00;
uint256 constant FLAG_CT_CALL = 0x01;
uint256 constant FLAG_CT_STATICCALL = 0x02;
uint256 constant FLAG_CT_VALUECALL = 0x03;
uint256 constant FLAG_CT_MASK = 0x03;
uint256 constant FLAG_EXTENDED_COMMAND = 0x80;
uint256 constant FLAG_TUPLE_RETURN = 0x40;
uint256 constant SHORT_COMMAND_FILL = 0x000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
address immutable self;
error ExecutionFailed(
uint256 command_index,
address target,
string message
);
constructor() {
self = address(this);
}
// function callExtension(
// bytes memory data
// ) virtual internal returns (bool success, bytes memory outdata);
function _execute(bytes32[] calldata commands, bytes[] memory state)
internal returns (bytes[] memory)
{
bytes32 command;
uint256 flags;
bytes32 indices;
bool success;
bytes memory outdata;
uint256 commandsLength = commands.length;
for (uint256 i; i < commandsLength;) {
command = commands[i];
flags = uint256(uint8(bytes1(command << 32)));
if (flags & FLAG_EXTENDED_COMMAND != 0) {
indices = commands[i++];
} else {
indices = bytes32(uint256(command << 40) | SHORT_COMMAND_FILL);
}
if (flags & FLAG_CT_MASK == FLAG_CT_DELEGATECALL) {
(success, outdata) = address(uint160(uint256(command))).delegatecall( // target
// inputs
state.buildInputs(
//selector
bytes4(command),
indices
)
);
} else if (flags & FLAG_CT_MASK == FLAG_CT_CALL) {
(success, outdata) = address(uint160(uint256(command))).call( // target
// inputs
state.buildInputs(
//selector
bytes4(command),
indices
)
);
} else if (flags & FLAG_CT_MASK == FLAG_CT_STATICCALL) {
(success, outdata) = address(uint160(uint256(command))).staticcall( // target
// inputs
state.buildInputs(
//selector
bytes4(command),
indices
)
);
} else if (flags & FLAG_CT_MASK == FLAG_CT_VALUECALL) {
uint256 calleth;
bytes memory v = state[uint8(bytes1(indices))];
require(v.length == 32, "_execute: value call has no value indicated.");
assembly {
calleth := mload(add(v, 0x20))
}
(success, outdata) = address(uint160(uint256(command))).call{ // target
value: calleth
}(
// inputs
state.buildInputs(
//selector
bytes4(command),
bytes32(uint256(indices << 8) | CommandBuilder.IDX_END_OF_ARGS)
)
);
} else {
revert("Invalid calltype");
}
if (!success) {
if (outdata.length > 0) {
assembly {
outdata := add(outdata, 68)
}
}
revert ExecutionFailed({
command_index: i,
target: address(uint160(uint256(command))),
message: string(outdata)
});
}
if (flags & FLAG_TUPLE_RETURN != 0) {
state.writeTuple(bytes1(command << 88), outdata);
} else {
state = state.writeOutputs(bytes1(command << 88), outdata);
}
unchecked{++i;}
}
return state;
}
}
Zapper2.sol 147 lines
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ERC2771Context } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
import { IWrappedNative } from "./IWrappedNative.sol";
import { VM } from "./weiroll/VM.sol";
import { PreventTampering } from "./PreventTampering.sol";
import { ZapParams, ZapERC20Params } from "./IRTokenZapper.sol";
import { ZapperExecutor, DeployFolioConfig, ExecuteDeployOutput } from "./ZapperExecutor.sol";
struct ZapperOutput {
uint256[] dust;
uint256 amountOut;
uint256 gasUsed;
}
contract Zapper2 is ReentrancyGuard {
IWrappedNative internal immutable wrappedNative;
ZapperExecutor internal immutable zapperExecutor;
constructor(
IWrappedNative wrappedNative_,
ZapperExecutor executor_
) {
wrappedNative = wrappedNative_;
zapperExecutor = executor_;
}
receive() external payable {}
function zap(ZapParams calldata params) external payable nonReentrant returns (ZapperOutput memory) {
uint256 startGas = gasleft();
return zapInner(params, balanceOf(params.tokenOut, params.recipient), startGas);
}
function zapDeploy(
ZapParams calldata params,
DeployFolioConfig calldata config,
bytes32 nonce
) external payable nonReentrant returns (ZapperOutput memory out) {
uint256 startGas = gasleft();
pullFundsFromSender(params.tokenIn, params.amountIn, address(zapperExecutor));
// STEP 1: Execute
ExecuteDeployOutput memory deployOutput = zapperExecutor.executeDeploy(
params.commands,
params.state,
params.tokens,
config,
params.recipient,
nonce
);
out.amountOut = deployOutput.amountOut;
out.dust = deployOutput.dust;
require(out.amountOut > params.amountOut, "INSUFFICIENT_OUT");
out.gasUsed = startGas - gasleft();
}
function validateTokenOut(address tokenOut) private {
uint256 codeSizeTokenOut = 0;
assembly {
codeSizeTokenOut := extcodesize(tokenOut)
}
require(codeSizeTokenOut == 0, "RETRY");
}
function zapInner(ZapParams memory params, uint256 initialBalance, uint256 startGas) private returns (ZapperOutput memory out) {
require(params.amountIn != 0, "INVALID_INPUT_AMOUNT");
require(params.amountOut != 0, "INVALID_OUTPUT_AMOUNT");
pullFundsFromSender(params.tokenIn, params.amountIn, address(zapperExecutor));
// STEP 1: Execute
out.dust = zapperExecutor.execute(
params.commands,
params.state,
params.tokens
).dust;
// STEP 2: Verify that the user has gotten the tokens they requested
uint256 newBalance = balanceOf(params.tokenOut, params.recipient);
require(newBalance > initialBalance, "INVALID_NEW_BALANCE");
uint256 difference = newBalance - initialBalance;
require(difference >= params.amountOut, "INSUFFICIENT_OUT");
out.amountOut = difference;
out.gasUsed = startGas - gasleft();
}
function pullFundsFromSender(
address token,
uint256 amount,
address to
) private {
if (token != address(0)) {
SafeERC20.safeTransferFrom(IERC20(token), msg.sender, to, amount);
} else {
require(msg.value >= amount, "INSUFFICIENT_ETH");
wrappedNative.deposit{ value: amount }();
SafeERC20.safeTransfer(IERC20(address(wrappedNative)), to, amount);
}
}
function balanceOf(address token, address account) private view returns (uint256) {
if (token != address(0)) {
// Check if token address contains bytecode
return IERC20(token).balanceOf(account);
} else {
return account.balance;
}
}
/** Stubs for old interface */
function translateOldStyleZap(ZapERC20Params calldata params) private returns (ZapperOutput memory) {
uint256 startGas = gasleft();
ZapParams memory zapParams = ZapParams({
tokenIn: address(params.tokenIn),
amountIn: params.amountIn,
commands: params.commands,
state: params.state,
tokens: params.tokens,
amountOut: params.amountOut,
tokenOut: address(params.tokenOut),
recipient: msg.sender
});
return zapInner(zapParams, balanceOf(address(params.tokenOut), msg.sender), startGas);
}
function zapERC20(ZapERC20Params calldata params) external nonReentrant returns (ZapperOutput memory) {
return translateOldStyleZap(params);
}
function zapETH(ZapERC20Params calldata params) external payable nonReentrant returns (ZapperOutput memory) {
return translateOldStyleZap(params);
}
function zapToETH(ZapERC20Params calldata params) external payable nonReentrant returns (ZapperOutput memory) {
return translateOldStyleZap(params);
}
}
ZapperExecutor.sol 173 lines
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { VM } from "./weiroll/VM.sol";
import { PreventTampering } from "./PreventTampering.sol";
import { IFolio, IVotes, GovRoles, IFolioDeployer, IGovernanceDeployer } from "./IFolio.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
struct DeployFolioConfig {
address deployer;
IFolio.FolioBasicDetails basicDetails;
IFolio.FolioAdditionalDetails additionalDetails;
GovRoles govRoles;
bool isGoverned;
IVotes stToken;
address owner;
IGovernanceDeployer.GovParams ownerGovParams;
IGovernanceDeployer.GovParams tradingGovParams;
}
struct ExecuteOutput {
uint256[] dust;
}
struct ExecuteDeployOutput {
uint256[] dust;
uint256 amountOut;
}
contract ZapperExecutor is VM, PreventTampering {
receive() external payable {}
function add(
uint256 a,
uint256 b
) external pure returns (uint256) {
return a + b;
}
function sub(
uint256 a,
uint256 b
) external pure returns (uint256) {
return a - b;
}
function fpMul(
uint256 a,
uint256 b,
uint256 scale
) external pure returns (uint256) {
return (a * b) / scale;
}
function assertLarger(
uint256 a,
uint256 b
) external pure returns (bool) {
require(a > b, "!ASSERT_GT");
return true;
}
function assertEqual(
uint256 a,
uint256 b
) external pure returns (bool) {
require(a == b, "!ASSERT_EQ");
return true;
}
/** @dev Main endpoint to call
* @param commands - Weiroll code to execute
* @param state - Intiaial Weiroll state to use
* @param tokens - All tokens used by the Zap in order to calculate dust
*/
function execute(
bytes32[] calldata commands,
bytes[] memory state,
IERC20[] memory tokens
)
revertOnCodeHashChange
public
payable
returns (ExecuteOutput memory out)
{
_execute(commands, state);
out.dust = new uint256[](tokens.length);
for(uint256 i; i < tokens.length; i++) {
out.dust[i] = tokens[i].balanceOf(address(this));
}
}
function executeDeploy(
bytes32[] calldata commands,
bytes[] memory state,
IERC20[] memory tokens,
DeployFolioConfig memory config,
address recipient,
bytes32 nonce
) revertOnCodeHashChange public payable returns (ExecuteDeployOutput memory out) {
_execute(commands, state);
// DSTEP 2: Deploy folio
uint256 initialShares = type(uint256).max;
for (uint256 i = 0; i < config.basicDetails.assets.length; i++) {
uint256 balance = IERC20(config.basicDetails.assets[i]).balanceOf(address(this));
if (balance == 0) {
revert('ZERO BALANCE');
}
uint256 quantityPrShare = config.basicDetails.amounts[i];
if (quantityPrShare == 0) {
revert('ZERO QUANTITY');
}
uint256 shares = balance * 1e18 / quantityPrShare;
if (shares < initialShares) {
initialShares = shares;
}
SafeERC20.safeApprove(IERC20(config.basicDetails.assets[i]), address(config.deployer), 0);
SafeERC20.safeApprove(IERC20(config.basicDetails.assets[i]), address(config.deployer), type(uint256).max);
}
if (initialShares == type(uint256).max) {
revert('NO SHARES');
}
for (uint256 i = 0; i < config.basicDetails.assets.length; i++) {
config.basicDetails.amounts[i] = initialShares * config.basicDetails.amounts[i] / 1e18;
}
config.basicDetails.initialShares = initialShares;
if (config.isGoverned) {
(address folio, , , , ,) = IFolioDeployer(config.deployer).deployGovernedFolio(
config.stToken,
config.basicDetails,
config.additionalDetails,
config.ownerGovParams,
config.tradingGovParams,
config.govRoles,
nonce
);
out.amountOut = IERC20(folio).balanceOf(address(this));
SafeERC20.safeTransfer(IERC20(folio), recipient, out.amountOut);
} else {
(address folio, ) = IFolioDeployer(config.deployer).deployFolio(
config.basicDetails,
config.additionalDetails,
config.owner,
config.govRoles.existingTradeProposers,
config.govRoles.tradeLaunchers,
config.govRoles.vibesOfficers,
nonce
);
out.amountOut = IERC20(folio).balanceOf(address(this));
SafeERC20.safeTransfer(IERC20(folio), recipient, out.amountOut);
}
out.dust = new uint256[](tokens.length);
for(uint256 i; i < tokens.length; i++) {
out.dust[i] = tokens[i].balanceOf(address(this));
SafeERC20.safeTransfer(tokens[i], recipient, out.dust[i]);
}
}
/** @dev Workaround for weiroll not supporting a way to make untyped calls.
* @param to - Address to call
* @param value - Amount of ETH to send
* @param data - Data to send
*/
function rawCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool success, bytes memory out) {
require(msg.sender == address(this), "ZapperExecutor: Only callable by Zapper");
(success, out) = to.call{value: value}(data);
}
}
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
zap 0x0d69de01
tuple params
returns: tuple
zapDeploy 0x7b928330
tuple params
tuple config
bytes32 nonce
returns: tuple
zapERC20 0x52abf338
tuple params
returns: tuple
zapETH 0xda673b16
tuple params
returns: tuple
zapToETH 0xbe355c46
tuple params
returns: tuple
Recent Transactions
No transactions found for this address