Address Contract Verified
Address
0xBd96050a7606771eB51aF02C278CE2AE543ae680
Balance
1.8501 ETH
Nonce
34
Code Size
11076 bytes
Creator
0xA511e076...7eFd at tx 0x385bbdaa...501b9e
Indexed Transactions
0
Contract Bytecode
11076 bytes
0x6080604052600436106101c25760003560e01c8063715018a6116100f7578063b95f8c9a11610095578063e30c397811610064578063e30c3978146105cd578063f2fde38b146105f8578063f7abab9e14610618578063f87ec1e11461062e57600080fd5b8063b95f8c9a146104ed578063b9a059f71461050d578063d43fd4d11461059a578063db61c76e146105ba57600080fd5b80638da5cb5b116100d15780638da5cb5b146104545780639909ccb11461047f578063b0f66ab7146104c1578063b484b050146104d757600080fd5b8063715018a61461040a57806379ba50971461041f578063818cb2331461043457600080fd5b8063540a9f6f1161016457806362a3c0961161013e57806362a3c0961461038a57806367a5a85f146103aa5780636dc5843f146103ca5780636e9dae75146103ea57600080fd5b8063540a9f6f14610307578063564e5ad21461031d5780635c60da1b1461035d57600080fd5b80632dc8f867116101a05780632dc8f8671461028e5780632f2f2d56146102a35780633fc8cef3146102b657806351f1bfa4146102e357600080fd5b80630e7aecb8146101c757806323774af21461021e5780632891721814610261575b600080fd5b3480156101d357600080fd5b506005546101f49073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b34801561022a57600080fd5b506101f46102393660046126a0565b600d6020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b34801561026d57600080fd5b506006546101f49073ffffffffffffffffffffffffffffffffffffffff1681565b6102a161029c3660046126bd565b61064e565b005b6101f46102b1366004612802565b6109d6565b3480156102c257600080fd5b506004546101f49073ffffffffffffffffffffffffffffffffffffffff1681565b3480156102ef57600080fd5b506102f960085481565b604051908152602001610215565b34801561031357600080fd5b506102f960075481565b34801561032957600080fd5b5061034d6103383660046126a0565b600f6020526000908152604090205460ff1681565b6040519015158152602001610215565b34801561036957600080fd5b506003546101f49073ffffffffffffffffffffffffffffffffffffffff1681565b34801561039657600080fd5b506102a16103a536600461286b565b610ae2565b3480156103b657600080fd5b506102f96103c5366004612884565b610b9d565b3480156103d657600080fd5b506102a16103e536600461286b565b610bca565b3480156103f657600080fd5b506102a161040536600461286b565b610c84565b34801561041657600080fd5b506102a1610d38565b34801561042b57600080fd5b506102a1610d4c565b34801561044057600080fd5b506102a161044f36600461286b565b610dc8565b34801561046057600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff166101f4565b34801561048b57600080fd5b506104af61049a3660046126a0565b600c6020526000908152604090205460ff1681565b60405160ff9091168152602001610215565b3480156104cd57600080fd5b506102f9600a5481565b3480156104e357600080fd5b506102f960095481565b3480156104f957600080fd5b506101f46105083660046126a0565b610e40565b34801561051957600080fd5b506105656105283660046126a0565b600e602052600090815260409020805460018201546002830154600384015460048501546005860154600690960154949593949293919290919087565b604080519788526020880196909652948601939093526060850191909152608084015260a083015260c082015260e001610215565b3480156105a657600080fd5b506102f96105b536600461286b565b610f10565b6102a16105c83660046128b0565b610fb8565b3480156105d957600080fd5b5060015473ffffffffffffffffffffffffffffffffffffffff166101f4565b34801561060457600080fd5b506102a16106133660046126a0565b61115d565b34801561062457600080fd5b506102f9600b5481565b34801561063a57600080fd5b506102f9610649366004612884565b61120d565b61065661122e565b82600003610690576040517f3712846700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8481166000908152600d6020526040902054166106ee576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff84166000908152600f602052604090205460ff161561074e576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f23b872dd0000000000000000000000000000000000000000000000000000000081523360048201523060248201526044810184905273ffffffffffffffffffffffffffffffffffffffff8516906323b872dd906064016020604051808303816000875af11580156107c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107eb91906128f2565b5060006107f8858561126f565b9050600061080582611329565b905060006108138284612943565b90508481101561084f576040517f4c1b0f2500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff87166000908152600e60205260409020600201548111156108b1576040517f4c1b0f2500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6108bc87878561133f565b6108c687836113dc565b60008473ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d8060008114610920576040519150601f19603f3d011682016040523d82523d6000602084013e610925565b606091505b5050905080610960576040517f18d16f5f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805133815273ffffffffffffffffffffffffffffffffffffffff878116602083015291810189905260608101849052908916907fbbc79dc7d11fb8ae8de963e009943172807faa4a90c3620ef772f4783e76355f9060800160405180910390a2505050506109d06001600255565b50505050565b60006109e061122e565b600754341015610a1c576040517f5c5d409d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000600754341115610a3857600754610a359034612943565b90505b610a43338585611412565b9150610a4e8261160f565b610a57826116f9565b8015610a7b57610a6b333384846000611827565b610a766007546119da565b610a86565b610a866007546119da565b60405173ffffffffffffffffffffffffffffffffffffffff8316815233907f46960970e01c8cbebf9e58299b0acf8137b299ef06eb6c4f5be2c0443d5e5f229060200160405180910390a250610adc6001600255565b92915050565b610aea611ab6565b6103e8811115610b26576040517f1b72f54100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6009548103610b61576040517f1b72f54100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60098190556040518181527f58bce3b9df0b2ee963bd2d7abf70edb7a2539aedcdd6c3cacc23b6c51a780ef5906020015b60405180910390a150565b6000610ba9838361126f565b90506000610bb682611329565b9050610bc28183612943565b949350505050565b610bd2611ab6565b670de0b6b3a7640000811115610c14576040517f5c5d409d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6007548103610c4f576040517f5c5d409d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60078190556040518181527f02c4eef437790fbe5a1b13f1ca245da317f31c6ab6d67fabd00b87212335ab4e90602001610b92565b610c8c611ab6565b6103e8811115610cc8576040517fa553da3500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6008548103610d03576040517fa553da3500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60088190556040518181527f849da3872c60f3ff8d48046a91cc7ecaea924d0755150f46f522faa382a5975290602001610b92565b610d40611ab6565b610d4a6000611b09565b565b600154339073ffffffffffffffffffffffffffffffffffffffff168114610dbc576040517f118cdaa700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff821660048201526024015b60405180910390fd5b610dc581611b09565b50565b610dd0611ab6565b600a548103610e0b576040517f4df7699d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600a8190556040518181527f184dbd51cc82e3d9b1298732d7b9a25a43118c9103be4adb30b163b97d66694990602001610b92565b600080610ee38373ffffffffffffffffffffffffffffffffffffffff81166000908152600c602090815260409182902054825160609490941b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000168483015260f81b7fff00000000000000000000000000000000000000000000000000000000000000166034840152815160158185030181526035909301909152815191012090565b600354909150610f099073ffffffffffffffffffffffffffffffffffffffff1682611b3a565b9392505050565b60008060075483610f219190612943565b90506000610f2e82611329565b90506000610f3c8284612943565b9050600081600a54610f4e9190612956565b90506000610f7d600a54670de0b6b3a76400006b037790968dc8efffd1000000611b9a9092919063ffffffff16565b90506000610f9482670de0b6b3a764000085611b9a565b9050610fac816b037790968dc8efffd1000000612943565b98975050505050505050565b610fc061122e565b34600003610ffa576040517fa9db4eba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8381166000908152600d602052604090205416611058576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff83166000908152600f602052604090205460ff16156110b8576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6110c53382853486611827565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600e6020908152604091829020825160e08101845281548152600182015492810192909252600281015492820183905260038101546060830181905260048201546080840152600582015460a084015260069091015460c0909201919091521161114e5761114e83611c95565b6111586001600255565b505050565b611165611ab6565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff000000000000000000000000000000000000000090911681179091556111c860005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b600061121882611329565b6112229083612943565b9150610f098383611edf565b6002805403611269576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60028055565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600e60209081526040808320815160e0810183528154815260018201549381018490526002820154928101929092526003810154606083015260048101546080830152600581015460a08301526006015460c08201529082906112ef908590612956565b60a083015190915060009061130d90670de0b6b3a764000084611b9a565b905080836080015161131f9190612943565b9695505050505050565b600854600090610adc9083906127106001611fb8565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600e6020526040812060018101805491928592611379908490612956565b92505081905550818160020160008282546113949190612943565b92505081905550818160040160008282546113af9190612943565b9091555050600181015460048201546113d191670de0b6b3a764000090611b9a565b600690910155505050565b60006113ef826113886127106001611fb8565b905060006113fd8284612943565b9050611408826119da565b6109d08482612009565b6000806114b58573ffffffffffffffffffffffffffffffffffffffff81166000908152600c602090815260409182902054825160609490941b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000168483015260f81b7fff00000000000000000000000000000000000000000000000000000000000000166034840152815160158185030181526035909301909152815191012090565b6003549091506000906114de9073ffffffffffffffffffffffffffffffffffffffff1683612117565b73ffffffffffffffffffffffffffffffffffffffff87166000908152600c60205260408120805492955085935060019290919061151f90849060ff16612969565b82546101009290920a60ff8181021990931691909216919091021790555073ffffffffffffffffffffffffffffffffffffffff8381166000818152600d60205260409081902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016938a1693909317909255600b5491517fb119490e000000000000000000000000000000000000000000000000000000008152909163b119490e916115d49189918991906004016129e6565b600060405180830381600087803b1580156115ee57600080fd5b505af1158015611602573d6000803e3d6000fd5b5050505050509392505050565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600e602052604081206b029009752660ad62af80000081556b037790968dc8efffd1000000600182018190556002820192909255600a5460048201819055909161167d91670de0b6b3a7640000611b9a565b6005820155600a546116a490670de0b6b3a76400006b037790968dc8efffd1000000611b9a565b6006820155600a546116e6670de0b6b3a76400006116da6b029009752660ad62af8000006b037790968dc8efffd1000000612943565b60058501549190611b9a565b6116f09190612943565b60039091015550565b600554600480546040517fc9c6539600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff918216928101929092528381166024830152600092169063c9c65396906044016020604051808303816000875af115801561177a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061179e9190612a1c565b6040517f8187f51600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808316600483015291925090831690638187f51690602401600060405180830381600087803b15801561180b57600080fd5b505af115801561181f573d6000803e3d6000fd5b505050505050565b600061183283611329565b905060006118408285612943565b9050600061184d866121ab565b9050600081831115611869576118638284612943565b90508192505b60006118758885611edf565b9050858110156118b1576040517f65fc6a9600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6118bc88858361222b565b6118c688866113dc565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8a811660048301526024820183905289169063a9059cbb906044016020604051808303816000875af115801561193b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061195f91906128f2565b5061196a8a8361229b565b6040805173ffffffffffffffffffffffffffffffffffffffff8c811682528b8116602083015291810189905260608101839052908916907fbab4aa6b2d5c0935e0e2937d1f73655848f670d43bf6f0c7e9e11e635bb5d86f9060800160405180910390a250505050505050505050565b806000036119e55750565b6000805460405173ffffffffffffffffffffffffffffffffffffffff9091169083908381818185875af1925050503d8060008114611a3f576040519150601f19603f3d011682016040523d82523d6000602084013e611a44565b606091505b5050905080611a7f576040517f31976d8200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040518281527fc472cb3a7a659a876494d66b3063145f279701771d6150b9329c31611ed6405c9060200160405180910390a15050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610d4a576040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152602401610db3565b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055610dc581612341565b6040513060388201526f5af43d82803e903d91602b57fd5bf3ff602482015260148101839052733d602d80600a3d3981f3363d3d373d3d3d363d738152605881018290526037600c82012060788201526055604390910120600090610f09565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8587098281108382030391505080600003611bef57838281611be557611be5612a39565b0492505050610f09565b808411611c28576040517f227bc15300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600f602052604090205460ff1615611cf5576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff81166000908152600e60209081526040808320815160e0810183528154815260018201549381019390935260028101549183018290526003810154606084015260048101546080840152600581015460a08401526006015460c0830152909190611d73906123b6565b90506000818360400151611d879190612943565b905060006b029009752660ad62af800000600b54611da59190612943565b73ffffffffffffffffffffffffffffffffffffffff86166000908152600f6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055909150819003611e2f576040517fc1ab6dc100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611e3a8583836123cc565b611e8e8573ffffffffffffffffffffffffffffffffffffffff166000908152600e60205260408120818155600181018290556002810182905560048101829055600581018290556006810182905560030155565b611e97836119da565b60405173ffffffffffffffffffffffffffffffffffffffff8616907f209156264c93be2bbde023bbbaf8e65ca5e0a0837f8fe9316b153acbd303b12290600090a25050505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600e60209081526040808320815160e081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546080830152600581015460a08301526006015460c082015281611f5c856121ab565b905080841115611f6a578093505b6000848360800151611f7c9190612956565b60a0840151909150600090611f9b90670de0b6b3a76400008484611fb8565b9050808460200151611fad9190612943565b979650505050505050565b600080611fc6868686611b9a565b9050611fd183612651565b8015611fed575060008480611fe857611fe8612a39565b868809115b1561200057611ffd600182612956565b90505b95945050505050565b80600003612015575050565b73ffffffffffffffffffffffffffffffffffffffff8281166000908152600d6020526040808220549051921691829084908381818185875af1925050503d806000811461207e576040519150601f19603f3d011682016040523d82523d6000602084013e612083565b606091505b50509050806120be576040517f31976d8200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8681168252602082018690528416917f6db075527fc7154c59e93ed1ec44bc170ce881eaa6b23be103124209f9b225db910160405180910390a250505050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b1760205281603760096000f5905073ffffffffffffffffffffffffffffffffffffffff8116610adc576040517fc2f868f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff81166000908152600e60209081526040808320815160e08101835281548152600182015493810193909352600281015491830182905260038101546060840181905260048201546080850152600582015460a085015260069091015460c0840152610f099190612943565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600e6020526040812060028101805491928592612265908490612956565b92505081905550828160040160008282546122809190612956565b92505081905550818160010160008282546113af9190612943565b806000036122a7575050565b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d8060008114612301576040519150601f19603f3d011682016040523d82523d6000602084013e612306565b606091505b5050905080611158576040517ff0c49d4400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600954600090610adc9083906127106001611fb8565b8273ffffffffffffffffffffffffffffffffffffffff166281a0b26040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561241357600080fd5b505af1158015612427573d6000803e3d6000fd5b50506006546040517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff918216600482015260248101859052908616925063095ea7b391506044016020604051808303816000875af11580156124a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c891906128f2565b5060065473ffffffffffffffffffffffffffffffffffffffff1663f305d719838584808360006124fa42611c20612956565b60405160e089901b7fffffffff0000000000000000000000000000000000000000000000000000000016815273ffffffffffffffffffffffffffffffffffffffff9687166004820152602481019590955260448501939093526064840191909152909216608482015260a481019190915260c40160606040518083038185885af115801561258c573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906125b19190612a68565b50506006546040517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff918216600482015260006024820152908516915063095ea7b3906044016020604051808303816000875af115801561262d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109d091906128f2565b6000600282600381111561266757612667612a96565b6126719190612ac5565b60ff166001149050919050565b73ffffffffffffffffffffffffffffffffffffffff81168114610dc557600080fd5b6000602082840312156126b257600080fd5b8135610f098161267e565b600080600080608085870312156126d357600080fd5b84356126de8161267e565b9350602085013592506040850135915060608501356126fc8161267e565b939692955090935050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f83011261274757600080fd5b813567ffffffffffffffff81111561276157612761612707565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff821117156127cd576127cd612707565b6040528181528382016020018510156127e557600080fd5b816020850160208301376000918101602001919091529392505050565b6000806040838503121561281557600080fd5b823567ffffffffffffffff81111561282c57600080fd5b61283885828601612736565b925050602083013567ffffffffffffffff81111561285557600080fd5b61286185828601612736565b9150509250929050565b60006020828403121561287d57600080fd5b5035919050565b6000806040838503121561289757600080fd5b82356128a28161267e565b946020939093013593505050565b6000806000606084860312156128c557600080fd5b83356128d08161267e565b92506020840135915060408401356128e78161267e565b809150509250925092565b60006020828403121561290457600080fd5b81518015158114610f0957600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115610adc57610adc612914565b80820180821115610adc57610adc612914565b60ff8181168382160190811115610adc57610adc612914565b6000815180845260005b818110156129a85760208185018101518683018201520161298c565b5060006020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b6060815260006129f96060830186612982565b8281036020840152612a0b8186612982565b915050826040830152949350505050565b600060208284031215612a2e57600080fd5b8151610f098161267e565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600080600060608486031215612a7d57600080fd5b5050815160208301516040909301519094929350919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600060ff831680612aff577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b8060ff8416069150509291505056fea2646970667358221220db326e17d3c90dba22e3dde187cf29202d5d2b449764b51cf23813c94b2f8bda64736f6c634300081a0033
Verified Source Code Full Match
Compiler: v0.8.26+commit.8a97fa7a
EVM: paris
Optimization: Yes (20000 runs)
FankoTokenV2.sol 69 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC20, ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/**
* @title FankoTokenV2
* @notice Immutable contract. Creator can't rug but they can still jeet, so becareful.
* @dev only FankoFactory can setPair abd unblockPair
*/
contract FankoTokenV2 is Initializable, ERC20Burnable, Ownable, ReentrancyGuard {
string private _name;
string private _symbol;
address public pair;
bool public pairBlocked;
error InvalidTransfer();
constructor() Ownable(msg.sender) ERC20("Fanko", "FANKO") {}
function initialize(string memory name_, string memory symbol_, uint256 totalSupply_) external initializer {
_name = name_;
_symbol = symbol_;
_mint(msg.sender, totalSupply_);
_transferOwnership(msg.sender);
pairBlocked = true;
}
///////////////////////////////////////////////////////////////
// Admin Actions //
///////////////////////////////////////////////////////////////
function setPair(address pair_) external onlyOwner {
pair = pair_;
}
function unblockPair() external onlyOwner {
pairBlocked = false;
}
////////////////////////////////////////////////////////////////
// Private Write Functions //
////////////////////////////////////////////////////////////////
function _update(address from, address to, uint256 value) internal virtual override {
if (to == pair && pairBlocked) {
revert InvalidTransfer();
}
super._update(from, to, value);
}
////////////////////////////////////////////////////////////////
// Public Read Functions //
////////////////////////////////////////////////////////////////
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
}
FankoFactoryV2ETH.sol 426 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Ownable, Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {FankoTokenV2} from "./FankoTokenV2.sol";
import {ICamelotV2Factory} from "./interfaces/ICamelotV2Factory.sol";
import {ICamelotV2Router} from "./interfaces/ICamelotV2Router.sol";
contract FankoFactoryV2ETH is Ownable2Step, ReentrancyGuard {
using Clones for address;
using Math for uint256;
address public implementation;
address public weth;
ICamelotV2Factory public camelotV2Factory;
ICamelotV2Router public camelotV2Router;
uint256 private constant FEE_MAX = 1 ether;
uint256 private constant FEE_BPS_SCALE = 10_000;
uint256 private constant FEE_BPS_MAX = 1_000;
uint256 private constant RESERVE_REAL_TOKEN = 793100000 ether;
uint256 private constant RESERVE_VIRT_TOKEN = 1073000000 ether;
uint256 public tokenCreationFee = 0.01 ether;
uint256 public tradingFeeBPS = 100;
uint256 public tokenLaunchingFeeBPS = 500;
uint256 public ethVirtualReserve = 1.17 ether;
uint256 public tokenTotalSupply = 1_000_000_000 ether;
struct BondingCurve {
uint256 tokenRealReserve;
uint256 tokenVirtualReserve;
uint256 ethRealReserve;
uint256 ethRealReserveThreshold;
uint256 ethVirtualReserve;
uint256 k;
uint256 spotPrice;
}
mapping(address account => uint8 count) public tokenCounts;
mapping(FankoTokenV2 token => address creator) public tokenCreator;
mapping(FankoTokenV2 token => BondingCurve curve) public bondingCurves;
mapping(FankoTokenV2 token => bool isLaunched) public tokenLaunched;
error CollectAdminFeesFailed();
error InvalidEthAmountIn();
error InvalidEthAmountOut();
error InvalidEthVirtualReserve();
error InvalidToken();
error InvalidTokenAmountIn();
error InvalidTokenAmountOut();
error InvalidTokenCreationFee();
error InvalidTokenLaunchingFeeBPS();
error InvalidTradingFeeBPS();
error SellFailed();
error RefundFailed();
event NewTokenCreationFee(uint256 fee);
event NewTradingFeeBPS(uint256 bps);
event NewGraduationFeeBPS(uint256 bps);
event NewEthVirtualReserve(uint256 reserve);
event NewToken(address indexed creator, FankoTokenV2 token);
event NewTokenLaunch(FankoTokenV2 indexed token);
event FeeCollected(uint256 amount);
event FeeCreatorCollected(address indexed creator, address token, uint256 amount);
event Buy(FankoTokenV2 indexed token, address from, address to, uint256 amountIn, uint256 amountOut);
event Sell(FankoTokenV2 indexed token, address from, address to, uint256 amountIn, uint256 amountOut);
constructor(
address admin_,
address implementation_,
address weth_,
address camelotV2Factory_,
address camelotV2Router_
) Ownable(admin_) {
implementation = implementation_;
weth = weth_;
camelotV2Factory = ICamelotV2Factory(camelotV2Factory_);
camelotV2Router = ICamelotV2Router(camelotV2Router_);
}
///////////////////////////////////////////////////////////////
// Admin Actions //
///////////////////////////////////////////////////////////////
function setTokenCreationFee(uint256 fee_) external onlyOwner {
if (fee_ > FEE_MAX) revert InvalidTokenCreationFee();
if (fee_ == tokenCreationFee) revert InvalidTokenCreationFee();
tokenCreationFee = fee_;
emit NewTokenCreationFee(tokenCreationFee);
}
function setTradingFeeBPS(uint256 bps_) external onlyOwner {
if (bps_ > FEE_BPS_MAX) revert InvalidTradingFeeBPS();
if (bps_ == tradingFeeBPS) revert InvalidTradingFeeBPS();
tradingFeeBPS = bps_;
emit NewTradingFeeBPS(tradingFeeBPS);
}
function setTokenLaunchingFeeBPS(uint256 bps_) external onlyOwner {
if (bps_ > FEE_BPS_MAX) revert InvalidTokenLaunchingFeeBPS();
if (bps_ == tokenLaunchingFeeBPS) revert InvalidTokenLaunchingFeeBPS();
tokenLaunchingFeeBPS = bps_;
emit NewGraduationFeeBPS(tokenLaunchingFeeBPS);
}
function setEthVirtualReserve(uint256 amount_) external onlyOwner {
if (amount_ == ethVirtualReserve) revert InvalidEthVirtualReserve();
ethVirtualReserve = amount_;
emit NewEthVirtualReserve(ethVirtualReserve);
}
////////////////////////////////////////////////////////////////
// Private Read Functions //
////////////////////////////////////////////////////////////////
function getSalt(address account_) private view returns (bytes32 salt) {
uint8 tokenIndex = tokenCounts[account_];
salt = keccak256(abi.encodePacked(account_, tokenIndex));
}
function getTradingFeeAmount(uint256 amount_) private view returns (uint256 feeAmount) {
feeAmount = amount_.mulDiv(tradingFeeBPS, FEE_BPS_SCALE, Math.Rounding.Ceil);
}
function getLaunchingFeeAmount(uint256 amount_) private view returns (uint256 feeAmount) {
feeAmount = amount_.mulDiv(tokenLaunchingFeeBPS, FEE_BPS_SCALE, Math.Rounding.Ceil);
}
function getBondingCurveTokenAmountOut(FankoTokenV2 token_, uint256 ethAmountIn_)
private
view
returns (uint256 tokenAmountOut)
{
BondingCurve memory curve = bondingCurves[token_];
uint256 _maxEthAmountIn = getBondingCurveMaxCapacity(token_);
if (ethAmountIn_ > _maxEthAmountIn) {
ethAmountIn_ = _maxEthAmountIn;
}
uint256 _newEthVirtualReserve = curve.ethVirtualReserve + ethAmountIn_;
uint256 _newTokenVirtualReserve = curve.k.mulDiv(1 ether, _newEthVirtualReserve, Math.Rounding.Floor);
tokenAmountOut = curve.tokenVirtualReserve - _newTokenVirtualReserve;
}
function getBondingCurveEthAmountOut(FankoTokenV2 token_, uint256 tokenAmountIn_)
private
view
returns (uint256 ethAmountOut)
{
BondingCurve memory curve = bondingCurves[token_];
uint256 _newTokenVirtualReserve = curve.tokenVirtualReserve + tokenAmountIn_;
uint256 _newEthVirtualReserve = curve.k.mulDiv(1 ether, _newTokenVirtualReserve);
ethAmountOut = curve.ethVirtualReserve - _newEthVirtualReserve;
}
function getBondingCurveMaxCapacity(FankoTokenV2 token_) private view returns (uint256 maxCap) {
BondingCurve memory curve = bondingCurves[token_];
maxCap = curve.ethRealReserveThreshold - curve.ethRealReserve;
}
function getNewTokenAddress(address account_) external view returns (address token) {
bytes32 salt = getSalt(account_);
token = implementation.predictDeterministicAddress(salt);
}
function launchable(FankoTokenV2 token_) private view returns (bool isLaunchable) {
BondingCurve memory curve = bondingCurves[token_];
isLaunchable = curve.ethRealReserve >= curve.ethRealReserveThreshold;
}
////////////////////////////////////////////////////////////////
// Private Write Functions //
////////////////////////////////////////////////////////////////
function deployToken(address creator_, string memory name_, string memory symbol_)
private
returns (FankoTokenV2 token)
{
bytes32 salt = getSalt(creator_);
address deployed = implementation.cloneDeterministic(salt);
token = FankoTokenV2(deployed);
tokenCounts[creator_] += 1;
tokenCreator[token] = creator_;
token.initialize(name_, symbol_, tokenTotalSupply);
}
function createBondingCurve(FankoTokenV2 token_) private {
BondingCurve storage curve = bondingCurves[token_];
curve.tokenRealReserve = RESERVE_REAL_TOKEN;
curve.tokenVirtualReserve = RESERVE_VIRT_TOKEN;
curve.ethRealReserve = 0 ether;
curve.ethVirtualReserve = ethVirtualReserve;
curve.k = RESERVE_VIRT_TOKEN.mulDiv(ethVirtualReserve, 1 ether);
curve.spotPrice = ethVirtualReserve.mulDiv(1 ether, RESERVE_VIRT_TOKEN);
curve.ethRealReserveThreshold =
curve.k.mulDiv(1 ether, RESERVE_VIRT_TOKEN - RESERVE_REAL_TOKEN) - ethVirtualReserve;
}
function resetBondingCurve(FankoTokenV2 token_) private {
BondingCurve storage curve = bondingCurves[token_];
curve.tokenRealReserve = 0;
curve.tokenVirtualReserve = 0;
curve.ethRealReserve = 0 ether;
curve.ethVirtualReserve = 0;
curve.k = 0;
curve.spotPrice = 0;
curve.ethRealReserveThreshold = 0;
}
function updateBondingCurveOnBuy(FankoTokenV2 token_, uint256 ethAmountIn_, uint256 tokenAmountOut_) private {
BondingCurve storage curve = bondingCurves[token_];
curve.ethRealReserve += ethAmountIn_;
curve.ethVirtualReserve += ethAmountIn_;
curve.tokenVirtualReserve -= tokenAmountOut_;
curve.spotPrice = curve.ethVirtualReserve.mulDiv(1 ether, curve.tokenVirtualReserve);
}
function updateBondingCurveOnSell(FankoTokenV2 token_, uint256 tokenAmountIn_, uint256 ethAmountOut_) private {
BondingCurve storage curve = bondingCurves[token_];
curve.tokenVirtualReserve += tokenAmountIn_;
curve.ethRealReserve -= ethAmountOut_;
curve.ethVirtualReserve -= ethAmountOut_;
curve.spotPrice = curve.ethVirtualReserve.mulDiv(1 ether, curve.tokenVirtualReserve);
}
function collectAdminFees(uint256 amount_) private {
if (amount_ == 0) return;
(bool succeed,) = owner().call{value: amount_}("");
if (!succeed) revert CollectAdminFeesFailed();
emit FeeCollected(amount_);
}
function refundEth(address recipient_, uint256 amount_) private {
if (amount_ == 0) return;
(bool succeed,) = recipient_.call{value: amount_}("");
if (!succeed) revert RefundFailed();
}
function collectCreatorFees(FankoTokenV2 token_, uint256 amount_) private {
if (amount_ == 0) return;
address creator = tokenCreator[token_];
(bool succeed,) = creator.call{value: amount_}("");
if (!succeed) revert CollectAdminFeesFailed();
emit FeeCreatorCollected(creator, address(token_), amount_);
}
function collectTradingFees(FankoTokenV2 token_, uint256 amount_) private {
uint256 protocolShare = amount_.mulDiv(5000, FEE_BPS_SCALE, Math.Rounding.Ceil);
uint256 creatorShare = amount_ - protocolShare;
collectAdminFees(protocolShare);
collectCreatorFees(token_, creatorShare);
}
function createCamelotV2Pair(FankoTokenV2 token_) private {
address pair = camelotV2Factory.createPair(weth, address(token_));
token_.setPair(pair);
}
function addCamelotV2Liquidity(FankoTokenV2 token_, uint256 ethAmount_, uint256 tokenAmount_) private {
token_.unblockPair();
token_.approve(address(camelotV2Router), tokenAmount_);
camelotV2Router.addLiquidityETH{value: ethAmount_}(
address(token_), tokenAmount_, tokenAmount_, ethAmount_, address(0), block.timestamp + 2 hours
);
token_.approve(address(camelotV2Router), 0);
}
function buy(
address sender_,
address recipient_,
FankoTokenV2 token_,
uint256 ethAmountIn_,
uint256 tokenAmountOutMin_
) private {
uint256 _feeAmount = getTradingFeeAmount(ethAmountIn_);
uint256 _ethAmount = ethAmountIn_ - _feeAmount;
uint256 _maxEthAmountIn = getBondingCurveMaxCapacity(token_);
uint256 refund = 0;
if (_ethAmount > _maxEthAmountIn) {
refund = _ethAmount - _maxEthAmountIn;
_ethAmount = _maxEthAmountIn;
}
uint256 _tokenAmount = getBondingCurveTokenAmountOut(token_, _ethAmount);
if (_tokenAmount < tokenAmountOutMin_) revert InvalidTokenAmountOut();
updateBondingCurveOnBuy(token_, _ethAmount, _tokenAmount);
collectTradingFees(token_, _feeAmount);
token_.transfer(recipient_, _tokenAmount);
refundEth(sender_, refund);
emit Buy(token_, sender_, recipient_, ethAmountIn_, _tokenAmount);
}
function launchToken(FankoTokenV2 token_) private {
if (tokenLaunched[token_]) revert InvalidToken();
BondingCurve memory curve = bondingCurves[token_];
uint256 _feeAmount = getLaunchingFeeAmount(curve.ethRealReserve);
uint256 _ethAmount = curve.ethRealReserve - _feeAmount;
uint256 _tokenAmount = tokenTotalSupply - RESERVE_REAL_TOKEN;
tokenLaunched[token_] = true;
if (_tokenAmount == 0) revert InvalidToken();
addCamelotV2Liquidity(token_, _ethAmount, _tokenAmount);
resetBondingCurve(token_);
collectAdminFees(_feeAmount);
emit NewTokenLaunch(token_);
}
////////////////////////////////////////////////////////////////
// Public Read Functions //
////////////////////////////////////////////////////////////////
function getNewTokenAmount(uint256 ethAmountIn_) external view returns (uint256 tokenAmountOut) {
uint256 _buyAmount = ethAmountIn_ - tokenCreationFee;
uint256 _buyFeeAmount = getTradingFeeAmount(_buyAmount);
uint256 _ethAmount = _buyAmount - _buyFeeAmount;
uint256 _newEthVirtualReserve = ethVirtualReserve + _ethAmount;
uint256 _k = RESERVE_VIRT_TOKEN.mulDiv(ethVirtualReserve, 1 ether);
uint256 _newTokenVirtualReserve = _k.mulDiv(1 ether, _newEthVirtualReserve);
tokenAmountOut = RESERVE_VIRT_TOKEN - _newTokenVirtualReserve;
}
function getTokenAmountOut(FankoTokenV2 token_, uint256 ethAmountIn_)
external
view
returns (uint256 tokenAmountOut)
{
ethAmountIn_ -= getTradingFeeAmount(ethAmountIn_);
return getBondingCurveTokenAmountOut(token_, ethAmountIn_);
}
function getEthAmountOut(FankoTokenV2 token_, uint256 tokenAmountIn_)
external
view
returns (uint256 ethAmountOut)
{
ethAmountOut = getBondingCurveEthAmountOut(token_, tokenAmountIn_);
uint256 _fee = getTradingFeeAmount(ethAmountOut);
ethAmountOut -= _fee;
}
////////////////////////////////////////////////////////////////
// Public Write Functions //
////////////////////////////////////////////////////////////////
function createToken(string memory name_, string memory symbol_)
external
payable
nonReentrant
returns (FankoTokenV2 token)
{
if (msg.value < tokenCreationFee) revert InvalidTokenCreationFee();
uint256 _ethAmountIn = 0;
if (msg.value > tokenCreationFee) {
_ethAmountIn = msg.value - tokenCreationFee;
}
token = deployToken(msg.sender, name_, symbol_);
createBondingCurve(token);
createCamelotV2Pair(token);
if (_ethAmountIn > 0) {
buy(msg.sender, msg.sender, token, _ethAmountIn, 0);
collectAdminFees(tokenCreationFee);
} else {
collectAdminFees(tokenCreationFee);
}
emit NewToken(msg.sender, token);
}
function buy(FankoTokenV2 token_, uint256 tokenAmountOutMin_, address recipient_) external payable nonReentrant {
if (msg.value == 0) revert InvalidEthAmountIn();
if (tokenCreator[token_] == address(0)) revert InvalidToken();
if (tokenLaunched[token_]) revert InvalidToken();
buy(msg.sender, recipient_, token_, msg.value, tokenAmountOutMin_);
if (launchable(token_)) {
launchToken(token_);
}
}
function sell(FankoTokenV2 token_, uint256 tokenAmountIn_, uint256 ethAmountOutMin_, address recipient_)
external
payable
nonReentrant
{
if (tokenAmountIn_ == 0) revert InvalidTokenAmountIn();
if (tokenCreator[token_] == address(0)) revert InvalidToken();
if (tokenLaunched[token_]) revert InvalidToken();
token_.transferFrom(msg.sender, address(this), tokenAmountIn_);
uint256 _ethAmountOut = getBondingCurveEthAmountOut(token_, tokenAmountIn_);
uint256 _feeAmount = getTradingFeeAmount(_ethAmountOut);
uint256 _ethAmount = _ethAmountOut - _feeAmount;
if (_ethAmount < ethAmountOutMin_) revert InvalidEthAmountOut();
if (_ethAmount > bondingCurves[token_].ethRealReserve) revert InvalidEthAmountOut();
updateBondingCurveOnSell(token_, tokenAmountIn_, _ethAmountOut);
collectTradingFees(token_, _feeAmount);
(bool succeed,) = recipient_.call{value: _ethAmount}("");
if (!succeed) revert SellFailed();
emit Sell(token_, msg.sender, recipient_, tokenAmountIn_, _ethAmount);
}
}
ICamelotV2Router.sol 21 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface ICamelotV2Router {
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
address referrer,
uint256 deadline
) external payable;
}
ICamelotV2Factory.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface ICamelotV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
Clones.sol 95 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Clones.sol)
pragma solidity ^0.8.20;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*/
library Clones {
/**
* @dev A clone instance deployment failed.
*/
error ERC1167FailedCreateClone();
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(0, 0x09, 0x37)
}
if (instance == address(0)) {
revert ERC1167FailedCreateClone();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(0, 0x09, 0x37, salt)
}
if (instance == address(0)) {
revert ERC1167FailedCreateClone();
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := keccak256(add(ptr, 0x43), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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 towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (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 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 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.
uint256 twos = denominator & (0 - denominator);
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 (unsignedRoundsUp(rounding) && 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
* towards zero.
*
* 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* 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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* 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 256, 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
ERC20.sol 316 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
Ownable2Step.sol 59 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @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;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
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
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// 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;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
Initializable.sol 228 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
ERC20Burnable.sol 39 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Burnable.sol)
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
import {Context} from "../../../utils/Context.sol";
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is Context, ERC20 {
/**
* @dev Destroys a `value` amount of tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 value) public virtual {
_burn(_msgSender(), value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, deducting from
* the caller's allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `value`.
*/
function burnFrom(address account, uint256 value) public virtual {
_spendAllowance(account, _msgSender(), value);
_burn(account, value);
}
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Read Contract
bondingCurves 0xb9a059f7 → uint256, uint256, uint256, uint256, uint256, uint256, uint256
camelotV2Factory 0x0e7aecb8 → address
camelotV2Router 0x28917218 → address
ethVirtualReserve 0xb0f66ab7 → uint256
getEthAmountOut 0x67a5a85f → uint256
getNewTokenAddress 0xb95f8c9a → address
getNewTokenAmount 0xd43fd4d1 → uint256
getTokenAmountOut 0xf87ec1e1 → uint256
implementation 0x5c60da1b → address
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
tokenCounts 0x9909ccb1 → uint8
tokenCreationFee 0x540a9f6f → uint256
tokenCreator 0x23774af2 → address
tokenLaunched 0x564e5ad2 → bool
tokenLaunchingFeeBPS 0xb484b050 → uint256
tokenTotalSupply 0xf7abab9e → uint256
tradingFeeBPS 0x51f1bfa4 → uint256
weth 0x3fc8cef3 → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
buy 0xdb61c76e
address token_
uint256 tokenAmountOutMin_
address recipient_
createToken 0x2f2f2d56
string name_
string symbol_
returns: address
renounceOwnership 0x715018a6
No parameters
sell 0x2dc8f867
address token_
uint256 tokenAmountIn_
uint256 ethAmountOutMin_
address recipient_
setEthVirtualReserve 0x818cb233
uint256 amount_
setTokenCreationFee 0x6dc5843f
uint256 fee_
setTokenLaunchingFeeBPS 0x62a3c096
uint256 bps_
setTradingFeeBPS 0x6e9dae75
uint256 bps_
transferOwnership 0xf2fde38b
address newOwner
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address