Address Contract Verified
Address
0x9FBb8863005a30c9888C5EBe096076e8062Cd221
Balance
0 ETH
Nonce
1
Code Size
9914 bytes
Creator
0x5991Ec04...dd39 at tx 0xe08cc4d9...849d27
Indexed Transactions
0
Contract Bytecode
9914 bytes
0x608060405234801561001057600080fd5b50600436106101165760003560e01c80637911ef9d116100a2578063c42bd05a11610071578063c42bd05a1461026d578063db068e0e1461028b578063e3aea651146102a7578063f2fde38b146102c3578063fc316285146102df57610116565b80637911ef9d146101f95780638456cb59146102155780638da5cb5b1461021f578063bfc102a01461023d57610116565b8063454b0608116100e9578063454b06081461017d578063485d8d9a146101995780635c975abb146101b55780636ff1c9bc146101d3578063715018a6146101ef57610116565b806329dcb0cf1461011b5780633ba0b9a9146101395780633d2cc56c146101575780633f4ba83a14610173575b600080fd5b6101236102fd565b6040516101309190611731565b60405180910390f35b610141610321565b60405161014e9190611731565b60405180910390f35b610171600480360381019061016c9190611917565b610327565b005b61017b61044d565b005b6101976004803603810190610192919061198c565b61049d565b005b6101b360048036038101906101ae9190611917565b61083f565b005b6101bd610962565b6040516101ca91906119d4565b60405180910390f35b6101ed60048036038101906101e89190611a2d565b610975565b005b6101f7610b05565b005b610213600480360381019061020e9190611917565b610b19565b005b61021d610c40565b005b610227610c91565b6040516102349190611a69565b60405180910390f35b61025760048036038101906102529190611a84565b610cba565b6040516102649190611731565b60405180910390f35b610275610cd2565b6040516102829190611b10565b60405180910390f35b6102a560048036038101906102a0919061198c565b610cf8565b005b6102c160048036038101906102bc9190611bdc565b610d7a565b005b6102dd60048036038101906102d89190611a84565b610f4a565b005b6102e7610fcd565b6040516102f49190611c7e565b60405180910390f35b7f0000000000000000000000000000000000000000000000000000000065e11a8081565b60035481565b61032f610ff3565b6000815103610373576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161036a90611cf6565b60405180910390fd5b60005b8151811015610449576103ad82828151811061039557610394611d16565b5b6020026020010151600461107190919063ffffffff16565b61043e576103df8282815181106103c7576103c6611d16565b5b602002602001015160046110a190919063ffffffff16565b508181815181106103f3576103f2611d16565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff167ff9b68063b051b82957fa193585681240904fed808db8b30fc5a2d2202c6ed62760405160405180910390a25b806001019050610376565b5050565b610455610ff3565b60008060146101000a81548160ff0219169083151502179055507fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d1693360405160405180910390a1565b6104b133600461107190919063ffffffff16565b156104f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e890611d91565b60405180910390fd5b7f0000000000000000000000000000000000000000000000000000000065e11a804211158061055f575080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b61059e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161059590611dfd565b60405180910390fd5b600081036105e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d890611e69565b60405180910390fd5b600060149054906101000a900460ff1615610631576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161062890611ed5565b60405180910390fd5b610680333083600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166110d1909392919063ffffffff16565b6000670de0b6b3a7640000600354836106999190611f24565b6106a39190611f95565b9050600081036106e8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106df90612012565b60405180910390fd5b7f0000000000000000000000000000000000000000000000000000000065e11a804211156107675781600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461075f9190612032565b925050819055505b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1933836040518363ffffffff1660e01b81526004016107c4929190612066565b600060405180830381600087803b1580156107de57600080fd5b505af11580156107f2573d6000803e3d6000fd5b5050505080823373ffffffffffffffffffffffffffffffffffffffff167fd083678824038160bef3975359ab29f19c3f0e9bcf9d7ead540a492d4d678b6360405160405180910390a45050565b610847610ff3565b600081510361088b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161088290611cf6565b60405180910390fd5b60005b815181101561095e576000600660008484815181106108b0576108af611d16565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081818151811061090957610908611d16565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff167f2dd3f6320f953acf0428741e31145ce700b1e63a85db97b580419246a53fc8b660405160405180910390a280600101905061088e565b5050565b600060149054906101000a900460ff1681565b61097d610ff3565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610a0d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a04906120db565b60405180910390fd5b60008173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610a489190611a69565b602060405180830381865afa158015610a65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a899190612110565b9050610abd610a96610c91565b828473ffffffffffffffffffffffffffffffffffffffff1661115a9092919063ffffffff16565b808273ffffffffffffffffffffffffffffffffffffffff167f2e39961a70a10f4d46383948095ac2752b3ee642a7c76aa827410aaff08c2e5160405160405180910390a35050565b610b0d610ff3565b610b1760006111e0565b565b610b21610ff3565b6000815103610b65576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b5c90611cf6565b60405180910390fd5b60005b8151811015610c3c57610b9f828281518110610b8757610b86611d16565b5b6020026020010151600461107190919063ffffffff16565b15610c3157610bd2828281518110610bba57610bb9611d16565b5b602002602001015160046112a490919063ffffffff16565b50818181518110610be657610be5611d16565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff167f2b6bf71b58b3583add364b3d9060ebf8019650f65f5be35f5464b9cb3e4ba2d460405160405180910390a25b806001019050610b68565b5050565b610c48610ff3565b6001600060146101000a81548160ff0219169083151502179055507f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e75260405160405180910390a1565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60066020528060005260406000206000915090505481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610d00610ff3565b60008103610d43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3a90612189565b60405180910390fd5b80600381905550807f1d5de90e7c5b244ac5797698b15fe80a92524d933dafd79e001daf844555fb1c60405160405180910390a250565b610d82610ff3565b60008484905003610dc8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dbf90611cf6565b60405180910390fd5b818190508484905014610e10576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e07906121f5565b60405180910390fd5b60005b84849050811015610f4357828282818110610e3157610e30611d16565b5b9050602002013560066000878785818110610e4f57610e4e611d16565b5b9050602002016020810190610e649190611a84565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610ead9190612215565b92505081905550828282818110610ec757610ec6611d16565b5b90506020020135858583818110610ee157610ee0611d16565b5b9050602002016020810190610ef69190611a84565b73ffffffffffffffffffffffffffffffffffffffff167fc745436130c43fc8fabab3b7d3d67b6e7be30fd0b846b35e68d39bedcbd31ffe60405160405180910390a3806001019050610e13565b5050505050565b610f52610ff3565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610fc1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fb8906122bb565b60405180910390fd5b610fca816111e0565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610ffb6112d4565b73ffffffffffffffffffffffffffffffffffffffff16611019610c91565b73ffffffffffffffffffffffffffffffffffffffff161461106f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161106690612327565b60405180910390fd5b565b6000611099836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6112dc565b905092915050565b60006110c9836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6112ff565b905092915050565b611154846323b872dd60e01b8585856040516024016110f293929190612347565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061136f565b50505050565b6111db8363a9059cbb60e01b8484604051602401611179929190612066565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061136f565b505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b60006112cc836000018373ffffffffffffffffffffffffffffffffffffffff1660001b611437565b905092915050565b600033905090565b600080836001016000848152602001908152602001600020541415905092915050565b600061130b83836112dc565b611364578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050611369565b600090505b92915050565b60006113d1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661154b9092919063ffffffff16565b90506000815114806113f35750808060200190518101906113f291906123aa565b5b611432576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161142990612449565b60405180910390fd5b505050565b6000808360010160008481526020019081526020016000205490506000811461153f5760006001826114699190612032565b90506000600186600001805490506114819190612032565b90508181146114f05760008660000182815481106114a2576114a1611d16565b5b90600052602060002001549050808760000184815481106114c6576114c5611d16565b5b90600052602060002001819055508387600101600083815260200190815260200160002081905550505b8560000180548061150457611503612469565b5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611545565b60009150505b92915050565b606061155a8484600085611563565b90509392505050565b6060824710156115a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161159f9061250a565b60405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516115d1919061259b565b60006040518083038185875af1925050503d806000811461160e576040519150601f19603f3d011682016040523d82523d6000602084013e611613565b606091505b509150915061162487838387611630565b92505050949350505050565b6060831561169257600083510361168a5761164a856116a5565b611689576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611680906125fe565b60405180910390fd5b5b82905061169d565b61169c83836116c8565b5b949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b6000825111156116db5781518083602001fd5b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161170f9190612662565b60405180910390fd5b6000819050919050565b61172b81611718565b82525050565b60006020820190506117466000830184611722565b92915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6117ae82611765565b810181811067ffffffffffffffff821117156117cd576117cc611776565b5b80604052505050565b60006117e061174c565b90506117ec82826117a5565b919050565b600067ffffffffffffffff82111561180c5761180b611776565b5b602082029050602081019050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061184d82611822565b9050919050565b61185d81611842565b811461186857600080fd5b50565b60008135905061187a81611854565b92915050565b600061189361188e846117f1565b6117d6565b905080838252602082019050602084028301858111156118b6576118b561181d565b5b835b818110156118df57806118cb888261186b565b8452602084019350506020810190506118b8565b5050509392505050565b600082601f8301126118fe576118fd611760565b5b813561190e848260208601611880565b91505092915050565b60006020828403121561192d5761192c611756565b5b600082013567ffffffffffffffff81111561194b5761194a61175b565b5b611957848285016118e9565b91505092915050565b61196981611718565b811461197457600080fd5b50565b60008135905061198681611960565b92915050565b6000602082840312156119a2576119a1611756565b5b60006119b084828501611977565b91505092915050565b60008115159050919050565b6119ce816119b9565b82525050565b60006020820190506119e960008301846119c5565b92915050565b60006119fa82611842565b9050919050565b611a0a816119ef565b8114611a1557600080fd5b50565b600081359050611a2781611a01565b92915050565b600060208284031215611a4357611a42611756565b5b6000611a5184828501611a18565b91505092915050565b611a6381611842565b82525050565b6000602082019050611a7e6000830184611a5a565b92915050565b600060208284031215611a9a57611a99611756565b5b6000611aa88482850161186b565b91505092915050565b6000819050919050565b6000611ad6611ad1611acc84611822565b611ab1565b611822565b9050919050565b6000611ae882611abb565b9050919050565b6000611afa82611add565b9050919050565b611b0a81611aef565b82525050565b6000602082019050611b256000830184611b01565b92915050565b600080fd5b60008083601f840112611b4657611b45611760565b5b8235905067ffffffffffffffff811115611b6357611b62611b2b565b5b602083019150836020820283011115611b7f57611b7e61181d565b5b9250929050565b60008083601f840112611b9c57611b9b611760565b5b8235905067ffffffffffffffff811115611bb957611bb8611b2b565b5b602083019150836020820283011115611bd557611bd461181d565b5b9250929050565b60008060008060408587031215611bf657611bf5611756565b5b600085013567ffffffffffffffff811115611c1457611c1361175b565b5b611c2087828801611b30565b9450945050602085013567ffffffffffffffff811115611c4357611c4261175b565b5b611c4f87828801611b86565b925092505092959194509250565b6000611c6882611add565b9050919050565b611c7881611c5d565b82525050565b6000602082019050611c936000830184611c6f565b92915050565b600082825260208201905092915050565b7f496e76616c6964206172726179206c656e677468000000000000000000000000600082015250565b6000611ce0601483611c99565b9150611ceb82611caa565b602082019050919050565b60006020820190508181036000830152611d0f81611cd3565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f41646472657373206973206c697374656420696e20626c61636b6c6973740000600082015250565b6000611d7b601e83611c99565b9150611d8682611d45565b602082019050919050565b60006020820190508181036000830152611daa81611d6e565b9050919050565b7f446561646c696e653b2077686974656c6973746564203c205f616d6f756e7400600082015250565b6000611de7601f83611c99565b9150611df282611db1565b602082019050919050565b60006020820190508181036000830152611e1681611dda565b9050919050565b7f496e76616c6964206d6967726174696f6e20616d6f756e740000000000000000600082015250565b6000611e53601883611c99565b9150611e5e82611e1d565b602082019050919050565b60006020820190508181036000830152611e8281611e46565b9050919050565b7f4d6967726174696f6e2070617573656400000000000000000000000000000000600082015250565b6000611ebf601083611c99565b9150611eca82611e89565b602082019050919050565b60006020820190508181036000830152611eee81611eb2565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611f2f82611718565b9150611f3a83611718565b9250828202611f4881611718565b91508282048414831517611f5f57611f5e611ef5565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000611fa082611718565b9150611fab83611718565b925082611fbb57611fba611f66565b5b828204905092915050565b7f496e76616c6964206d6967726174656420616d6f756e74000000000000000000600082015250565b6000611ffc601783611c99565b915061200782611fc6565b602082019050919050565b6000602082019050818103600083015261202b81611fef565b9050919050565b600061203d82611718565b915061204883611718565b92508282039050818111156120605761205f611ef5565b5b92915050565b600060408201905061207b6000830185611a5a565b6120886020830184611722565b9392505050565b7f496e76616c696420616464726573730000000000000000000000000000000000600082015250565b60006120c5600f83611c99565b91506120d08261208f565b602082019050919050565b600060208201905081810360008301526120f4816120b8565b9050919050565b60008151905061210a81611960565b92915050565b60006020828403121561212657612125611756565b5b6000612134848285016120fb565b91505092915050565b7f496e76616c69642065786368616e676520726174650000000000000000000000600082015250565b6000612173601583611c99565b915061217e8261213d565b602082019050919050565b600060208201905081810360008301526121a281612166565b9050919050565b7f4172726179206c656e677468206d69736d617463680000000000000000000000600082015250565b60006121df601583611c99565b91506121ea826121a9565b602082019050919050565b6000602082019050818103600083015261220e816121d2565b9050919050565b600061222082611718565b915061222b83611718565b925082820190508082111561224357612242611ef5565b5b92915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006122a5602683611c99565b91506122b082612249565b604082019050919050565b600060208201905081810360008301526122d481612298565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000612311602083611c99565b915061231c826122db565b602082019050919050565b6000602082019050818103600083015261234081612304565b9050919050565b600060608201905061235c6000830186611a5a565b6123696020830185611a5a565b6123766040830184611722565b949350505050565b612387816119b9565b811461239257600080fd5b50565b6000815190506123a48161237e565b92915050565b6000602082840312156123c0576123bf611756565b5b60006123ce84828501612395565b91505092915050565b7f5361666545524332303a204552433230206f7065726174696f6e20646964206e60008201527f6f74207375636365656400000000000000000000000000000000000000000000602082015250565b6000612433602a83611c99565b915061243e826123d7565b604082019050919050565b6000602082019050818103600083015261246281612426565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b7f416464726573733a20696e73756666696369656e742062616c616e636520666f60008201527f722063616c6c0000000000000000000000000000000000000000000000000000602082015250565b60006124f4602683611c99565b91506124ff82612498565b604082019050919050565b60006020820190508181036000830152612523816124e7565b9050919050565b600081519050919050565b600081905092915050565b60005b8381101561255e578082015181840152602081019050612543565b60008484015250505050565b60006125758261252a565b61257f8185612535565b935061258f818560208601612540565b80840191505092915050565b60006125a7828461256a565b915081905092915050565b7f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000600082015250565b60006125e8601d83611c99565b91506125f3826125b2565b602082019050919050565b60006020820190508181036000830152612617816125db565b9050919050565b600081519050919050565b60006126348261261e565b61263e8185611c99565b935061264e818560208601612540565b61265781611765565b840191505092915050565b6000602082019050818103600083015261267c8184612629565b90509291505056fea26469706673582212204e958e0d71c286c47c6aee80939db335d2e68a8c58ccd78857cba33e0b4696c164736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: No
Migration.sol 312 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "./IOFTMintable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
/**
* @title Migration
* @notice This contract facilitates the migration of an old token to a new token.
* @dev The exchange rate between the old and new tokens is set by the contract owner.
* Whitelisted addresses can migrate tokens after the deadline.
* Non-whitelisted addresses can only migrate tokens before the deadline.
* The contract owner can add or remove addresses from the whitelist or blacklist.
* The contract owner can also pause or unpause the migration process.
*/
contract Migration is Ownable {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
/// @notice Paused status of the migration.
bool public paused;
/// @notice Old token address to migrate from.
IERC20 public prevToken;
/// @notice New token address to migrate to.
IOFTMintable public newToken;
/// @notice Exchange rate for swapping old token to new one.
uint256 public exchangeRate;
/// @dev Exchange rate divider, hardcoded for the current use case.
uint256 constant DIVIDER = 1e18;
/// @notice Migration deadline for non-whitelisted addresses.
uint256 public immutable deadline;
/// @dev Set of blacklisted addresses.
EnumerableSet.AddressSet private blacklist;
/// @notice Amounts for whitelisted addresses.
mapping(address => uint256) public whitelistedAmounts;
/**
* @notice Event emitted when the exchange rate is set.
* @param rate exchange rate.
*/
event SetExchangeRate(uint256 indexed rate);
/**
* @notice Event emitted when tokens are migrated.
* @param account Address which migrated tokens.
* @param prev Amount of old tokens migrated.
* @param migrated Amount of new tokens received.
*/
event Migrated(
address indexed account,
uint256 indexed prev,
uint256 indexed migrated
);
/**
* @notice Event emitted when an address is added to the blacklist.
* @param account Address added to the blacklist.
*/
event AddedToBlacklist(address indexed account);
/**
* @notice Event emitted when an address is removed from the blacklist.
* @param account Address removed from the blacklist.
*/
event RemovedFromBlacklist(address indexed account);
/**
* @notice Event emitted when an address is added to the whitelist.
* @param account Address added to the whitelist.
* @param amount Amount to whitelist.
*/
event AddedWhitelistedAmount(
address indexed account,
uint256 indexed amount
);
/**
* @notice Event emitted when address is removed from whitelist.
* @dev White listed amount is set to 0.
* @param account Address removed from the whitelist.
*/
event RemovedWhitelistedAmount(address indexed account);
/**
* @notice Event emitted when ERC20 tokens are withdrawn by the owner.
* @param token Address of token withdrawn.
* @param amount Amount of token withdrawn.
*/
event EmergencyWithdrawn(address indexed token, uint256 indexed amount);
/**
* @notice Event emitted when migration is paused.
*/
event Paused();
/**
* @notice Event emitted when migration is unpaused.
*/
event Unpaused();
/**
* @notice Modifier to check if the caller is in the blacklist.
*/
modifier isBlacklist() {
require(
!blacklist.contains(msg.sender),
"Address is listed in blacklist"
);
_;
}
/**
* @dev Constructor.
* @param _prev address of previous token.
* @param _migrated address of new token.
* @param _rate exchange rate.
* @param _deadline migration deadline (timestamp).
*/
constructor(
address _prev,
address _migrated,
uint256 _rate,
uint256 _deadline
) {
require(_prev != address(0), "Invalid address");
require(_migrated != address(0), "Invalid address");
require(_rate != 0, "Invalid exchange rate");
require(_deadline >= block.timestamp + 7 days, "Invalid deadline");
prevToken = IERC20(_prev);
newToken = IOFTMintable(_migrated);
exchangeRate = _rate;
deadline = _deadline;
emit SetExchangeRate(_rate);
}
///////////////////////
/// User Functions ///
///////////////////////
/**
* @notice Migrate old tokens to new tokens.
* @dev This function can only be called by non-blacklisted addresses.
* @dev Account needs first to approve the contract to spend the old tokens.
* @dev If the deadline is passed, the account needs to have whitelisted amount.
* @param _amount amount of old tokens to migrate.
*/
function migrate(uint256 _amount) external isBlacklist {
require(
block.timestamp <= deadline ||
whitelistedAmounts[msg.sender] >= _amount,
"Deadline; whitelisted < _amount"
);
require(_amount != 0, "Invalid migration amount");
require(!paused, "Migration paused");
// 1. receive previous token
prevToken.safeTransferFrom(msg.sender, address(this), _amount);
// 2. migrate to new token
uint256 migratedAmt = (_amount * exchangeRate) / DIVIDER;
require(migratedAmt != 0, "Invalid migrated amount");
if (block.timestamp > deadline) {
whitelistedAmounts[msg.sender] -= _amount;
}
newToken.mint(msg.sender, migratedAmt);
emit Migrated(msg.sender, _amount, migratedAmt);
}
///////////////////////
/// Owner Functions ///
///////////////////////
/**
* @notice Set exchange rate.
* @dev This function can only be called by the contract owner.
* @param _rate new exchange rate.
*/
function setExchangeRate(uint256 _rate) external onlyOwner {
require(_rate != 0, "Invalid exchange rate");
exchangeRate = _rate;
emit SetExchangeRate(_rate);
}
/**
* @notice Add whitelisted amounts for the accounts.
* @dev This function can only be called by the contract owner.
* @dev Both `_list` and `_amounts` arrays must have the same length.
* @param _list array of accounts.
* @param _amounts array of amounts to whitelist.
*/
function addWhitelistedAmounts(
address[] calldata _list,
uint256[] calldata _amounts
) external onlyOwner {
require(_list.length != 0, "Invalid array length");
require(_list.length == _amounts.length, "Array length mismatch");
for (uint i; i < _list.length; ) {
whitelistedAmounts[_list[i]] += _amounts[i];
emit AddedWhitelistedAmount(_list[i], _amounts[i]);
unchecked {
++i;
}
}
}
/**
* @notice Remove whitelisted amount of the account.
* @dev This function can only be called by the contract owner.
* @param _list array of accounts.
*/
function removeWhitelistedAmounts(
address[] memory _list
) external onlyOwner {
require(_list.length != 0, "Invalid array length");
for (uint i; i < _list.length; ) {
whitelistedAmounts[_list[i]] = 0;
emit RemovedWhitelistedAmount(_list[i]);
unchecked {
++i;
}
}
}
/**
* @notice Add addresses to blacklist.
* @dev This function can only be called by the contract owner.
* @param _list array of blacklisted accounts.
*/
function addBlacklist(address[] memory _list) external onlyOwner {
require(_list.length != 0, "Invalid array length");
for (uint i; i < _list.length; ) {
if (!blacklist.contains(_list[i])) {
blacklist.add(_list[i]);
emit AddedToBlacklist(_list[i]);
}
unchecked {
++i;
}
}
}
/**
* @notice Remove addresses from blacklist.
* @dev This function can only be called by the contract owner.
* @param _list array of accounts.
*/
function removeBlacklist(address[] memory _list) external onlyOwner {
require(_list.length != 0, "Invalid array length");
for (uint i; i < _list.length; ) {
if (blacklist.contains(_list[i])) {
blacklist.remove(_list[i]);
emit RemovedFromBlacklist(_list[i]);
}
unchecked {
++i;
}
}
}
/**
* @notice Emergency withdraw ERC20 tokens.
* @dev This function can only be called by the contract owner.
* @param _token address of ERC20 token to withdraw.
*/
function emergencyWithdraw(IERC20 _token) external onlyOwner {
require(address(_token) != address(prevToken), "Invalid address");
uint256 _amount = _token.balanceOf(address(this));
_token.safeTransfer(owner(), _amount);
emit EmergencyWithdrawn(address(_token), _amount);
}
/**
* @notice Pause migration.
* @dev This function can only be called by the contract owner.
*/
function pause() external onlyOwner {
paused = true;
emit Paused();
}
/**
* @notice Unpause migration.
* @dev This function can only be called by the contract owner.
*/
function unpause() external onlyOwner {
paused = false;
emit Unpaused();
}
}
IOFTMintable.sol 20 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
interface IOFTMintable {
/**
* @notice Mint tokens.
* @dev Only callable by address with minter role.
* @param _account Address to mint tokens to.
* @param _amount Amount of tokens to mint.
*/
function mint(address _account, uint256 _amount) external;
/**
* @notice Set minter role.
* @param _minter address for adding or removing minter role.
* @param _isMinter boolean value for defining minter role.
*/
function setMinter(address _minter, bool _isMinter) external;
}
Address.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 Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* 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);
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* 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 Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_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);
}
}
IERC20.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 IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
EnumerableSet.sol 378 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
deadline 0x29dcb0cf → uint256
exchangeRate 0x3ba0b9a9 → uint256
newToken 0xc42bd05a → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
prevToken 0xfc316285 → address
whitelistedAmounts 0xbfc102a0 → uint256
Write Contract 11 functions
These functions modify contract state and require a wallet transaction to execute.
addBlacklist 0x3d2cc56c
address[] _list
addWhitelistedAmounts 0xe3aea651
address[] _list
uint256[] _amounts
emergencyWithdraw 0x6ff1c9bc
address _token
migrate 0x454b0608
uint256 _amount
pause 0x8456cb59
No parameters
removeBlacklist 0x7911ef9d
address[] _list
removeWhitelistedAmounts 0x485d8d9a
address[] _list
renounceOwnership 0x715018a6
No parameters
setExchangeRate 0xdb068e0e
uint256 _rate
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address