Address Contract Verified
Address
0xef2ce3414e83b2eA7e4bF2d64840cc5e88cd3637
Balance
0 ETH
Nonce
1
Code Size
13097 bytes
Creator
0x21D3376a...7442 at tx 0x7bbef66c...0aa8f5
Indexed Transactions
0
Contract Bytecode
13097 bytes
0x608060405234801561001057600080fd5b50600436106102b65760003560e01c806379cd8d7611610172578063a9059cbb116100d9578063dd644f7211610092578063dd644f72146105a0578063e4997dc5146105a9578063ec669036146105bc578063f0f44260146105c4578063f2fde38b146105d7578063f30d6da1146105ea578063fcd3533c146105f257600080fd5b8063a9059cbb14610539578063b7a229731461054c578063c0324c771461055f578063ce19057814610572578063d547741f1461057a578063dd62ed3e1461058d57600080fd5b806391d148541161012b57806391d14854146104d257806394bf804d146104e557806395d89b41146104f85780639f3c6ccb14610500578063a457c2d714610513578063a7040ef91461052657600080fd5b806379cd8d761461046e5780637c2efcba1461048157806387c1be6e1461048857806388c16fe81461049b5780638da5cb5b146104ae5780638eed871d146104bf57600080fd5b80633af32abf116102215780635c975abb116101da5780635c975abb146103fa57806361d027b3146104025780636f0ccec91461041a57806370a082311461042d578063715018a614610456578063716875041461045e57806375b238fc1461046657600080fd5b80633af32abf1461039c57806343e2ae92146103af5780634460bdd6146103c45780634601c329146103cc578063575850a1146103df57806359bf1abe146103e757600080fd5b8063248a9ca311610273578063248a9ca31461033f5780632f2ff15d14610352578063305eb41e14610365578063313ce5671461036d5780633539071414610380578063395093511461038957600080fd5b806306fdde03146102bb578063095ea7b3146102d95780630ecb93c0146102f957806316c61ccc1461030e57806318160ddd1461031b57806323b872dd1461032c575b600080fd5b6102c3610605565b6040516102d09190612031565b60405180910390f35b6102ec6102e7366004612083565b610697565b6040516102d091906120ca565b61030c6103073660046120d8565b6106b1565b005b609a546102ec9060ff1681565b6067545b6040516102d091906120ff565b6102ec61033a36600461210d565b610730565b61031f61034d36600461215d565b610802565b61030c61036036600461217e565b610822565b6102c3610848565b60975460ff166040516102d091906121ba565b61031f60995481565b6102ec610397366004612083565b6108d6565b6102ec6103aa3660046120d8565b6108f8565b6103b7610928565b6040516102d091906121d1565b61031f600081565b61030c6103da3660046121f2565b610943565b6102ec610a3c565b6102ec6103f53660046120d8565b610a56565b6102ec610a61565b6097546103b79061010090046001600160a01b031681565b61030c610428366004612347565b610aad565b61031f61043b3660046120d8565b6001600160a01b031660009081526065602052604090205490565b61030c610c25565b61030c610c39565b61031f600181565b61030c61047c36600461242e565b610c55565b600161031f565b61030c610496366004612450565b610cc4565b6102ec6104a936600461215d565b610ce1565b6033546001600160a01b03166103b7565b61030c6104cd366004612471565b610d04565b6102ec6104e036600461217e565b610d1c565b61030c6104f336600461217e565b610d95565b6102c3610df6565b61030c61050e3660046124f5565b610e05565b6102ec610521366004612083565b610e28565b61030c6105343660046120d8565b610e70565b6102ec610547366004612083565b610f1a565b61030c61055a3660046120d8565b610fd9565b61030c61056d36600461242e565b61103b565b61030c6110bb565b61030c61058836600461217e565b6110d2565b61031f61059b36600461253c565b6110f2565b61031f60985481565b61030c6105b73660046120d8565b61111d565b61030c61118a565b61030c6105d23660046120d8565b6111a1565b61030c6105e53660046120d8565b6111ff565b61030c611239565b61030c61060036600461217e565b611251565b60606068805461061490612574565b80601f016020809104026020016040519081016040528092919081815260200182805461064090612574565b801561068d5780601f106106625761010080835404028352916020019161068d565b820191906000526020600020905b81548152906001019060200180831161067057829003601f168201915b5050505050905090565b6000336106a58185856112b2565b60019150505b92915050565b6001806106bf813381611366565b60006106c9611438565b6001600160a01b03851660009081526001808301602052604091829020805460ff19169091179055519091507f42e160154868087d6bfdc0ca23d96a1c1cfa32f1b72ba9ba27b69b98a0d819dc906107229086906121d1565b60405180910390a150505050565b600061073a610a61565b156107605760405162461bcd60e51b8152600401610757906125d3565b60405180910390fd5b61076984610a56565b1561077357600080fd5b61077c83610a56565b1561078657600080fd5b60006107a96127106107a36098548661145c90919063ffffffff16565b90611494565b90506099548111156107ba57506099545b60006107c684836114a1565b905081156107eb576097546107eb90879061010090046001600160a01b0316846114bd565b6107f686868361159b565b925050505b9392505050565b60008061080d6115b4565b60009384526020525050604090206002015490565b61082b82610802565b6001610838823383611366565b61084284846115d8565b50505050565b609b805461085590612574565b80601f016020809104026020016040519081016040528092919081815260200182805461088190612574565b80156108ce5780601f106108a3576101008083540402835291602001916108ce565b820191906000526020600020905b8154815290600101906020018083116108b157829003601f168201915b505050505081565b6000336106a58185856108e983836110f2565b6108f391906125f9565b6112b2565b60008061090361170c565b6001600160a01b03909316600090815260019093016020525050604090205460ff1690565b600080610933611438565b546001600160a01b031692915050565b61094c83610802565b6001610959823383611366565b60006109636115b4565b905084156109c0576001600160a01b0384166109915760405162461bcd60e51b815260040161075790612669565b600086815260208290526040902060010180546001600160a01b0319166001600160a01b0386161790556109e0565b600086815260208290526040902060010180546001600160a01b03191690555b600086815260208290526040808220600301805460ff191688151590811790915590516001600160a01b0387169289917f410d361975f890f62db8b6b7e8029cd181851543911958eb1900a864bd72d38f9190a4505050505050565b600080610a4761170c565b54610100900460ff1692915050565b600080610903611438565b600080610a6c61170c565b8054909150610100900460ff168015610aa75750805460ff16610a90576001610aa7565b33600090815260018201602052604090205460ff16155b91505090565b600054610100900460ff1615808015610acd5750600054600160ff909116105b80610ae75750303b158015610ae7575060005460ff166001145b610b035760405162461bcd60e51b8152600401610757906126c4565b6000805460ff191660011790558015610b26576000805461ff0019166101001790555b6001600160a01b038316610b4c5760405162461bcd60e51b815260040161075790612706565b6001600160a01b038216610b725760405162461bcd60e51b81526004016107579061275a565b610b7c8888611730565b610b84611761565b610b8c611790565b610b95826117bf565b60978054609887905560998690556001600160a01b038516610100026001600160a81b031990911660ff891617179055610bcf338a6117ef565b8015610c1a576000805461ff00191690556040517f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890610c1190600190612787565b60405180910390a15b505050505050505050565b610c2d611873565b610c37600061189d565b565b600180610c47813381611366565b610c5160006118ef565b5050565b610c5e82610802565b6001610c6b823383611366565b6000610c756115b4565b6000868152602082905260408082206002018054908890559051929350918691839189917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff91a4505050505050565b60006001610cd3823383611366565b610cdc83611956565b505050565b600080610cec6115b4565b60009384526020525050604090206003015460ff1690565b600180610d12813381611366565b61084284846119f0565b600080610d276115b4565b60008581526020829052604090206003015490915060ff16610d6c576000848152602082815260408083206001600160a01b038716845290915290205460ff16610d8d565b6000848152602082905260409020600101546001600160a01b038481169116145b949350505050565b600180610da3813381611366565b83600003610db057600080fd5b610dba83856117ef565b6040516001600160a01b0384169085907ff3cea5493d790af0133817606f7350a91d7f154ea52eaa79d179d4d231e5010290600090a350505050565b60606069805461061490612574565b60006001610e14823383611366565b609b610e21848683612852565b5050505050565b60003381610e3682866110f2565b905083811015610e585760405162461bcd60e51b815260040161075790612952565b610e6582868684036112b2565b506001949350505050565b600180610e7e813381611366565b6000610e88611438565b6001600160a01b038516600090815260018201602052604090205490915060ff16610eb257600080fd5b6001600160a01b0384811660009081526065602052604090205482549091610edd91879116836114bd565b60405181906001600160a01b038716907f4b4a34aef00841b2ebc64a3a620b3d8bc4b5b76d570a3ca9ecde4abbd161433790600090a35050505050565b6000610f24610a61565b15610f415760405162461bcd60e51b8152600401610757906125d3565b610f4a33610a56565b15610f5457600080fd5b610f5d83610a56565b15610f6757600080fd5b6000610f846127106107a36098548661145c90919063ffffffff16565b9050609954811115610f9557506099545b6000610fa184836114a1565b90508115610fc657609754610fc690339061010090046001600160a01b0316846114bd565b610fd08582611a53565b95945050505050565b600180610fe7813381611366565b6001600160a01b03831661100d5760405162461bcd60e51b815260040161075790612990565b6000611017611438565b80546001600160a01b0319166001600160a01b039590951694909417909355505050565b600180611049813381611366565b6014841061105657600080fd5b6032831061106357600080fd5b60988490556097546110849061107d9060ff16600a612aae565b849061145c565b60998190556098546040517fb044a1e409eac5c48e5af22d4af52670dd1a99059537a78b31b48c6500a6354e90600090a350505050565b600060016110ca823383611366565b610c51611a61565b6110db82610802565b60016110e8823383611366565b6108428484611afc565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205490565b60018061112b813381611366565b6000611135611438565b6001600160a01b038516600090815260018201602052604090819020805460ff19169055519091507fd7e9ec6e6ecd65492dce6bf513cd6867560d49544421d0783ddf06e76c24470c906107229086906121d1565b60006001611199823383611366565b610c51611ba1565b6001806111af813381611366565b6001600160a01b0383166111d55760405162461bcd60e51b815260040161075790612706565b5050609780546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b611207611873565b6001600160a01b03811661122d5760405162461bcd60e51b815260040161075790612b06565b6112368161189d565b50565b600180611247813381611366565b610c5160016118ef565b60018061125f813381611366565b8360000361126c57600080fd5b6112768385611c1e565b6040516001600160a01b0384169085907ff6554c3a5d28e08c120b5a69c7edbaf52f935bd2596a60b8a18e282cd257cddb90600090a350505050565b6001600160a01b0383166112d85760405162461bcd60e51b815260040161075790612b57565b6001600160a01b0382166112fe5760405162461bcd60e51b815260040161075790612ba6565b6001600160a01b0380841660008181526066602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925906113599085906120ff565b60405180910390a3505050565b6113708383610d1c565b610cdc578015806113915750808015611391575061138f600083610d1c565b155b15610cdc57806113df576113af826001600160a01b03166014611cc3565b6113ba846020611cc3565b6040516020016113cb929190612bff565b60405160208183030381529060405261141f565b6113f3826001600160a01b03166014611cc3565b6113fe846020611cc3565b60405160200161140f929190612c60565b6040516020818303038152906040525b60405162461bcd60e51b81526004016107579190612031565b7feab7fa05d5d1cae44570c8feb9348f82b9573209d63b0696ca655ae06d66ca0090565b60008260000361146e575060006106ab565b600061147a8385612ca8565b9050826114878583612cdd565b146107fb576107fb612cf1565b600080610d8d8385612cdd565b6000828211156114b3576114b3612cf1565b6107fb8284612d07565b6001600160a01b0383166114e35760405162461bcd60e51b815260040161075790612d5c565b6001600160a01b0382166115095760405162461bcd60e51b815260040161075790612dac565b6001600160a01b038316600090815260656020526040902054818110156115425760405162461bcd60e51b815260040161075790612dff565b6001600160a01b0380851660008181526065602052604080822086860390559286168082529083902080548601905591516000805160206132b48339815191529061158e9086906120ff565b60405180910390a3610842565b6000336115a9858285611e34565b610e658585856114bd565b7f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680090565b60006115e26115b4565b90506001600160a01b03821661160a5760405162461bcd60e51b815260040161075790612e3f565b6116148383610d1c565b1580156116295750611627600083610d1c565b155b15610cdc578261165a5761163e600183610d1c565b61165a5760405162461bcd60e51b815260040161075790612e83565b60008381526020829052604090206003015460ff16156116a357600083815260208290526040902060010180546001600160a01b0319166001600160a01b0384161790556116cf565b6000838152602082815260408083206001600160a01b03861684529091529020805460ff191660011790555b60405133906001600160a01b0384169085907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d90600090a4505050565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330090565b600054610100900460ff166117575760405162461bcd60e51b815260040161075790612edb565b610c518282611e78565b600054610100900460ff166117885760405162461bcd60e51b815260040161075790612edb565b610c37611eb8565b600054610100900460ff166117b75760405162461bcd60e51b815260040161075790612edb565b610c37611ef5565b600054610100900460ff166117e65760405162461bcd60e51b815260040161075790612edb565b61123681611f7c565b6001600160a01b0382166118155760405162461bcd60e51b815260040161075790612f1f565b806067600082825461182791906125f9565b90915550506001600160a01b038216600081815260656020526040808220805485019055516000805160206132b4833981519152906118679085906120ff565b60405180910390a35050565b6033546001600160a01b03163314610c375760405162461bcd60e51b815260040161075790612f61565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6118f7610a3c565b6119135760405162461bcd60e51b815260040161075790612fbe565b600061191d61170c565b805460ff19168315151781556040519091506000805160206132d48339815191529061194a9084906120ca565b60405180910390a15050565b61195e610a3c565b1561197b5760405162461bcd60e51b815260040161075790613017565b600061198561170c565b805483151561ffff19909116176101001781556040519091507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258906119cb9033906121d1565b60405180910390a16000805160206132d48339815191528260405161194a91906120ca565b60006119fa61170c565b6001600160a01b0384166000818152600183016020526040808220805460ff19168715159081179091559051939450927f92e6de539d0ff917ae205ae97aa446aea072b3dcb57e224c6af01e575a52fd6e9190a3505050565b6000336106a58185856114bd565b611a69610a3c565b611a855760405162461bcd60e51b815260040161075790612fbe565b6000611a8f61170c565b805461ffff191681556040519091507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa90611acb9033906121d1565b60405180910390a16000805160206132d48339815191526000604051611af191906120ca565b60405180910390a150565b6000611b066115b4565b60008481526020829052604090206003015490915060ff1615611b3b5760405162461bcd60e51b815260040161075790613068565b611b458383610d1c565b15610cdc576000838152602082815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4505050565b600054610100900460ff1615611bc95760405162461bcd60e51b8152600401610757906130bc565b60005460ff90811614610c37576000805460ff191660ff9081179091556040517f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249891611c14916121ba565b60405180910390a1565b6001600160a01b038216611c445760405162461bcd60e51b81526004016107579061310a565b6001600160a01b03821660009081526065602052604090205481811015611c7d5760405162461bcd60e51b815260040161075790613159565b6001600160a01b0383166000818152606560205260408082208585039055606780548690039055519091906000805160206132b4833981519152906113599086906120ff565b6060826000611cd3846002612ca8565b611cde9060026125f9565b6001600160401b03811115611cf557611cf5612238565b6040519080825280601f01601f191660200182016040528015611d1f576020820181803683370190505b509050600360fc1b81600081518110611d3a57611d3a613169565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611d6957611d69613169565b60200101906001600160f81b031916908160001a9053506000611d8d856002612ca8565b611d989060016125f9565b90505b6001811115611e10576f181899199a1a9b1b9c1cb0b131b232b360811b83600f1660108110611dcc57611dcc613169565b1a60f81b828281518110611de257611de2613169565b60200101906001600160f81b031916908160001a90535060049290921c91611e098161317f565b9050611d9b565b508115610d8d57848460405163e22e27eb60e01b8152600401610757929190613196565b6000611e4084846110f2565b905060001981146108425781811015611e6b5760405162461bcd60e51b8152600401610757906131e5565b61084284848484036112b2565b600054610100900460ff16611e9f5760405162461bcd60e51b815260040161075790612edb565b6068611eab83826131f5565b506069610cdc82826131f5565b600054610100900460ff16611edf5760405162461bcd60e51b815260040161075790612edb565b6000611ee961170c565b805461ffff1916905550565b600054610100900460ff16611f1c5760405162461bcd60e51b815260040161075790612edb565b6000611f266115b4565b600080805260209190915260408082206003808201805460ff199081166001908117909255600280850187905593820180546001600160a01b031916331790559085529284209081018054909316909255015550565b600054610100900460ff16611fa35760405162461bcd60e51b815260040161075790612edb565b6000611fad611438565b80546001600160a01b0319166001600160a01b03939093169290921790915550565b60005b83811015611fea578181015183820152602001611fd2565b50506000910152565b601f01601f191690565b6000612007825190565b80845260208401935061201e818560208601611fcf565b61202781611ff3565b9093019392505050565b602080825281016107fb8184611ffd565b60006001600160a01b0382166106ab565b61205c81612042565b811461123657600080fd5b80356106ab81612053565b8061205c565b80356106ab81612072565b6000806040838503121561209957612099600080fd5b60006120a58585612067565b92505060206120b685828601612078565b9150509250929050565b8015155b82525050565b602081016106ab82846120c0565b6000602082840312156120ed576120ed600080fd5b6000610d8d8484612067565b806120c4565b602081016106ab82846120f9565b60008060006060848603121561212557612125600080fd5b60006121318686612067565b935050602061214286828701612067565b925050604061215386828701612078565b9150509250925092565b60006020828403121561217257612172600080fd5b6000610d8d8484612078565b6000806040838503121561219457612194600080fd5b60006121a08585612078565b92505060206120b685828601612067565b60ff81166120c4565b602081016106ab82846121b1565b6120c481612042565b602081016106ab82846121c8565b80151561205c565b80356106ab816121df565b60008060006060848603121561220a5761220a600080fd5b60006122168686612078565b9350506020612227868287016121e7565b925050604061215386828701612067565b634e487b7160e01b600052604160045260246000fd5b61225782611ff3565b81018181106001600160401b038211171561227457612274612238565b6040525050565b600061228660405190565b9050612292828261224e565b919050565b60006001600160401b038211156122b0576122b0612238565b6122b982611ff3565b60200192915050565b82818337506000910152565b60006122e16122dc84612297565b61227b565b9050828152602081018484840111156122fc576122fc600080fd5b6123078482856122c2565b509392505050565b600082601f83011261232357612323600080fd5b8135610d8d8482602086016122ce565b60ff811661205c565b80356106ab81612333565b600080600080600080600080610100898b03121561236757612367600080fd5b60006123738b8b612078565b98505060208901356001600160401b0381111561239257612392600080fd5b61239e8b828c0161230f565b97505060408901356001600160401b038111156123bd576123bd600080fd5b6123c98b828c0161230f565b96505060606123da8b828c0161233c565b95505060806123eb8b828c01612078565b94505060a06123fc8b828c01612078565b93505060c061240d8b828c01612067565b92505060e061241e8b828c01612067565b9150509295985092959890939650565b6000806040838503121561244457612444600080fd5b60006120a58585612078565b60006020828403121561246557612465600080fd5b6000610d8d84846121e7565b6000806040838503121561248757612487600080fd5b60006124938585612067565b92505060206120b6858286016121e7565b60008083601f8401126124b9576124b9600080fd5b5081356001600160401b038111156124d3576124d3600080fd5b6020830191508360018202830111156124ee576124ee600080fd5b9250929050565b6000806020838503121561250b5761250b600080fd5b82356001600160401b0381111561252457612524600080fd5b612530858286016124a4565b92509250509250929050565b6000806040838503121561255257612552600080fd5b60006121a08585612067565b634e487b7160e01b600052602260045260246000fd5b60028104600182168061258857607f821691505b60208210810361259a5761259a61255e565b50919050565b601981526000602082017815da1a5d195b1a5cdd14185d5cd8589b194e881c185d5cd959603a1b815291505b5060200190565b602080825281016106ab816125a0565b634e487b7160e01b600052601160045260246000fd5b808201808211156106ab576106ab6125e3565b603a81526000602082017f496e697469616c206d656d626572206d7573742062652070726f76696465642081527f69662073657474696e67206f6e6c794f6e6520746f2074727565000000000000602082015291505b5060400190565b602080825281016106ab8161260c565b602e81526000602082017f496e697469616c697a61626c653a20636f6e747261637420697320616c72656181526d191e481a5b9a5d1a585b1a5e995960921b60208201529150612662565b602080825281016106ab81612679565b60208082527f43616e6e6f742073657420747265617375727920746f20302061646472657373910190815260006125cc565b602080825281016106ab816126d4565b602781526000602082017f43616e6e6f74207365742066726f7a656e20747265617375727920746f2030208152666164647265737360c81b60208201529150612662565b602080825281016106ab81612716565b60006106ab82612778565b90565b60ff1690565b6120c48161276a565b602081016106ab828461277e565b60006106ab6127758381565b6127aa83612795565b815460001960089490940293841b1916921b91909117905550565b6000610cdc8184846127a1565b81811015610c51576127e56000826127c5565b6001016127d2565b601f821115610cdc576000818152602090206020601f850104810160208510156128145750805b610e216020601f8601048301826127d2565b6000196008929092029190911c191690565b60006128448383612826565b600290930290921792915050565b826001600160401b0381111561286a5761286a612238565b6128748254612574565b61287f8282856127ed565b6000601f8311600181146128ad576000841561289b5750858201355b6128a58582612838565b865550612907565b600085815260208120601f198616915b828110156128dd57888501358255602094850194600190920191016128bd565b868310156128fa57848901356128f6601f891682612826565b8355505b6001600288020188555050505b50505050505050565b602581526000602082017f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77815264207a65726f60d81b60208201529150612662565b602080825281016106ab81612910565b601781526000602082017643616e6e6f742073657420746f2030206164647265737360481b815291506125cc565b602080825281016106ab81612962565b80825b60018511156129df578086048111156129be576129be6125e3565b60018516156129cc57908102905b80026129d88560011c90565b94506129a3565b94509492505050565b6000826129f7575060016107fb565b81612a04575060006107fb565b8160018114612a1a5760028114612a2457612a51565b60019150506107fb565b60ff841115612a3557612a356125e3565b8360020a915084821115612a4b57612a4b6125e3565b506107fb565b5060208310610133831016604e8410600b8410161715612a84575081810a83811115612a7f57612a7f6125e3565b6107fb565b612a9184848460016129a0565b92509050818404811115612aa757612aa76125e3565b0292915050565b600060ff831692506107fb60001984846129e8565b602681526000602082017f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181526564647265737360d01b60208201529150612662565b602080825281016106ab81612ac3565b602481526000602082017f45524332303a20617070726f76652066726f6d20746865207a65726f206164648152637265737360e01b60208201529150612662565b602080825281016106ab81612b16565b602281526000602082017f45524332303a20617070726f766520746f20746865207a65726f206164647265815261737360f01b60208201529150612662565b602080825281016106ab81612b67565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260005b5060170190565b6000612be7825190565b612bf5818560208601611fcf565b9290920192915050565b6000612c0a82612bb6565b9150612c168285612bdd565b7001034b99036b4b9b9b4b733903937b6329607d1b81526011019150610d8d8284612bdd565b761030b7321034b9903737ba1039bab832b91030b236b4b760491b81526000612bd6565b6000612c6b82612bb6565b9150612c778285612bdd565b7001034b99036b4b9b9b4b733903937b6329607d1b81526011019150612c9d8284612bdd565b9150610d8d82612c3c565b818102808215838204851417612cc057612cc06125e3565b5092915050565b634e487b7160e01b600052601260045260246000fd5b600082612cec57612cec612cc7565b500490565b634e487b7160e01b600052600160045260246000fd5b818103818111156106ab576106ab6125e3565b602581526000602082017f45524332303a207472616e736665722066726f6d20746865207a65726f206164815264647265737360d81b60208201529150612662565b602080825281016106ab81612d1a565b602381526000602082017f45524332303a207472616e7366657220746f20746865207a65726f206164647281526265737360e81b60208201529150612662565b602080825281016106ab81612d6c565b602681526000602082017f45524332303a207472616e7366657220616d6f756e7420657863656564732062815265616c616e636560d01b60208201529150612662565b602080825281016106ab81612dbc565b601981526000602082017863616e6e6f74206772616e7420746f2030206164647265737360381b815291506125cc565b602080825281016106ab81612e0f565b601e81526000602082017f4e6578742073757065722061646d696e206d7573742062652061646d696e0000815291506125cc565b602080825281016106ab81612e4f565b602b81526000602082017f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206981526a6e697469616c697a696e6760a81b60208201529150612662565b602080825281016106ab81612e93565b601f81526000602082017f45524332303a206d696e7420746f20746865207a65726f206164647265737300815291506125cc565b602080825281016106ab81612eeb565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572910190815260006125cc565b602080825281016106ab81612f2f565b603081526000602082017f57686974656c6973745061757361626c653a206e6f7420706175736564206f6d81526f1a5d1d1a5b99c81dda1a5d195b1a5cdd60821b60208201529150612662565b602080825281016106ab81612f71565b602c81526000602082017f57686974656c6973745061757361626c653a20706175736564206f6d6974746981526b1b99c81dda1a5d195b1a5cdd60a21b60208201529150612662565b602080825281016106ab81612fce565b602481526000602082017f43616e6e6f74207265766f6b652061206f6e6c792d6f6e652d6d656d62657220815263726f6c6560e01b60208201529150612662565b602080825281016106ab81613027565b602781526000602082017f496e697469616c697a61626c653a20636f6e747261637420697320696e697469815266616c697a696e6760c81b60208201529150612662565b602080825281016106ab81613078565b602181526000602082017f45524332303a206275726e2066726f6d20746865207a65726f206164647265738152607360f81b60208201529150612662565b602080825281016106ab816130cc565b602281526000602082017f45524332303a206275726e20616d6f756e7420657863656564732062616c616e815261636560f01b60208201529150612662565b602080825281016106ab8161311a565b634e487b7160e01b600052603260045260246000fd5b60008161318e5761318e6125e3565b506000190190565b604081016131a482856120f9565b6107fb60208301846120f9565b601d81526000602082017f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000815291506125cc565b602080825281016106ab816131b1565b81516001600160401b0381111561320e5761320e612238565b6132188254612574565b6132238282856127ed565b6020601f831160018114613251576000841561323f5750858201515b6132498582612838565b8655506132ab565b600085815260208120601f198616915b828110156132815788850151825560209485019460019092019101613261565b8683101561329e578489015161329a601f891682612826565b8355505b6001600288020188555050505b50505050505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efd9fd4e447d669d5d23823cbf882de8c31318aee221ac329de57364a97f8fbd27a2646970667358221220840269114358d9fd50ccc8fd24b3e50c95ef24a7d5b962ffd5791963cbb8dc7964736f6c63430008170033
Verified Source Code Full Match
Compiler: v0.8.23+commit.f704f362
EVM: paris
OwnableUpgradeable.sol 95 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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.
*
* By default, the owner account will be the one that deploys the contract. 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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @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 {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
Initializable.sol 166 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @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 Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_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 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_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() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @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 {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
ERC20Upgradeable.sol 377 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.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}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* 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.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => 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.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override 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 override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override 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 `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` 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 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
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 `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `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.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` 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.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[45] private __gap;
}
IERC20MetadataUpgradeable.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @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);
}
IERC20Upgradeable.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
AddressUpgradeable.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
ContextUpgradeable.sol 41 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
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;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
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;
}
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
BlackListUpgradeable.sol 133 lines
// SPDX-License-Identifier: Apache-2.0
// USDT Contracts (last updated v0.4.17) (TetherToken.sol)
pragma solidity ^0.8.23;
import {AccessControlGPSCUpgradeable} from "../security/AccessControlGPSCUpgradeable.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @dev A modified version of the USDT BlackList.sol. We replaced the Ownable contract with
* our custom AccessControlGPSCUpgradeable contract to allow roles to interact with the blacklist
* instead of just one owner. It is also modified to be upgradeable now.
*
* Essentially, this contract allows those with the super admin or admin role to add/remove accounts
* to/from the blacklist and confiscate funds from blacklisted accounts.
*
* This module is used through inheritance with an ERC-20 token. Attach it to your ERC-20 token contract
* to allow it to have blacklist functionality.
*/
abstract contract BlackListUpgradeable is Initializable, ERC20Upgradeable, AccessControlGPSCUpgradeable {
/// @custom:storage-location GPSC.Pausable
struct BlackListStorage {
address treasuryFrozen;
mapping (address account => bool) isBlackListed;
}
// keccak256(abi.encode(uint256(keccak256("GPSC.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant BlackListStorageLocation = 0xeab7fa05d5d1cae44570c8feb9348f82b9573209d63b0696ca655ae06d66ca00;
function _getBlackListStorage() private pure returns (BlackListStorage storage $) {
assembly {
$.slot := BlackListStorageLocation
}
}
/**
* @dev Sets the initial treasury account to send confiscated funds to.
*
* Can be updated later on with admin role.
*/
function __BlackList_init(address _treasuryFrozen) internal onlyInitializing {
__BlackList_init_unchained(_treasuryFrozen);
}
function __BlackList_init_unchained(address _treasuryFrozen) internal onlyInitializing {
BlackListStorage storage $ = _getBlackListStorage();
$.treasuryFrozen = _treasuryFrozen;
}
/**
* @dev Grants `true` if `_maker` is on the blacklist or false otherwise.
*/
function getBlackListStatus(address _maker) external view returns (bool) {
BlackListStorage storage $ = _getBlackListStorage();
return $.isBlackListed[_maker];
}
/**
* @dev Allows admins or the super admin to add an account `_evilUser` to the blacklist.
*/
function addBlackList(address _evilUser) public onlyRole(ADMIN_ROLE, true) {
BlackListStorage storage $ = _getBlackListStorage();
$.isBlackListed[_evilUser] = true;
emit AddedBlackList(_evilUser);
}
/**
* @dev Allows admins or the super admin to remove an account `_clearedUser` from the blacklist.
*/
function removeBlackList(address _clearedUser) public onlyRole(ADMIN_ROLE, true) {
BlackListStorage storage $ = _getBlackListStorage();
$.isBlackListed[_clearedUser] = false;
emit RemovedBlackList(_clearedUser);
}
/**
* @dev Allows admins or the super admin to confiscate tokens from an account `_blackListedUser`.
*
* The account must be on the blacklist.
*
* The tokens are sent to the `treasuryFrozen` address.
*/
function confiscateFunds(address _blackListedUser) public onlyRole(ADMIN_ROLE, true) {
BlackListStorage storage $ = _getBlackListStorage();
require($.isBlackListed[_blackListedUser]);
uint dirtyFunds = balanceOf(_blackListedUser);
_transfer(_blackListedUser, $.treasuryFrozen, dirtyFunds);
emit ConfiscateFunds(_blackListedUser, dirtyFunds);
}
/**
* @dev Allows admins or the super admin to update the `treasuryFrozen` address.
*/
function setTreasuryFrozen(address _treasuryFrozen) public onlyRole(ADMIN_ROLE, true) {
require(_treasuryFrozen != address(0), "Cannot set to 0 address");
BlackListStorage storage $ = _getBlackListStorage();
$.treasuryFrozen = _treasuryFrozen;
}
/**
* @dev Allows caller to read the `treasuryFrozen` address.
*/
function getTreasuryFrozen() public view returns (address) {
BlackListStorage storage $ = _getBlackListStorage();
return $.treasuryFrozen;
}
/**
* @dev Internal contract function for checking whether an address `_account`
* is on the blacklist.
*/
function isBlacklisted(address _account) internal view returns (bool) {
BlackListStorage storage $ = _getBlackListStorage();
return $.isBlackListed[_account];
}
/**
* @dev Emitted when tokens are confiscated in `confiscateFunds`.
*/
event ConfiscateFunds(address indexed _blackListedUser, uint indexed _balance);
/**
* @dev Emitted when an address is added to the blacklist in `addBlackList`.
*/
event AddedBlackList(address _user);
/**
* @dev Emitted when an address is removed from the blacklist in `removeBlackList`.
*/
event RemovedBlackList(address _user);
}
AccessControlGPSCUpgradeable.sol 274 lines
// SPDX-License-Identifier: Apache-2.0
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.23;
import {IAccessControl} from "./IAccessControl.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
/**
* @dev This is a custom modified version of AccessControlUpgradeable.sol from
* OpenZeppelin to allow for single member roles and to change the default roles
* from `DEFAULT_ADMIN_ROLE` to `SUPER_ADMIN_ROLE` and `ADMIN_ROLE`. The ability to
* renounce roles has also been removed. Instead, only the admin of the role can
* remove a role from a user.
*
* Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `SUPER_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke the admin
* role to other accounts. More complex role relationships can be created by using
* {_setRoleAdmin}. There can only be one super admin, but there can be multiple admins.
* The super admin also usually has power to do everything the admin can do.
*
* WARNING: The `SUPER_ADMIN_ROLE`, as with all other roles that only allow one member, must
* be transferred and cannot be revoked nor transferred to the 0 address.
*/
abstract contract AccessControlGPSCUpgradeable is Initializable, IAccessControl {
struct RoleData {
mapping(address account => bool) members;
address member;
bytes32 adminRole;
bool onlyOne;
}
bytes32 public constant SUPER_ADMIN_ROLE = 0x00;
bytes32 public constant ADMIN_ROLE = bytes32(uint256(0x01));
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
struct AccessControlStorage {
mapping(bytes32 role => RoleData) _roles;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;
function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
assembly {
$.slot := AccessControlStorageLocation
}
}
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role. Allows super admin to override.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role, bool superAdminAllowed) {
_checkRole(role, msg.sender, superAdminAllowed);
_;
}
function __AccessControlGPSC_init() internal onlyInitializing {
__AccessControlGPSC_init_unchained();
}
/**
* @dev Sets up the initial roles and sets the initial super admin as the deployer.
*/
function __AccessControlGPSC_init_unchained() internal onlyInitializing {
AccessControlStorage storage $ = _getAccessControlStorage();
// setup super admin
$._roles[SUPER_ADMIN_ROLE].onlyOne = true;
$._roles[SUPER_ADMIN_ROLE].adminRole = SUPER_ADMIN_ROLE;
$._roles[SUPER_ADMIN_ROLE].member = msg.sender;
// setup admins
$._roles[ADMIN_ROLE].onlyOne = false;
$._roles[ADMIN_ROLE].adminRole = SUPER_ADMIN_ROLE;
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].onlyOne ? $._roles[role].member == account : $._roles[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account, bool superAdminAllowed) internal view {
if (!hasRole(role, account)) {
if (!superAdminAllowed || (superAdminAllowed && !hasRole(SUPER_ADMIN_ROLE, account))) {
revert(
superAdminAllowed ?
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32),
" and is not super admin"
)
)
:
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
}
/**
* @dev Modifies the admin of a role.
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function modifyRoleAdmin(bytes32 role, bytes32 adminRole) external override onlyRole(getRoleAdmin(role), true) {
AccessControlStorage storage $ = _getAccessControlStorage();
bytes32 previousAdminRole = $._roles[role].adminRole;
$._roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Modifies whether a role can only have one account or not.
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function modifyRoleOnlyOne(bytes32 role, bool onlyOne, address newMember) external override onlyRole(getRoleAdmin(role), true) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (onlyOne) {
require(newMember != address(0), "Initial member must be provided if setting onlyOne to true");
$._roles[role].member = newMember;
} else {
$._roles[role].member = address(0);
}
$._roles[role].onlyOne = onlyOne;
emit RoleOnlyOneChanged(role, onlyOne, newMember);
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].adminRole;
}
/**
* @dev Returns whether `role` allows only one member or not. See {grantRole} and
* {revokeRole}.
*
* To change whether `role` allows only one member, see {modifyRoleOnlyOne}.
*/
function getRoleIsOnlyOne(bytes32 role) public view override returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].onlyOne;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
* - If the role only allows one member, the role will be transferred to account.
*/
function grantRole(bytes32 role, address account) external override onlyRole(getRoleAdmin(role), true) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - The caller must have ``role``'s admin role.
* - Roles that only allow one member cannot be revoked. They must be transferred via grantRole.
*/
function revokeRole(bytes32 role, address account) external override onlyRole(getRoleAdmin(role), true) {
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
* Cannot grant super admin to extra roles.
* Cannot only promote a current admin to super admin.
*/
function _grantRole(bytes32 role, address account) internal {
AccessControlStorage storage $ = _getAccessControlStorage();
require(account != address(0), "cannot grant to 0 address");
if (!hasRole(role, account) && !hasRole(SUPER_ADMIN_ROLE, account)) {
if (role == SUPER_ADMIN_ROLE) {
require(hasRole(ADMIN_ROLE, account), "Next super admin must be admin");
}
if ($._roles[role].onlyOne) {
$._roles[role].member = account;
} else {
$._roles[role].members[account] = true;
}
emit RoleGranted(role, account, msg.sender);
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*/
function _revokeRole(bytes32 role, address account) internal {
AccessControlStorage storage $ = _getAccessControlStorage();
require(!$._roles[role].onlyOne, "Cannot revoke a only-one-member role");
if (hasRole(role, account)) {
$._roles[role].members[account] = false;
emit RoleRevoked(role, account, msg.sender);
}
}
}
IAccessControl.sol 102 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (access/IAccessControl.sol)
pragma solidity ^0.8.23;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `SUPER_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when changing whether a role can have only one member to `newOnlyOne`
*/
event RoleOnlyOneChanged(bytes32 indexed role, bool indexed newOnlyOne, address indexed newMember);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Modifies the admin of a role.
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function modifyRoleAdmin(bytes32 role, bytes32 adminRole) external;
/**
* @dev Modifies whether a role can only have one account or not.
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function modifyRoleOnlyOne(bytes32 role, bool onlyOne, address newMember) external;
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Returns whether `role` allows only one member or not. See {grantRole} and
* {revokeRole}.
*
* To change whether `role` allows only one member, see {modifyRoleOnlyOne}.
*/
function getRoleIsOnlyOne(bytes32 role) external view returns (bool);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
}
WhitelistPausableUpgradeable.sol 195 lines
// SPDX-License-Identifier: Apache-2.0
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.23;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account. Modified to include a
* whitelist that allows these users to interact during a whitelisted pause, but
* not during a global pause.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract WhitelistPausableUpgradeable is Initializable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _allowWhitelist;
bool _paused;
mapping(address account => bool) _whitelist;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev Emitted when the whitelist accounts are set allowed or not allowed to bypass the pause in `allowWhitelist`.
*/
event AllowWhitelist(bool allowWhitelist);
/**
* @dev Emitted when an `account` whitelist status is updated.
*/
event WhitelistStatusChange(address indexed account, bool indexed status);
/**
* @dev Initializes the contract in unpaused state.
*/
function __WhitelistPausable_init() internal onlyInitializing {
__WhitelistPausable_init_unchained();
}
function __WhitelistPausable_init_unchained() internal onlyInitializing {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
$._allowWhitelist = false;
}
/**
* @dev Returns true if the contract is paused and the sender is on the whitelist.
* Else, it returns false if the sender is not on the whitelist or if it's not paused.
*/
function paused() public view returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused && ($._allowWhitelist ? !$._whitelist[msg.sender] : true);
}
/**
* @dev Returns true if the contract is paused, and false otherwise regardless of whitelist.
*/
function pausedOmitWhitelist() public view returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused;
}
/**
* @dev Returns true if the given `account` is whitelisted. Else, returns false.
*/
function isWhitelisted(address account) public view returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._whitelist[account];
}
/**
* @dev Modifier to make a function callable only when the contract is not paused
* or when the contract is paused but the sender is on the whitelist.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "WhitelistPausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused regardless of the whitelist.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPausedOmitWhitelist() {
require(!pausedOmitWhitelist(), "WhitelistPausable: paused omitting whitelist");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused and the
* sender is not on the whitelist.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "WhitelistPausable: not paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPausedOmitWhitelist() {
require(pausedOmitWhitelist(), "WhitelistPausable: not paused omitting whitelist");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause(bool allowWhitelist) internal whenNotPausedOmitWhitelist {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
$._allowWhitelist = allowWhitelist;
emit Paused(msg.sender);
emit AllowWhitelist(allowWhitelist);
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal whenPausedOmitWhitelist {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
$._allowWhitelist = false;
emit Unpaused(msg.sender);
emit AllowWhitelist(false);
}
/**
* @dev Function to allow or disallow accounts on the whitelist to bypass the pause.
*
* Requirements:
*
* - The contract must be paused regardless of whitelist.
*/
function _setAllowWhitelist(bool allowWhitelist) internal whenPausedOmitWhitelist {
PausableStorage storage $ = _getPausableStorage();
$._allowWhitelist = allowWhitelist;
emit AllowWhitelist(allowWhitelist);
}
/**
* @dev Function to set an account's whitelist status.
*/
function _setAccountWhitelistStatus(address account, bool whitelist) internal {
PausableStorage storage $ = _getPausableStorage();
$._whitelist[account] = whitelist;
emit WhitelistStatusChange(account, whitelist);
}
}
StablecoinUpgradeable.sol 302 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.23;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {WhitelistPausableUpgradeable} from "./security/WhitelistPausableUpgradeable.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {BlackListUpgradeable} from "./access/BlackListUpgradeable.sol";
import {AccessControlGPSCUpgradeable} from "./security/AccessControlGPSCUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "./utils/SafeMath.sol";
/**
* @dev Fully upgradeable stablecoin pegged to fiat currency by off-chain price oracle. Tokens can be burned and minted to match reserves.
* Inherits from AccessControl to set roles for certain functionality. The default roles are super admin and admin. Super admins can usually do
* everything that an admin can do.
*
* Whitelist pause feature to disallow certain functions from running while paused. With the whitelist enabled, accounts that are on the whitelist
* can bypass the pause.
*
* Blacklist feature to stop certain accounts from transacting with the token. Tokens can be confiscated at will by admins from people on the blacklist.
*
* This stablecoin also features an optional fee system that takes a small fee for every transfer that occurs.
*/
contract StablecoinUpgradeable is OwnableUpgradeable, WhitelistPausableUpgradeable, ERC20Upgradeable, AccessControlGPSCUpgradeable, BlackListUpgradeable {
using SafeMath for uint;
uint constant HARD_BASIS_POINTS_LIMIT = 20;
uint constant HARD_MAX_FEE_LIMIT = 50;
uint8 private _decimals;
address public treasury;
uint public basisPointsRate;
uint public maximumFee;
bool public _paused;
string public collateralProof;
/**
* @dev The contract can be initialized with a number of tokens
* All the tokens are deposited to the super admin address initially
*
* @param _initialSupply Initial supply of the contract
* @param _name Token Name
* @param _symbol Token symbol
* @param __decimals Token decimals
* @param _initialBasisPoints Initial fee amount for transfers
* @param _initialMaxFee Initial max fee amount for transfers
* @param _treasury Address to receive fees
* @param _treasuryFrozen Address to receieve confiscated tokens
*/
function initialize(uint256 _initialSupply, string memory _name, string memory _symbol, uint8 __decimals, uint _initialBasisPoints, uint _initialMaxFee, address _treasury, address _treasuryFrozen) public initializer {
require(_treasury != address(0), "Cannot set treasury to 0 address");
require(_treasuryFrozen != address(0), "Cannot set frozen treasury to 0 address");
__ERC20_init(_name, _symbol);
__WhitelistPausable_init();
__AccessControlGPSC_init();
__BlackList_init(_treasuryFrozen);
_decimals = __decimals;
basisPointsRate = _initialBasisPoints;
maximumFee = _initialMaxFee;
treasury = _treasury;
_mint(msg.sender, _initialSupply);
}
/**
* @dev Returns the token decimals. Overrides the default 18 decimals.
*
* @return _decimals The number of token decimals
*/
function decimals() public view override returns (uint8) {
return _decimals;
}
/**
* @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.
*
* Takes a fee and sends it to the `treasury` address if fees are enabled.
*
* Only works when the contract is not paused. Also, the transaction will revert if the sender or receiver
* is on the blacklist.
*
* @param _to Account to send tokens to
* @param _value Amount to send in wei
* @return bool True if the transaction is successful, false otherwise
*/
function transfer(address _to, uint256 _value) public override whenNotPaused returns (bool) {
require(!isBlacklisted(msg.sender));
require(!isBlacklisted(_to));
uint256 fee = (_value.mul(basisPointsRate)).div(10000);
if (fee > maximumFee) {
fee = maximumFee;
}
uint256 sendAmount = _value.sub(fee);
if (fee > 0) {
_transfer(msg.sender, treasury, fee);
}
return super.transfer(_to, sendAmount);
}
/**
* @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.
*
* Takes a fee and sends it to the `treasury` address if fees are enabled.
*
* Only works when the contract is not paused. Also, the transaction will revert if the sender or receiver
* is on the blacklist.
*
* @param _from Account to send from
* @param _to Account to send to
* @param _value Amount to send in wei
* @return bool True if the transaction is successful, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public override whenNotPaused returns (bool) {
require(!isBlacklisted(_from));
require(!isBlacklisted(_to));
uint256 fee = (_value.mul(basisPointsRate)).div(10000);
if (fee > maximumFee) {
fee = maximumFee;
}
uint256 sendAmount = _value.sub(fee);
if (fee > 0) {
_transfer(_from, treasury, fee);
}
return super.transferFrom(_from, _to, sendAmount);
}
/**
* @dev Creates a `_amount` amount of tokens and assigns them to `_to`, by transferring it from address(0).
* Relies on the `_transfer` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Only admins and super admins can do this.
*
* @param _amount Amount to mint in wei
* @param _to Account to mint to
*/
function mint(uint256 _amount, address _to) public onlyRole(ADMIN_ROLE, true) {
require(_amount != 0);
_mint(_to, _amount);
emit Mint(_amount, _to);
}
/**
* @dev Destroys a `_amount` amount of tokens from `_from`, lowering the total supply.
* Relies on the `_transfer` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Only admins and super admins can do this.
*
* @param _amount Amount to burn in wei
* @param _from Account to burn from
*/
function burn(uint256 _amount, address _from) public onlyRole(ADMIN_ROLE, true) {
require(_amount != 0);
_burn(_from, _amount);
emit Burn(_amount, _from);
}
/**
* @dev Sets fee percentage and maximum fee percentage taken from transfers.
* `_newBasisPoints` must not surpass HARD_BASIS_POINTS_LIMIT
* `_newMaxFee` must not surpass HARD_MAX_FEE_LIMIT
*
* Only admins and super admins can set this.
*
* @param _newBasisPoints Percentage of the transaction to take as a fee. Calculated as _newBasisPoints / 10000
* @param _newMaxFee The new maximum fee amount to take in a transaction.
*/
function setParams(uint _newBasisPoints, uint _newMaxFee) public onlyRole(ADMIN_ROLE, true) {
// Ensure transparency by hardcoding limit beyond which fees can never be added
require(_newBasisPoints < HARD_BASIS_POINTS_LIMIT);
require(_newMaxFee < HARD_MAX_FEE_LIMIT);
basisPointsRate = _newBasisPoints;
maximumFee = _newMaxFee.mul(10**_decimals);
emit Params(basisPointsRate, maximumFee);
}
/**
* @dev Sets the treasury address where fee amounts are delivered.
*
* Only admins and super admins can set this.
*
* @param _treasury The new address for the treasury
*/
function setTreasury(address _treasury) public onlyRole(ADMIN_ROLE, true) {
require(_treasury != address(0), "Cannot set treasury to 0 address");
treasury = _treasury;
}
/**
* @dev Permanently disables all future upgrades.
*
* Only the super admin can do this ans must be used with caution.
*/
function disableUpgrades() public onlyRole(SUPER_ADMIN_ROLE, true) {
_disableInitializers();
}
/**
* @dev Sets a pause on all token transactions.
* Allows a parameter `allowWhitelist` for whether or not the
* accounts on the whitelist can bypass this pause.
*
* Only super admins can set this.
*
* @param allowWhitelist Initializes whether whitelisted accounts can bypass the whitelist.
*/
function globalPause(bool allowWhitelist) external onlyRole(SUPER_ADMIN_ROLE, true) {
_pause(allowWhitelist);
}
/**
* @dev Removes a pause on all token transactions.
* Allows a parameter for whether or not the
* accounts on the whitelist can bypass this pause.
*
* Only super admins can set this.
*/
function globalUnpause() external onlyRole(SUPER_ADMIN_ROLE, true) {
_unpause();
}
/**
* @dev When paused, allows whitelisted accounts to bypass the pause.
*
* Only admins and super admins can set this.
*/
function whitelistPause() external onlyRole(ADMIN_ROLE, true) {
_setAllowWhitelist(true);
}
/**
* @dev When paused, disallows whitelisted accounts to bypass the pause.
*
* Only admins and super admins can set this.
*/
function whitelistUnpause() external onlyRole(ADMIN_ROLE, true) {
_setAllowWhitelist(false);
}
/**
* @dev Adds or removes `account` to/from the whitelist
*
* Only admins and super admins can set this.
*
* @param account The address of the account to add/remove to/from the whitelist.
* @param whitelist True if adding the account to the whitelist, false if removing
*/
function setAccountWhitelistStatus(address account, bool whitelist) external onlyRole(ADMIN_ROLE, true) {
_setAccountWhitelistStatus(account, whitelist);
}
/**
* @dev Sets the collateral proof of the token
*
* Only super admins can set this.
*
* @param _collateralProof The URL of the collateral proof.
*/
function setCollateralProof(string calldata _collateralProof) external onlyRole(SUPER_ADMIN_ROLE, true) {
collateralProof = _collateralProof;
}
function v() public pure returns (uint256) {
return 1;
}
/**
* @dev Called when new token are issued
* @param _amount Amount minted
* @param _to Address to mint to
*/
event Mint(uint indexed _amount, address indexed _to);
/**
* @dev Called when tokens are burned
* @param _amount Amount burned
* @param _from Address to burn from
*/
event Burn(uint indexed _amount, address indexed _from);
/**
* @dev Called if contract ever adds fees
* @param _feeBasisPoints New fee basis points to set
* @param _maxFee New max fee to set
*/
event Params(uint indexed _feeBasisPoints, uint indexed _maxFee);
}
SafeMath.sol 36 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
SUPER_ADMIN_ROLE 0x4460bdd6 → bytes32
_paused 0x16c61ccc → bool
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
basisPointsRate 0xdd644f72 → uint256
collateralProof 0x305eb41e → string
decimals 0x313ce567 → uint8
getBlackListStatus 0x59bf1abe → bool
getRoleAdmin 0x248a9ca3 → bytes32
getRoleIsOnlyOne 0x88c16fe8 → bool
getTreasuryFrozen 0x43e2ae92 → address
hasRole 0x91d14854 → bool
isWhitelisted 0x3af32abf → bool
maximumFee 0x35390714 → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pausedOmitWhitelist 0x575850a1 → bool
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
treasury 0x61d027b3 → address
v 0x7c2efcba → uint256
Write Contract 27 functions
These functions modify contract state and require a wallet transaction to execute.
addBlackList 0x0ecb93c0
address _evilUser
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
burn 0xfcd3533c
uint256 _amount
address _from
confiscateFunds 0xa7040ef9
address _blackListedUser
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
disableUpgrades 0xec669036
No parameters
globalPause 0x87c1be6e
bool allowWhitelist
globalUnpause 0xce190578
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
initialize 0x6f0ccec9
uint256 _initialSupply
string _name
string _symbol
uint8 __decimals
uint256 _initialBasisPoints
uint256 _initialMaxFee
address _treasury
address _treasuryFrozen
mint 0x94bf804d
uint256 _amount
address _to
modifyRoleAdmin 0x79cd8d76
bytes32 role
bytes32 adminRole
modifyRoleOnlyOne 0x4601c329
bytes32 role
bool onlyOne
address newMember
removeBlackList 0xe4997dc5
address _clearedUser
renounceOwnership 0x715018a6
No parameters
revokeRole 0xd547741f
bytes32 role
address account
setAccountWhitelistStatus 0x8eed871d
address account
bool whitelist
setCollateralProof 0x9f3c6ccb
string _collateralProof
setParams 0xc0324c77
uint256 _newBasisPoints
uint256 _newMaxFee
setTreasury 0xf0f44260
address _treasury
setTreasuryFrozen 0xb7a22973
address _treasuryFrozen
transfer 0xa9059cbb
address _to
uint256 _value
returns: bool
transferFrom 0x23b872dd
address _from
address _to
uint256 _value
returns: bool
transferOwnership 0xf2fde38b
address newOwner
whitelistPause 0xf30d6da1
No parameters
whitelistUnpause 0x71687504
No parameters
Recent Transactions
No transactions found for this address