Address Contract Verified
Address
0xAa693EfC498E12A43A0c1C716A0750DDe4F8748d
Balance
0 ETH
Nonce
1
Code Size
16476 bytes
Creator
0x5424404D...a4A1 at tx 0xb131ff16...a00964
Indexed Transactions
0
Contract Bytecode
16476 bytes
0x608060405234801561001057600080fd5b50600436106103b95760003560e01c8063789ff0e1116101f4578063b1974a021161011a578063d547741f116100ad578063e7a8daa81161007c578063e7a8daa814610898578063ea6f2e86146108ab578063eccbada4146108d2578063fa5a8c83146108db57600080fd5b8063d547741f1461083f578063d6bf561514610852578063da5cc8a014610872578063e5b39e871461088557600080fd5b8063c051ef0b116100e9578063c051ef0b146107d8578063c28f4392146107eb578063cb0269bc14610812578063d4f86e3b1461081f57600080fd5b8063b1974a0214610797578063b2d5ae44146107aa578063b7b1b8e9146107b2578063b9025966146107c557600080fd5b80639057aa9f116101925780639570370f116101615780639570370f146107495780639f37ad4a14610769578063a217fddf1461077c578063a57e48451461078457600080fd5b80639057aa9f1461071157806391d148541461071a57806391d311f01461072d578063944771041461073657600080fd5b806384b0196e116101ce57806384b0196e146106bd5780638903ab9d146106d85780638b326516146106eb5780638c80fd90146106fe57600080fd5b8063789ff0e11461068f5780637a803da0146106a25780638456cb59146106b557600080fd5b806336568abe116102e457806357bf4c4d11610277578063668a702911610246578063668a70291461063957806367a00d361461064c5780637558683714610655578063776958961461067c57600080fd5b806357bf4c4d146105e0578063582abd12146105f45780635c975abb1461061b5780635c99d8cc1461062657600080fd5b80634b79401e116102b35780634b79401e146105bf5780634e49df0a146105c75780634e71d92d146105cf57806351a96609146105d757600080fd5b806336568abe14610574578063375b3c0a146105875780633f4ba83a1461059057806343f2ee311461059857600080fd5b8063176898c91161035c5780632eba42001161032b5780632eba4200146104e95780632f2ff15d146104fc5780632fe4cd931461050f578063327d83b81461053057600080fd5b8063176898c91461048057806319023882146104935780631afecb97146104a6578063248a9ca3146104c657600080fd5b80630600646a116103985780630600646a146104445780630db194571461045b578063131827ab146104635780631495eb071461046b57600080fd5b8062e77aa6146103be57806301300af91461040257806301ffc9a714610421575b600080fd5b6103e57f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b6040516001600160a01b0390911681526020015b60405180910390f35b60065461040f9060ff1681565b60405160ff90911681526020016103f9565b61043461042f3660046135ee565b6108ee565b60405190151581526020016103f9565b61044d600c5481565b6040519081526020016103f9565b610434610925565b61044d601481565b61047e610479366004613673565b61096b565b005b61047e61048e3660046136d4565b610d76565b61047e6104a1366004613707565b610d95565b61044d6104b43660046137f6565b60116020526000908152604090205481565b61044d6104d4366004613811565b60009081526020819052604090206001015490565b61047e6104f736600461382a565b611489565b61047e61050a366004613854565b6114b1565b600f5461051d9061ffff1681565b60405161ffff90911681526020016103f9565b61054361053e36600461382a565b6114db565b60408051968752602087019590955293850192909252606084015261ffff16608083015260a082015260c0016103f9565b61047e610582366004613854565b611536565b61044d600e5481565b61047e6115b4565b61044d7f000000000000000000000000000000000000000000021bfbc6e8f0f78dc0000081565b61051d6115ca565b61044d6115d6565b61047e6115e2565b61044d60135481565b600f5461051d9062010000900461ffff1681565b61044d7f2aeb38be3df14d720aeb10a2de6df09b0fb3cd5c5ec256283a22d4593110ca4081565b60015460ff16610434565b61044d6106343660046137f6565b6116a2565b61044d610647366004613880565b6116e5565b61044d600d5481565b61040f7f000000000000000000000000000000000000000000000000000000000000000681565b61051d61068a366004613811565b611716565b6009546103e5906001600160a01b031681565b61047e6106b0366004613811565b611769565b61047e61177a565b6106c561178d565b6040516103f997969594939291906138ec565b61044d6106e63660046137f6565b611816565b61044d6106f936600461382a565b61191b565b61047e61070c366004613811565b611a48565b61044d60075481565b610434610728366004613854565b611a59565b61044d60085481565b61044d6107443660046137f6565b611a82565b61075c6107573660046137f6565b611b75565b6040516103f99190613982565b61047e6107773660046139fe565b611c24565b61044d600081565b61044d6107923660046139fe565b611ca2565b61047e6107a5366004613a20565b611cdd565b61047e611ef7565b61047e6107c03660046137f6565b6120f2565b61044d6107d33660046139fe565b612118565b61044d6107e63660046139fe565b6121dd565b6103e57f0000000000000000000000007d3e4165fd7d8590fb2a415a550f7bdece5c4f5281565b6015546104349060ff1681565b61044d61082d3660046137f6565b60146020526000908152604090205481565b61047e61084d366004613854565b61228a565b61044d6108603660046137f6565b60126020526000908152604090205481565b600b546103e5906001600160a01b031681565b61047e6108933660046137f6565b6122af565b61044d6108a6366004613811565b61233f565b61040f7f000000000000000000000000000000000000000000000000000000000000001281565b61044d600a5481565b61047e6108e936600461382a565b612389565b60006001600160e01b03198216637965db0b60e01b148061091f57506301ffc9a760e01b6001600160e01b03198316145b92915050565b3360009081526011602052604081205415801561094a5750600061094833611a82565b115b80156109585750600c544210155b8015610966575060155460ff165b905090565b6000610976816124b7565b60008460ff161161098657600080fd5b600282146109af5760405162461bcd60e51b81526004016109a690613a62565b60405180910390fd5b60065460ff908116908516106109fd5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b60448201526064016109a6565b600083836000818110610a1257610a12613ac9565b90506020020135118015610a3f5750600083836001818110610a3657610a36613ac9565b90506020020135115b610a8b5760405162461bcd60e51b815260206004820152601e60248201527f416d6f756e7473206d7573742062652067726561746572207468616e2030000060448201526064016109a6565b82826000818110610a9e57610a9e613ac9565b9050602002013560056000600187610ab69190613af5565b60ff1660ff168152602001908152602001600020600081548110610adc57610adc613ac9565b906000526020600020015410610b045760405162461bcd60e51b81526004016109a690613b0e565b82826001818110610b1757610b17613ac9565b9050602002013560056000600187610b2f9190613af5565b60ff1660ff168152602001908152602001600020600181548110610b5557610b55613ac9565b906000526020600020015410610b7d5760405162461bcd60e51b81526004016109a690613b78565b600654610b8f9060019060ff16613af5565b60ff168460ff161015610d525782826000818110610baf57610baf613ac9565b9050602002013560056000866001610bc79190613be2565b60ff1660ff168152602001908152602001600020600081548110610bed57610bed613ac9565b906000526020600020015411610c775760405162461bcd60e51b815260206004820152604360248201527f4e65787420746965722066696e6320616d6f756e74206d75737420626520677260448201527f6561746572207468616e2063757272656e7420746965722066696e6320616d6f6064820152621d5b9d60ea1b608482015260a4016109a6565b82826001818110610c8a57610c8a613ac9565b9050602002013560056000866001610ca29190613be2565b60ff1660ff168152602001908152602001600020600181548110610cc857610cc8613ac9565b906000526020600020015411610d525760405162461bcd60e51b815260206004820152604360248201527f4e6578742074696572207573647420616d6f756e74206d75737420626520677260448201527f6561746572207468616e2063757272656e742074696572207573647420616d6f6064820152621d5b9d60ea1b608482015260a4016109a6565b60ff84166000908152600560205260409020610d6f908484613530565b5050505050565b6000610d81816124b7565b506015805460ff1916911515919091179055565b610d9d6124c1565b610da5612509565b33600081815260146020526040812054869103610e0e57600e54811015610e0e5760405162461bcd60e51b815260206004820152601d60248201527f5374616b696e672062616c616e63652062656c6f77206d696e696d756d00000060448201526064016109a6565b600c54421015610e605760405162461bcd60e51b815260206004820152601b60248201527f426f6e64696e6720686173206e6f74207374617274656420796574000000000060448201526064016109a6565b600d54421115610ea65760405162461bcd60e51b8152602060048201526011602482015270109bdb991a5b99c81a185cc8195b991959607a1b60448201526064016109a6565b83421015610ef65760405162461bcd60e51b815260206004820152601d60248201527f54696d657374616d70206d75737420626520696e20746865207061737400000060448201526064016109a6565b4260075485610f059190613bfb565b1015610f4a5760405162461bcd60e51b8152602060048201526014602482015273151a5b595cdd185b5c081a5cc81d1bdbc81bdb1960621b60448201526064016109a6565b610f573387878787612560565b610f975760405162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b60448201526064016109a6565b60008711610fe75760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e203000000060448201526064016109a6565b7f000000000000000000000000000000000000000000021bfbc6e8f0f78dc0000087600a546110169190613bfb565b11156110645760405162461bcd60e51b815260206004820152601860248201527f426f6e64696e672073616c65206361702072656163686564000000000000000060448201526064016109a6565b336000908152601060205260409020546014116110c35760405162461bcd60e51b815260206004820152601a60248201527f4d617820626f6e6473207065722075736572207265616368656400000000000060448201526064016109a6565b60006110ef887f000000000000000000000000000000000000000000000000000000000000001261261d565b905060006110fc89611716565b9050600061110a8a89611ca2565b9050611136817f000000000000000000000000000000000000000000000000000000000000000661261d565b90506000670de0b6b3a764000061114d8386613c0e565b6111579190613c2d565b905061118c611166338c61191b565b7f000000000000000000000000000000000000000000000000000000000000000661261d565b336000908152601260205260409020546111a7908390613bfb565b11156111f55760405162461bcd60e51b815260206004820152601760248201527f4d617820626f6e6420616d6f756e74207265616368656400000000000000000060448201526064016109a6565b60006112008c61233f565b905060106000336001600160a01b03166001600160a01b031681526020019081526020016000206040518060c001604052808e8152602001600081526020014281526020018381526020018661ffff16815260200161127f867f000000000000000000000000000000000000000000000000000000000000000661267d565b9052815460018082018455600093845260208085208451600690940201928355830151908201556040820151600282015560608201516003820155608082015160048201805461ffff191661ffff90921691909117905560a090910151600590910155600a80548e92906112f4908490613bfb565b90915550503360009081526012602052604081208054849290611318908490613bfb565b9091555050600854600090156113b25760006127106008548561133b9190613c0e565b6113459190613c2d565b9050611371817f000000000000000000000000000000000000000000000000000000000000000661267d565b6009549092506113b0906001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7811691339116856126b3565b505b6113dc837f000000000000000000000000000000000000000000000000000000000000000661267d565b905080601360008282546113f09190613bfb565b9091555050600b54611431906001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7811691339116846126b3565b604080518781526020810186905261ffff871681830152905133917fea42ad359daf2189c72681fed90521c157b5da39a29eb4810cc011b3dd4104c4919081900360600190a25050505050505050610d6f6001600255565b6000611494816124b7565b506001600160a01b03909116600090815260146020526040902055565b6000828152602081905260409020600101546114cc816124b7565b6114d68383612713565b505050565b601060205281600052604060002081815481106114f757600080fd5b600091825260209091206006909102018054600182015460028301546003840154600485015460059095015493965091945092909161ffff9091169086565b6001600160a01b03811633146115a65760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016109a6565b6115b08282612797565b5050565b60006115bf816124b7565b6115c76127fc565b50565b60006109666000611716565b6000610966600061233f565b60005b336000908152601060205260409020548110156115c75733600090815260106020526040812080548390811061161d5761161d613ac9565b60009182526020918290206040805160c08101825260069093029091018054808452600182015494840185905260028201549284019290925260038101546060840152600481015461ffff1660808401526005015460a0830152909250116116855750611690565b61168e8261284e565b505b8061169a81613c4f565b9150506115e5565b6001600160a01b03811660009081526012602052604081205461091f907f000000000000000000000000000000000000000000000000000000000000000661267d565b6005602052816000526040600020818154811061170157600080fd5b90600052602060002001600091509150505481565b600080611724600a546129d0565b61ffff169050600061174284600a5461173d9190613bfb565b6129d0565b61ffff169050600060026117568385613bfb565b6117609190613c2d565b95945050505050565b6000611774816124b7565b50600755565b6000611785816124b7565b6115c7612aa5565b6000606080828080836117c17f4475746368426f6e6453616c650000000000000000000000000000000000000d6003612ae0565b6117ec7f31000000000000000000000000000000000000000000000000000000000000016004612ae0565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6001600160a01b0381166000908152601060209081526040808320805482518185028101850190935280835284938493929190849084015b828210156118ba5760008481526020908190206040805160c08101825260068602909201805483526001808201548486015260028201549284019290925260038101546060840152600481015461ffff1660808401526005015460a0830152908352909201910161184e565b50505050905060005b81518110156119125760006118f08383815181106118e3576118e3613ac9565b6020026020010151612b84565b90506118fc8185613bfb565b935050808061190a90613c4f565b9150506118c3565b50909392505050565b6001600160a01b0382166000908152601460205260408120541561195857506001600160a01b03821660009081526014602052604090205461091f565b60065460009061196d9060019060ff16613af5565b90505b60ff8116156119f75760ff81166000908152600560205260408120805490919061199c5761199c613ac9565b906000526020600020015483106119e55760ff81166000908152600560205260409020805460019081106119d2576119d2613ac9565b906000526020600020015491505061091f565b806119ef81613c68565b915050611970565b506000805260056020527f05b8ccbb9d4d8fb16ea74ce3c29a41f1b461fbdaff4714a0d9a8eb05499746bc80546001908110611a3557611a35613ac9565b9060005260206000200154905092915050565b6000611a53816124b7565b50600e55565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6001600160a01b0381166000908152601060209081526040808320805482518185028101850190935280835284938493929190849084015b82821015611b265760008481526020908190206040805160c08101825260068602909201805483526001808201548486015260028201549284019290925260038101546060840152600481015461ffff1660808401526005015460a08301529083529092019101611aba565b50505050905060005b815181101561191257818181518110611b4a57611b4a613ac9565b60200260200101516000015183611b619190613bfb565b925080611b6d81613c4f565b915050611b2f565b6001600160a01b0381166000908152601060209081526040808320805482518185028101850190935280835260609492939192909184015b82821015611c195760008481526020908190206040805160c08101825260068602909201805483526001808201548486015260028201549284019290925260038101546060840152600481015461ffff1660808401526005015460a08301529083529092019101611bad565b505050509050919050565b6000611c2f816124b7565b818310611c965760405162461bcd60e51b815260206004820152602f60248201527f426f6e642073746172742074696d65206d757374206265206c6573732074686160448201526e6e20626f6e6420656e642074696d6560881b60648201526084016109a6565b50600c91909155600d55565b600080611cae84611716565b61ffff169050612710611cc18282613c85565b611ccb9085613c0e565b611cd59190613c2d565b949350505050565b6000611ce8816124b7565b60028214611d085760405162461bcd60e51b81526004016109a690613a62565b600083836000818110611d1d57611d1d613ac9565b90506020020135118015611d4a5750600083836001818110611d4157611d41613ac9565b90506020020135115b611d965760405162461bcd60e51b815260206004820152601e60248201527f416d6f756e7473206d7573742062652067726561746572207468616e2030000060448201526064016109a6565b82826000818110611da957611da9613ac9565b90506020020135600560006001600660009054906101000a900460ff16611dd09190613af5565b60ff1660ff168152602001908152602001600020600081548110611df657611df6613ac9565b906000526020600020015410611e1e5760405162461bcd60e51b81526004016109a690613b0e565b82826001818110611e3157611e31613ac9565b90506020020135600560006001600660009054906101000a900460ff16611e589190613af5565b60ff1660ff168152602001908152602001600020600181548110611e7e57611e7e613ac9565b906000526020600020015410611ea65760405162461bcd60e51b81526004016109a690613b78565b60065460ff166000908152600560205260409020611ec5908484613530565b506006805460ff16906000611ed983613c98565b91906101000a81548160ff021916908360ff16021790555050505050565b611eff6124c1565b600c544210158015611f13575060155460ff165b611f535760405162461bcd60e51b8152602060048201526011602482015270526566756e64206e6f742061637469766560781b60448201526064016109a6565b3360009081526011602052604090205415611fa25760405162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e4818db185a5b5959608a1b60448201526064016109a6565b6000611fad33611a82565b905060008111611ff25760405162461bcd60e51b815260206004820152601060248201526f4e6f2076657374656420746f6b656e7360801b60448201526064016109a6565b33600090815260106020526040812061200a9161357b565b3360009081526012602052604081208054908290559061204a827f000000000000000000000000000000000000000000000000000000000000000661267d565b9050806013600082825461205e9190613c85565b9250508190555082600a60008282546120779190613c85565b9091555050600b546120b7906001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec78116911633846126b3565b60405181815233907fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d0651906020015b60405180910390a2505050565b60006120fd816124b7565b506001600160a01b0316600090815260146020526040812055565b6000806121258484611ca2565b9050612151847f000000000000000000000000000000000000000000000000000000000000001261261d565b935061217d817f000000000000000000000000000000000000000000000000000000000000000661261d565b90506000670de0b6b3a76400006121948387613c0e565b61219e9190613c2d565b90506121ca817f000000000000000000000000000000000000000000000000000000000000000661267d565b9050612710600854826117569190613c0e565b6000806121ea8484611ca2565b9050612216847f000000000000000000000000000000000000000000000000000000000000001261261d565b9350612242817f000000000000000000000000000000000000000000000000000000000000000661261d565b9050611cd5670de0b6b3a764000061225a8387613c0e565b6122649190613c2d565b7f000000000000000000000000000000000000000000000000000000000000000661267d565b6000828152602081905260409020600101546122a5816124b7565b6114d68383612797565b60006122ba816124b7565b6001600160a01b03821661231c5760405162461bcd60e51b815260206004820152602360248201527f426f6e6420726573657276652063616e6e6f74206265207a65726f206164647260448201526265737360e81b60648201526084016109a6565b50600b80546001600160a01b0319166001600160a01b0392909216919091179055565b60008061234b83611716565b61ffff169050600060646123628362015180613c0e565b61236c9190613c2d565b600f5490915061ffff620100008204811691611ccb911683613c0e565b6000612394816124b7565b6127108211156123fb5760405162461bcd60e51b815260206004820152602c60248201527f426f6e6420666565206d757374206265206c657373207468616e206f7220657160448201526b075616c20746f2031303030360a41b60648201526084016109a6565b6001600160a01b03831661245c5760405162461bcd60e51b815260206004820152602260248201527f46656520726573657276652063616e6e6f74206265207a65726f206164647265604482015261737360f01b60648201526084016109a6565b50600980546001600160a01b0319166001600160a01b039390931692909217909155600855565b600060208351101561249f5761249883612c08565b905061091f565b816124aa8482613d3f565b5060ff905061091f565b90565b6115c78133612c46565b60015460ff16156125075760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016109a6565b565b600280540361255a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016109a6565b60028055565b604080517f0730076ac49111cd34345c6f172317b7847facdbd734ca4c972ec4f0dfb8884660208201526001600160a01b03871691810191909152606081018590526080810184905260a0810183905260009081906125d79060c00160405160208183030381529060405280519060200120612c9f565b905060006125e58285612ccc565b90506126117f2aeb38be3df14d720aeb10a2de6df09b0fb3cd5c5ec256283a22d4593110ca4082611a59565b98975050505050505050565b60008160ff1660120361263157508161091f565b60128260ff16111561265d57612648601283613af5565b61265390600a613ee3565b6124989084613c2d565b612668826012613af5565b61267390600a613ee3565b6124989084613c0e565b60008160ff1660120361269157508161091f565b60128260ff1611156126a857612668601283613af5565b612648826012613af5565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b17905261270d908590612cf0565b50505050565b61271d8282611a59565b6115b0576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556127533390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6127a18282611a59565b156115b0576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b612804612dc5565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b3360009081526010602052604090205481106128a15760405162461bcd60e51b8152602060048201526012602482015271092dcecc2d8d2c840c4dedcc840d2dcc8caf60731b60448201526064016109a6565b3360009081526010602052604081208054839081106128c2576128c2613ac9565b600091825260208083206040805160c08101825260069094029091018054845260018101549284019290925260028201549083015260038101546060830152600481015461ffff166080830152600581015460a0830152925061292490612b84565b90508082600101600082825461293a9190613bfb565b9091555050336000908152601160205260408120805483929061295e908490613bfb565b9091555050600b5461299e906001600160a01b037f0000000000000000000000007d3e4165fd7d8590fb2a415a550f7bdece5c4f528116911633846126b3565b60405181815233907fd8138f8a3f377c5259ca548e70e4c2de94f129f5a11036a15b69513cba2b426a906020016120e5565b6000807f000000000000000000000000000000000000000000021bfbc6e8f0f78dc00000612a0061271085613c0e565b612a0a9190613c2d565b90506000612a587f00000000000000000000000000000000000000000000000000000000000004e27f00000000000000000000000000000000000000000000000000000000000009c4613ef2565b61ffff1690506000612710612a6d8484613c0e565b612a779190613c2d565b6117609061ffff7f00000000000000000000000000000000000000000000000000000000000009c416613c85565b612aad6124c1565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833612831565b606060ff8314612af35761249883612e0e565b818054612aff90613cb7565b80601f0160208091040260200160405190810160405280929190818152602001828054612b2b90613cb7565b8015612b785780601f10612b4d57610100808354040283529160200191612b78565b820191906000526020600020905b815481529060010190602001808311612b5b57829003601f168201915b5050505050905061091f565b600080600083606001518460400151612b9d9190613bfb565b9050804210612bb25783606001519150612bd8565b83604001514211612bc65760009150612bd8565b6040840151612bd59042613c85565b91505b600084602001518560600151848760000151612bf49190613c0e565b612bfe9190613c2d565b6117609190613c85565b600080829050601f81511115612c33578260405163305a27a960e01b81526004016109a69190613f14565b8051612c3e82613f27565b179392505050565b612c508282611a59565b6115b057612c5d81612e4d565b612c68836020612e5f565b604051602001612c79929190613f4b565b60408051601f198184030181529082905262461bcd60e51b82526109a691600401613f14565b600061091f612cac613002565b8360405161190160f01b8152600281019290925260228201526042902090565b6000806000612cdb858561312d565b91509150612ce881613172565b509392505050565b6000612d45826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166132bc9092919063ffffffff16565b9050805160001480612d66575080806020019051810190612d669190613fc0565b6114d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016109a6565b60015460ff166125075760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016109a6565b60606000612e1b836132cb565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b606061091f6001600160a01b03831660145b60606000612e6e836002613c0e565b612e79906002613bfb565b67ffffffffffffffff811115612e9157612e916136f1565b6040519080825280601f01601f191660200182016040528015612ebb576020820181803683370190505b509050600360fc1b81600081518110612ed657612ed6613ac9565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612f0557612f05613ac9565b60200101906001600160f81b031916908160001a9053506000612f29846002613c0e565b612f34906001613bfb565b90505b6001811115612fac576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612f6857612f68613ac9565b1a60f81b828281518110612f7e57612f7e613ac9565b60200101906001600160f81b031916908160001a90535060049490941c93612fa581613fdd565b9050612f37565b508315612ffb5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016109a6565b9392505050565b6000306001600160a01b037f000000000000000000000000aa693efc498e12a43a0c1c716a0750dde4f8748d1614801561305b57507f000000000000000000000000000000000000000000000000000000000000000146145b1561308557507fc8d9107fec88e9c5196451cf7831d955b9888b76423e259ab5200585a505440a90565b610966604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527fa4dfb499f7a9df3228710132505c0e06cbba621d938c8910941396f38aebada2918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60008082516041036131635760208301516040840151606085015160001a613157878285856132f3565b9450945050505061316b565b506000905060025b9250929050565b600081600481111561318657613186613ff4565b0361318e5750565b60018160048111156131a2576131a2613ff4565b036131ef5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016109a6565b600281600481111561320357613203613ff4565b036132505760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016109a6565b600381600481111561326457613264613ff4565b036115c75760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016109a6565b6060611cd584846000856133b7565b600060ff8216601f81111561091f57604051632cd44ac360e21b815260040160405180910390fd5b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561332a57506000905060036133ae565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561337e573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166133a7576000600192509250506133ae565b9150600090505b94509492505050565b6060824710156134185760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016109a6565b600080866001600160a01b03168587604051613434919061400a565b60006040518083038185875af1925050503d8060008114613471576040519150601f19603f3d011682016040523d82523d6000602084013e613476565b606091505b509150915061348787838387613492565b979650505050505050565b606083156135015782516000036134fa576001600160a01b0385163b6134fa5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016109a6565b5081611cd5565b611cd583838151156135165781518083602001fd5b8060405162461bcd60e51b81526004016109a69190613f14565b82805482825590600052602060002090810192821561356b579160200282015b8281111561356b578235825591602001919060010190613550565b5061357792915061359c565b5090565b50805460008255600602906000526020600020908101906115c791906135b1565b5b80821115613577576000815560010161359d565b5b8082111561357757600080825560018201819055600282018190556003820181905560048201805461ffff1916905560058201556006016135b2565b60006020828403121561360057600080fd5b81356001600160e01b031981168114612ffb57600080fd5b803560ff8116811461362957600080fd5b919050565b60008083601f84011261364057600080fd5b50813567ffffffffffffffff81111561365857600080fd5b6020830191508360208260051b850101111561316b57600080fd5b60008060006040848603121561368857600080fd5b61369184613618565b9250602084013567ffffffffffffffff8111156136ad57600080fd5b6136b98682870161362e565b9497909650939450505050565b80151581146115c757600080fd5b6000602082840312156136e657600080fd5b8135612ffb816136c6565b634e487b7160e01b600052604160045260246000fd5b600080600080600060a0868803121561371f57600080fd5b85359450602086013593506040860135925060608601359150608086013567ffffffffffffffff8082111561375357600080fd5b818801915088601f83011261376757600080fd5b813581811115613779576137796136f1565b604051601f8201601f19908116603f011681019083821181831017156137a1576137a16136f1565b816040528281528b60208487010111156137ba57600080fd5b8260208601602083013760006020848301015280955050505050509295509295909350565b80356001600160a01b038116811461362957600080fd5b60006020828403121561380857600080fd5b612ffb826137df565b60006020828403121561382357600080fd5b5035919050565b6000806040838503121561383d57600080fd5b613846836137df565b946020939093013593505050565b6000806040838503121561386757600080fd5b82359150613877602084016137df565b90509250929050565b6000806040838503121561389357600080fd5b61384683613618565b60005b838110156138b757818101518382015260200161389f565b50506000910152565b600081518084526138d881602086016020860161389c565b601f01601f19169290920160200192915050565b60ff60f81b881681526000602060e08184015261390c60e084018a6138c0565b838103604085015261391e818a6138c0565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b8181101561397057835183529284019291840191600101613954565b50909c9b505050505050505050505050565b602080825282518282018190526000919060409081850190868401855b828110156139f157815180518552868101518786015285810151868601526060808201519086015260808082015161ffff169086015260a0908101519085015260c0909301929085019060010161399f565b5091979650505050505050565b60008060408385031215613a1157600080fd5b50508035926020909101359150565b60008060208385031215613a3357600080fd5b823567ffffffffffffffff811115613a4a57600080fd5b613a568582860161362e565b90969095509350505050565b60208082526041908201527f4d617820626f6e6420616d6f756e7473206d7573742068617665203220656c6560408201527f6d656e74732c2066696e6320616d6f756e74203d3e207573647420616d6f756e6060820152601d60fa1b608082015260a00190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60ff828116828216039081111561091f5761091f613adf565b60208082526044908201527f50726576696f757320746965722066696e6320616d6f756e74206d757374206260408201527f65206c657373207468616e2063757272656e7420746965722066696e6320616d6060820152631bdd5b9d60e21b608082015260a00190565b60208082526044908201527f50726576696f75732074696572207573647420616d6f756e74206d757374206260408201527f65206c657373207468616e2063757272656e742074696572207573647420616d6060820152631bdd5b9d60e21b608082015260a00190565b60ff818116838216019081111561091f5761091f613adf565b8082018082111561091f5761091f613adf565b6000816000190483118215151615613c2857613c28613adf565b500290565b600082613c4a57634e487b7160e01b600052601260045260246000fd5b500490565b600060018201613c6157613c61613adf565b5060010190565b600060ff821680613c7b57613c7b613adf565b6000190192915050565b8181038181111561091f5761091f613adf565b600060ff821660ff8103613cae57613cae613adf565b60010192915050565b600181811c90821680613ccb57607f821691505b602082108103613ceb57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156114d657600081815260208120601f850160051c81016020861015613d185750805b601f850160051c820191505b81811015613d3757828155600101613d24565b505050505050565b815167ffffffffffffffff811115613d5957613d596136f1565b613d6d81613d678454613cb7565b84613cf1565b602080601f831160018114613da25760008415613d8a5750858301515b600019600386901b1c1916600185901b178555613d37565b600085815260208120601f198616915b82811015613dd157888601518255948401946001909101908401613db2565b5085821015613def5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600181815b80851115613e3a578160001904821115613e2057613e20613adf565b80851615613e2d57918102915b93841c9390800290613e04565b509250929050565b600082613e515750600161091f565b81613e5e5750600061091f565b8160018114613e745760028114613e7e57613e9a565b600191505061091f565b60ff841115613e8f57613e8f613adf565b50506001821b61091f565b5060208310610133831016604e8410600b8410161715613ebd575081810a61091f565b613ec78383613dff565b8060001904821115613edb57613edb613adf565b029392505050565b6000612ffb60ff841683613e42565b61ffff828116828216039080821115613f0d57613f0d613adf565b5092915050565b602081526000612ffb60208301846138c0565b80516020808301519190811015613ceb5760001960209190910360031b1b16919050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351613f8381601785016020880161389c565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613fb481602884016020880161389c565b01602801949350505050565b600060208284031215613fd257600080fd5b8151612ffb816136c6565b600081613fec57613fec613adf565b506000190190565b634e487b7160e01b600052602160045260246000fd5b6000825161401c81846020870161389c565b919091019291505056fea26469706673582212206c1a500dcc4d6ac436473d8f52732ac3920f6e85968d36b79095f6679c2c841e64736f6c63430008100033
Verified Source Code Full Match
Compiler: v0.8.16+commit.07a7930e
EVM: london
Optimization: Yes (200 runs)
AccessControl.sol 248 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev 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 `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required 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})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @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) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @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 virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @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.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_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.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @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`
*
* `DEFAULT_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 `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 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 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;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
IERC5267.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.0;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* 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 Pausable is Context {
/**
* @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);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
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);
}
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));
}
}
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;
}
}
draft-EIP712.sol 8 lines
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; // EIP-712 is Final as of 2022-08-11. This file is deprecated. import "./EIP712.sol";
ECDSA.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
EIP712.sol 142 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.8;
import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* _Available since v3.4._
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {EIP-5267}.
*
* _Available since v4.9._
*/
function eip712Domain()
public
view
virtual
override
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_name.toStringWithFallback(_nameFallback),
_version.toStringWithFallback(_versionFallback),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// 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.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @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);
}
}
}
ShortStrings.sol 122 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.8;
import "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(_FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}
StorageSlot.sol 138 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
Strings.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @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), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(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) {
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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
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 keccak256(bytes(a)) == keccak256(bytes(b));
}
}
DutchBondSale.sol 536 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.16;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "contracts/bond/IBondSale.sol";
import "contracts/kyc/IKYCProvider.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
contract DutchBondSale is IBondSale, AccessControl, Pausable, ReentrancyGuard, EIP712 {
using SafeERC20 for IERC20;
using SafeERC20 for IERC20Metadata;
bytes32 public constant SIGNER = keccak256("SIGNER");
string private constant SIGNING_DOMAIN = "DutchBondSale";
string private constant SIGNATURE_VERSION = "1";
uint256 public constant MAX_BONDS_PER_USER = 20;
mapping(uint8 => uint256[]) public maxBondAmounts;
uint8 public tierNumber;
uint256 public maxPriceDelay = 300;
uint256 public bondFee;
address public feeReserve;
IERC20Metadata public immutable bondToken;
uint8 public immutable bondTokenDecimals;
uint8 public immutable peggedTokenDecimals;
IERC20Metadata public immutable peggedToken;
uint256 public immutable totalBondSize;
uint256 public totalBondedTokens;
address public bondReserve;
uint256 public bondStartTime;
uint256 public bondEndTime;
uint256 public minStake;
uint16 public discountToVestingNominator;
uint16 public discountToVestingDenominator;
uint16 private constant DISCOUNT_PRECISION = 10000; /// @notice 10000 = 100%
uint16 private constant ONE_PERCENT = 100; /// @notice 100 = 1%
uint16 private immutable discountStart;
uint16 private immutable discountEnd;
mapping(address => Bond[]) public bonds;
mapping(address => uint256) public totalClaimedTokens;
mapping(address => uint256) public totalBondedValues;
uint256 public totalBondedValueAll;
mapping(address => uint256) public adminsWhitelist;
bool public refundActive;
// Event emitted when a pair price is received
event PairPrice(uint256 pair, uint256 price, uint256 decimals);
modifier onlyWhenStaked(address account, uint256 stakedAmount) {
if (adminsWhitelist[account] == 0) {
require(stakedAmount >= minStake, "Staking balance below minimum");
}
_;
}
constructor(
address _bondReserve,
address _bondingTokenAddress,
address _paymentTokenAddress,
uint256 _totalSaleCap,
uint16 _discountStart,
uint16 _discountEnd,
uint256 _bondStartTime,
uint256 _bondEndTime,
uint16 _disToVestNom,
uint16 _disToVestDenom
) EIP712(SIGNING_DOMAIN, SIGNATURE_VERSION) {
require(_bondReserve != address(0), "Bond reserve cannot be zero address");
require(_bondingTokenAddress != address(0), "Bonding token cannot be zero address");
require(_paymentTokenAddress != address(0), "Payment token cannot be zero address");
require(_totalSaleCap > 0, "Total sale cap must be greater than 0");
require(
_discountStart >= _discountEnd,
"Discount start must be greater than or equal to discount end"
);
require(
_discountStart < DISCOUNT_PRECISION,
"Discount start must be less than or equal than percision"
);
require(_bondStartTime < _bondEndTime, "Bond start time must be less than bond end time");
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(SIGNER, msg.sender);
bondReserve = _bondReserve;
bondToken = IERC20Metadata(_bondingTokenAddress);
peggedToken = IERC20Metadata(_paymentTokenAddress);
totalBondSize = _totalSaleCap;
discountStart = _discountStart;
discountEnd = _discountEnd;
bondStartTime = _bondStartTime;
bondEndTime = _bondEndTime;
discountToVestingNominator = _disToVestNom;
discountToVestingDenominator = _disToVestDenom;
bondTokenDecimals = bondToken.decimals();
peggedTokenDecimals = peggedToken.decimals();
minStake = 10000 * 10 ** 18;
maxBondAmounts[0] = [0, 0];
maxBondAmounts[1] = [10000 * (10 ** 18), 500 * (10 ** peggedTokenDecimals)];
maxBondAmounts[2] = [50000 * (10 ** 18), 1500 * (10 ** peggedTokenDecimals)];
maxBondAmounts[3] = [100000 * (10 ** 18), 3000 * (10 ** peggedTokenDecimals)];
maxBondAmounts[4] = [200000 * (10 ** 18), 6000 * (10 ** peggedTokenDecimals)];
maxBondAmounts[5] = [500000 * (10 ** 18), 10000 * (10 ** peggedTokenDecimals)];
tierNumber = 6;
}
function setRefundStatus(bool _status) external onlyRole(DEFAULT_ADMIN_ROLE) {
refundActive = _status;
}
function setMinStake(uint256 _minStake) external onlyRole(DEFAULT_ADMIN_ROLE) {
minStake = _minStake;
}
/**
* @notice Function to update tier configurations.
* @dev Very dangerous function. There are no safety checks on the current tier number parameter. Always check manually.
* @param _index The index of the tier to update
* @param _maxBondAmounts The tier configuration
*/
function updateMaxBondAmounts(
uint8 _index,
uint256[] calldata _maxBondAmounts
) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_index > 0);
require(
_maxBondAmounts.length == 2,
"Max bond amounts must have 2 elements, finc amount => usdt amount"
);
require(_index < tierNumber, "Index out of bounds");
require(_maxBondAmounts[0] > 0 && _maxBondAmounts[1] > 0, "Amounts must be greater than 0");
require(
maxBondAmounts[_index - 1][0] < _maxBondAmounts[0],
"Previous tier finc amount must be less than current tier finc amount"
);
require(
maxBondAmounts[_index - 1][1] < _maxBondAmounts[1],
"Previous tier usdt amount must be less than current tier usdt amount"
);
if (_index < tierNumber - 1) {
require(
maxBondAmounts[_index + 1][0] > _maxBondAmounts[0],
"Next tier finc amount must be greater than current tier finc amount"
);
require(
maxBondAmounts[_index + 1][1] > _maxBondAmounts[1],
"Next tier usdt amount must be greater than current tier usdt amount"
);
}
maxBondAmounts[_index] = _maxBondAmounts;
}
function addTier(uint256[] calldata _maxBondAmounts) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(
_maxBondAmounts.length == 2,
"Max bond amounts must have 2 elements, finc amount => usdt amount"
);
require(_maxBondAmounts[0] > 0 && _maxBondAmounts[1] > 0, "Amounts must be greater than 0");
require(
maxBondAmounts[tierNumber - 1][0] < _maxBondAmounts[0],
"Previous tier finc amount must be less than current tier finc amount"
);
require(
maxBondAmounts[tierNumber - 1][1] < _maxBondAmounts[1],
"Previous tier usdt amount must be less than current tier usdt amount"
);
maxBondAmounts[tierNumber] = _maxBondAmounts;
tierNumber++;
}
function setBondFee(
address _feeReserve,
uint256 _bondFee
) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bondFee <= 10000, "Bond fee must be less than or equal to 10000");
require(_feeReserve != address(0), "Fee reserve cannot be zero address");
feeReserve = _feeReserve;
bondFee = _bondFee;
}
function setBondTimes(
uint256 _bondStartTime,
uint256 _bondEndTime
) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bondStartTime < _bondEndTime, "Bond start time must be less than bond end time");
bondStartTime = _bondStartTime;
bondEndTime = _bondEndTime;
}
function addWhitelistedUser(
address _user,
uint256 _amount
) external onlyRole(DEFAULT_ADMIN_ROLE) {
adminsWhitelist[_user] = _amount;
}
function removeWhitelistedUser(address _user) external onlyRole(DEFAULT_ADMIN_ROLE) {
adminsWhitelist[_user] = 0;
}
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_pause();
}
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_unpause();
}
function setMaxPriceDelay(uint256 _maxPriceDelay) external onlyRole(DEFAULT_ADMIN_ROLE) {
maxPriceDelay = _maxPriceDelay;
}
function depositedOf(address account) external view returns (uint256) {
return from18Decimals(totalBondedValues[account], peggedTokenDecimals);
}
function setBondReserve(address _bondReserve) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(_bondReserve != address(0), "Bond reserve cannot be zero address");
bondReserve = _bondReserve;
}
function bond(
uint256 _bondTokenAmount,
uint256 _stakedAmount,
uint256 _currentPrice,
uint256 _timestamp,
bytes memory _signature
) external whenNotPaused nonReentrant onlyWhenStaked(msg.sender, _stakedAmount) {
require(block.timestamp >= bondStartTime, "Bonding has not started yet");
require(block.timestamp <= bondEndTime, "Bonding has ended");
require(block.timestamp >= _timestamp, "Timestamp must be in the past");
require(_timestamp + maxPriceDelay >= block.timestamp, "Timestamp is too old");
require(
verify(msg.sender, _stakedAmount, _currentPrice, _timestamp, _signature),
"Invalid signature"
);
require(_bondTokenAmount > 0, "Amount must be greater than 0");
require(totalBondedTokens + _bondTokenAmount <= totalBondSize, "Bonding sale cap reached");
require(bonds[msg.sender].length < MAX_BONDS_PER_USER, "Max bonds per user reached");
uint256 bondToken18 = to18Decimals(_bondTokenAmount, bondTokenDecimals);
uint16 discountRate = currentDiscountFor(_bondTokenAmount);
uint256 tokenPrice = currentDiscountedPriceFor(_bondTokenAmount, _currentPrice);
tokenPrice = to18Decimals(tokenPrice, peggedTokenDecimals);
uint256 peggedValue = (bondToken18 * tokenPrice) / 1e18;
require(
totalBondedValues[msg.sender] + peggedValue <=
to18Decimals(maxBondAmountOf(msg.sender, _stakedAmount), peggedTokenDecimals),
"Max bond amount reached"
);
uint256 vestingDuration = currentVestingDurationFor(_bondTokenAmount);
bonds[msg.sender].push(
Bond(
_bondTokenAmount,
0,
block.timestamp,
vestingDuration,
discountRate,
from18Decimals(tokenPrice, peggedTokenDecimals)
)
);
totalBondedTokens += _bondTokenAmount;
totalBondedValues[msg.sender] += peggedValue;
uint256 _convertedpegged;
if (bondFee > 0) {
uint256 fee = (peggedValue * bondFee) / 10000;
_convertedpegged = from18Decimals(fee, peggedTokenDecimals);
peggedToken.safeTransferFrom(msg.sender, feeReserve, _convertedpegged);
}
_convertedpegged = from18Decimals(peggedValue, peggedTokenDecimals);
totalBondedValueAll += _convertedpegged;
peggedToken.safeTransferFrom(msg.sender, bondReserve, _convertedpegged);
emit Bonded(msg.sender, bondToken18, tokenPrice, discountRate);
}
function claim() external {
for (uint256 i = 0; i < bonds[msg.sender].length; i++) {
Bond memory userBond = bonds[msg.sender][i];
if (userBond.claimed >= userBond.amount) {
continue;
}
claimBond(i);
}
}
function getRefund() external whenNotPaused {
require((block.timestamp >= bondStartTime) && refundActive, "Refund not active");
require(totalClaimedTokens[msg.sender] == 0, "Already claimed");
uint256 totalBondedTokensOf = vestedOf(msg.sender);
require(totalBondedTokensOf > 0, "No vested tokens");
// Erase all bonds of user
delete bonds[msg.sender];
uint256 totalRefund = totalBondedValues[msg.sender];
delete totalBondedValues[msg.sender];
uint256 _convertedpegged = from18Decimals(totalRefund, peggedTokenDecimals);
totalBondedValueAll -= _convertedpegged;
totalBondedTokens -= totalBondedTokensOf;
peggedToken.safeTransferFrom(bondReserve, msg.sender, _convertedpegged);
emit Refunded(msg.sender, _convertedpegged);
}
function canRequestRefund() public view returns (bool) {
return
(totalClaimedTokens[msg.sender] == 0) &&
(vestedOf(msg.sender) > 0) &&
(block.timestamp >= bondStartTime) &&
refundActive;
}
function claimableOf(address account) external view returns (uint256) {
uint256 _amount = 0;
Bond[] memory userBonds = bonds[account];
for (uint256 i = 0; i < userBonds.length; i++) {
uint256 _claimable = claimableAmountFor(userBonds[i]);
_amount += _claimable;
}
return _amount;
}
function vestedOf(address account) public view returns (uint256) {
uint256 _amount = 0;
Bond[] memory userBonds = bonds[account];
for (uint256 i = 0; i < userBonds.length; i++) {
_amount += userBonds[i].amount;
}
return _amount;
}
function bondsOf(address account) external view returns (Bond[] memory) {
return bonds[account];
}
function currentDiscount() external view returns (uint16) {
return currentDiscountFor(0);
}
function currentVestingDuration() external view returns (uint256) {
return currentVestingDurationFor(0);
}
function feeForBondValue(
uint256 _bondTokenAmount,
uint256 _currentPrice
) external view returns (uint256) {
uint256 tokenPrice = currentDiscountedPriceFor(_bondTokenAmount, _currentPrice);
_bondTokenAmount = to18Decimals(_bondTokenAmount, bondTokenDecimals);
tokenPrice = to18Decimals(tokenPrice, peggedTokenDecimals);
uint256 peggedValue = (_bondTokenAmount * tokenPrice) / 1e18;
peggedValue = from18Decimals(peggedValue, peggedTokenDecimals);
return (peggedValue * bondFee) / 10000;
}
/**
* Calculate the amount of bond tokens for a given amount of bond tokens
* @param _amount amount of bond tokens to calculate the pegged value for
*/
function currentPeggedValueFor(
uint256 _amount,
uint256 _currentPrice
) public view override returns (uint256) {
uint256 discountedPrice = currentDiscountedPriceFor(_amount, _currentPrice);
_amount = to18Decimals(_amount, bondTokenDecimals);
discountedPrice = to18Decimals(discountedPrice, peggedTokenDecimals);
return from18Decimals((_amount * discountedPrice) / 1e18, peggedTokenDecimals);
}
function maxBondAmountOf(
address account,
uint256 stakedAmount
) public view override returns (uint256) {
if (adminsWhitelist[account] > 0) {
return adminsWhitelist[account];
}
for (uint8 i = tierNumber - 1; i > 0; i--) {
if (stakedAmount >= maxBondAmounts[i][0]) {
return maxBondAmounts[i][1];
}
}
return maxBondAmounts[0][1];
}
/**
* @notice Returns the current discounted price for a given amount of bond tokens in native decimals
* @param _amount The amount of bond tokens to calculate the discounted price for
* @return The discounted pegged token price in native decimals
*/
function currentDiscountedPriceFor(
uint256 _amount,
uint256 _currentPrice
) public view override returns (uint256) {
uint256 discount = currentDiscountFor(_amount);
return (_currentPrice * (10000 - discount)) / 10000;
}
/**
* @notice Returns the current vesting duration for a given amount of bond tokens in native decimals
* @param _amount The amount of bond tokens to calculate the vesting duration for
*/
function currentVestingDurationFor(uint256 _amount) public view override returns (uint256) {
uint256 discount = currentDiscountFor(_amount);
uint256 vestingTime = (discount * 1 days) / ONE_PERCENT;
vestingTime = (vestingTime * discountToVestingNominator) / discountToVestingDenominator;
return vestingTime;
}
/**
* @notice Returns the current discount for a given amount of bond tokens in native decimals
* @param _amount The amount of bond tokens to calculate the discount for
*/
function currentDiscountFor(uint256 _amount) public view override returns (uint16) {
uint256 discountNow = discountAt(totalBondedTokens);
uint256 discountAfter = discountAt(totalBondedTokens + _amount);
uint256 average = (discountNow + discountAfter) / 2;
return uint16(average);
}
function claimBond(uint256 index) internal {
require(index < bonds[msg.sender].length, "Invalid bond index");
Bond storage userBond = bonds[msg.sender][index];
uint256 _claimable = claimableAmountFor(userBond);
userBond.claimed += _claimable;
totalClaimedTokens[msg.sender] += _claimable;
bondToken.safeTransferFrom(bondReserve, msg.sender, _claimable);
emit Claimed(msg.sender, _claimable);
}
function verify(
address _account,
uint256 _stakedAmount,
uint256 _currentPrice,
uint256 _timestamp,
bytes memory _signature
) internal view returns (bool) {
bytes32 digest = _hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"Verify(address account,uint256 stakedAmount,uint256 currentPrice,uint256 timestamp)"
),
_account,
_stakedAmount,
_currentPrice,
_timestamp
)
)
);
address signer = ECDSA.recover(digest, _signature);
return hasRole(SIGNER, signer);
}
/**
* @notice Returns the current discount for a given amount of bonded tokens
* @param _amount The amount of bond tokens to calculate the discount for
*/
function discountAt(uint256 _amount) internal view returns (uint16) {
uint256 percentageSold = (_amount * DISCOUNT_PRECISION) / totalBondSize;
uint256 discountDelta = discountStart - discountEnd;
uint256 discount = discountStart - ((discountDelta * percentageSold) / DISCOUNT_PRECISION);
return uint16(discount);
}
function claimableAmountFor(Bond memory _bond) internal view returns (uint256) {
uint256 elapsed;
uint256 bondEnd = _bond.startTime + _bond.duration;
if (block.timestamp >= bondEnd) {
elapsed = _bond.duration;
} else if (block.timestamp <= _bond.startTime) {
elapsed = 0;
} else {
elapsed = block.timestamp - _bond.startTime;
}
uint256 claimable = ((_bond.amount * elapsed) / _bond.duration) - _bond.claimed;
return claimable;
}
/**
* @dev Converts an amount from 18 decimals to an equivalent amount in a token with 'desiredDecimals'
* @param amount The amount in 18 decimals
* @param desiredDecimals The number of decimals of the target token
* @return The amount adjusted to the desired decimals
*/
function from18Decimals(uint256 amount, uint8 desiredDecimals) internal pure returns (uint256) {
if (desiredDecimals == 18) {
return amount;
} else if (desiredDecimals > 18) {
return amount * (10 ** (desiredDecimals - 18));
} else {
return amount / (10 ** (18 - desiredDecimals));
}
}
/**
* @dev Converts an amount from `currentDecimals` decimals to an equivalent amount in a token with 18 decimals
* @param amount The amount in `currentDecimals` decimals
* @param currentDecimals The current number of decimals of the token
* @return The amount adjusted to the 18 decimals
*/
function to18Decimals(uint256 amount, uint8 currentDecimals) internal pure returns (uint256) {
if (currentDecimals == 18) {
return amount;
} else if (currentDecimals > 18) {
return amount / (10 ** (currentDecimals - 18));
} else {
return amount * (10 ** (18 - currentDecimals));
}
}
}
IBondSale.sol 65 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.16;
interface IBondSale {
struct Bond {
uint256 amount; /// @notice Total amount of bond tokens to be claimed
uint256 claimed; /// @notice Amount of bond tokens already claimed
uint256 startTime; /// @notice Start time of the vesting
uint256 duration; /// @notice Duration of the vesting in seconds
uint16 discountRate; /// @notice Discount rate of the bond
uint256 tokenPrice; /// @notice Price of the bond token
}
event Bonded(
address indexed account,
uint256 bondAmount,
uint256 tokenPrice,
uint16 discountRate
);
event Claimed(address indexed account, uint256 amount);
event Refunded(address indexed account, uint256 amount);
function bond(
uint256 _bondTokenAmount,
uint256 _stakedAmount,
uint256 _currentPrice,
uint256 _timestamp,
bytes memory _signature
) external;
function claim() external;
function getRefund() external;
function canRequestRefund() external view returns (bool);
function totalBondedTokens() external view returns (uint256);
function totalBondSize() external view returns (uint256);
function currentPeggedValueFor(
uint256 _amount,
uint256 _currentPrice
) external view returns (uint256);
function currentDiscountedPriceFor(
uint256 _amount,
uint256 _currentPrice
) external view returns (uint256);
function currentDiscountFor(uint256 _amount) external view returns (uint16);
function currentVestingDurationFor(uint256 _amount) external view returns (uint256);
function bondsOf(address account) external view returns (Bond[] memory);
function depositedOf(address account) external view returns (uint256);
function claimableOf(address account) external view returns (uint256);
function maxBondAmountOf(address account, uint256 stakedAmount) external view returns (uint256);
function vestedOf(address account) external view returns (uint256);
}
IKYCProvider.sol 43 lines
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.16;
interface IKYCProvider {
/**
* @dev Emitted when `_account` is added to whitelist
*/
event Whitelisted(address indexed _account, uint256 _timestamp);
/**
* @dev Emitted when `_account` is removed from whitelist
*/
event Blacklisted(address indexed _account, uint256 _timestamp);
/**
* @dev Returns true if `_account` is KYC approve
* @param _account Account to check
*/
function isWhitelisted(address _account) external view returns (bool);
/**
* @dev Adds `_account` to whitelist
* @param _account Account to add to whitelist
*/
function addToWhitelist(address _account) external;
/**
* @dev Adds `_accounts` to whitelist in a single transaction
*/
function batchAddToWhitelist(address[] memory _accounts) external;
/**
* @dev Removes `_account` from whitelist
* @param _account Account to remove from whitelist
*/
function removeFromWhitelist(address _account) external;
/**
* @dev Removes `_accounts` from whitelist in a single transaction
* @param _accounts Accounts to remove from whitelist
*/
function batchRemoveFromWhitelist(address[] memory _accounts) external;
}
Read Contract
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MAX_BONDS_PER_USER 0x131827ab → uint256
SIGNER 0x582abd12 → bytes32
adminsWhitelist 0xd4f86e3b → uint256
bondEndTime 0x67a00d36 → uint256
bondFee 0x91d311f0 → uint256
bondReserve 0xda5cc8a0 → address
bondStartTime 0x0600646a → uint256
bondToken 0xc28f4392 → address
bondTokenDecimals 0xea6f2e86 → uint8
bonds 0x327d83b8 → uint256, uint256, uint256, uint256, uint16, uint256
bondsOf 0x9570370f → tuple[]
canRequestRefund 0x0db19457 → bool
claimableOf 0x8903ab9d → uint256
currentDiscount 0x4b79401e → uint16
currentDiscountFor 0x77695896 → uint16
currentDiscountedPriceFor 0xa57e4845 → uint256
currentPeggedValueFor 0xc051ef0b → uint256
currentVestingDuration 0x4e49df0a → uint256
currentVestingDurationFor 0xe7a8daa8 → uint256
depositedOf 0x5c99d8cc → uint256
discountToVestingDenominator 0x57bf4c4d → uint16
discountToVestingNominator 0x2fe4cd93 → uint16
eip712Domain 0x84b0196e → bytes1, string, string, uint256, address, bytes32, uint256[]
feeForBondValue 0xb9025966 → uint256
feeReserve 0x789ff0e1 → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
maxBondAmountOf 0x8b326516 → uint256
maxBondAmounts 0x668a7029 → uint256
maxPriceDelay 0x9057aa9f → uint256
minStake 0x375b3c0a → uint256
paused 0x5c975abb → bool
peggedToken 0x00e77aa6 → address
peggedTokenDecimals 0x75586837 → uint8
refundActive 0xcb0269bc → bool
supportsInterface 0x01ffc9a7 → bool
tierNumber 0x01300af9 → uint8
totalBondSize 0x43f2ee31 → uint256
totalBondedTokens 0xeccbada4 → uint256
totalBondedValueAll 0x51a96609 → uint256
totalBondedValues 0xd6bf5615 → uint256
totalClaimedTokens 0x1afecb97 → uint256
vestedOf 0x94477104 → uint256
Write Contract 18 functions
These functions modify contract state and require a wallet transaction to execute.
addTier 0xb1974a02
uint256[] _maxBondAmounts
addWhitelistedUser 0x2eba4200
address _user
uint256 _amount
bond 0x19023882
uint256 _bondTokenAmount
uint256 _stakedAmount
uint256 _currentPrice
uint256 _timestamp
bytes _signature
claim 0x4e71d92d
No parameters
getRefund 0xb2d5ae44
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
removeWhitelistedUser 0xb7b1b8e9
address _user
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setBondFee 0xfa5a8c83
address _feeReserve
uint256 _bondFee
setBondReserve 0xe5b39e87
address _bondReserve
setBondTimes 0x9f37ad4a
uint256 _bondStartTime
uint256 _bondEndTime
setMaxPriceDelay 0x7a803da0
uint256 _maxPriceDelay
setMinStake 0x8c80fd90
uint256 _minStake
setRefundStatus 0x176898c9
bool _status
unpause 0x3f4ba83a
No parameters
updateMaxBondAmounts 0x1495eb07
uint8 _index
uint256[] _maxBondAmounts
Recent Transactions
No transactions found for this address