Address Contract Partially Verified
Address
0xC2B9Dd791348D9C0a145f7E15455837a9d64E3F6
Balance
0 ETH
Nonce
1
Code Size
9189 bytes
Creator
0x3A6163B0...D76a at tx 0x78bd24d7...9ac3d3
Indexed Transactions
0
Contract Bytecode
9189 bytes
0x6080604052600436106101de575f3560e01c80638da5cb5b116100fd578063db27b8dd11610092578063f2fde38b11610062578063f2fde38b1461070e578063f5648a4f1461072d578063f96d0baa14610741578063fb4aa0a11461075c575f80fd5b8063db27b8dd1461069b578063e37242f9146106ba578063ef2cfd1a146106d9578063f1e13fda146106ef575f80fd5b8063b1c97194116100cd578063b1c97194146105bd578063b325d14e1461060f578063c54e44eb14610649578063cb9637281461067c575f80fd5b80638da5cb5b146104b05780639d104770146104cd578063a7c601601461057f578063aeccf7351461059e575f80fd5b80635bf5d54c11610173578063777e0d8611610143578063777e0d86146104215780637b3e5e7b14610435578063833cde521461044a57806389a302711461047d575f80fd5b80635bf5d54c1461039d578063690d8320146103cf5780636af57dd7146103ee578063715018a61461040d575f80fd5b80632220033e116101ae5780632220033e146102f15780633b7d770414610310578063518ab2a81461035b57806353ee46471461037e575f80fd5b806301e33667146101e95780630bc37e691461020a57806315d7b2c41461021d5780631e88b2aa1461023c575f80fd5b366101e557005b5f80fd5b3480156101f4575f80fd5b50610208610203366004611efa565b61077b565b005b610208610218366004611f33565b6107f9565b348015610228575f80fd5b50610208610237366004611f53565b6109d4565b348015610247575f80fd5b506102a6610256366004611f81565b600660208190525f918252604090912080546001820154600283015460038401546004850154600586015496860154600787015460089097015495979496939592949193919260ff909116919089565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915260a0850152151560c084015260e0830152610100820152610120015b60405180910390f35b3480156102fc575f80fd5b5061020861030b366004611fe4565b610a75565b34801561031b575f80fd5b506103437f0000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b841981565b6040516001600160a01b0390911681526020016102e8565b348015610366575f80fd5b5061037060045481565b6040519081526020016102e8565b348015610389575f80fd5b5061020861039836600461208b565b610d7c565b3480156103a8575f80fd5b506003546103bd90600160a01b900460ff1681565b60405160ff90911681526020016102e8565b3480156103da575f80fd5b506102086103e9366004611f53565b610f1f565b3480156103f9575f80fd5b50610208610408366004611f81565b610f59565b348015610418575f80fd5b50610208610fa8565b34801561042c575f80fd5b50610370610fbb565b348015610440575f80fd5b5061037060055481565b348015610455575f80fd5b506103437f00000000000000000000000062217f8c102a33b6112c8b5b897bb9ee400737a581565b348015610488575f80fd5b506103437f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b3480156104bb575f80fd5b506001546001600160a01b0316610343565b3480156104d8575f80fd5b506102a66104e7366004611f81565b60ff9081165f90815260066020818152604092839020835161012081018552815480825260018301549382018490526002830154958201869052600383015460608301819052600484015460808401819052600585015460a0850181905296850154909816151560c08401819052600785015460e0850181905260089095015461010090940184905291989497909590949093919290565b34801561058a575f80fd5b506102086105993660046120db565b611048565b3480156105a9575f80fd5b506102086105b83660046120db565b6111e6565b3480156105c8575f80fd5b506105fa6105d73660046120f2565b600760209081525f92835260408084209091529082529020805460019091015482565b604080519283526020830191909152016102e8565b34801561061a575f80fd5b5061062e6106293660046120f2565b611376565b604080518251815260209283015192810192909252016102e8565b348015610654575f80fd5b506103437f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b348015610687575f80fd5b50610208610696366004611f53565b6113c4565b3480156106a6575f80fd5b50600354610343906001600160a01b031681565b3480156106c5575f80fd5b506102086106d4366004611f53565b611511565b3480156106e4575f80fd5b50610370620f424081565b3480156106fa575f80fd5b50610208610709366004611f81565b61153b565b348015610719575f80fd5b50610208610728366004611f53565b61164a565b348015610738575f80fd5b50610208611684565b34801561074c575f80fd5b50610370670de0b6b3a764000081565b348015610767575f80fd5b50600254610343906001600160a01b031681565b610783611706565b60405163a9059cbb60e01b81526001600160a01b0383811660048301526024820183905284169063a9059cbb906044016020604051808303815f875af11580156107cf573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107f39190612127565b50505050565b610801611733565b5f34116108435760405162461bcd60e51b815260206004820152600b60248201526a139bc8115512081cd95b9d60aa1b60448201526064015b60405180910390fd5b804211156108835760405162461bcd60e51b815260206004820152600d60248201526c141c9a58d948195e1c1a5c9959609a1b604482015260640161083a565b60035460ff600160a01b90910481165f9081526006602081905260409091209081015490911680156108b85750806005015442105b6108d45760405162461bcd60e51b815260040161083a90612146565b5f6108dd610fbb565b905060646108ec856063612182565b6108f69190612199565b811015801561091b5750606461090d856065612182565b6109179190612199565b8111155b6109675760405162461bcd60e51b815260206004820152601860248201527f507269636520646576696174696f6e20746f6f20686967680000000000000000604482015260640161083a565b5f6305f5e1006109778334612182565b6109819190612199565b905061098d813361178a565b6002546040516001600160a01b03909116903480156108fc02915f818181858888f193505050501580156109c3573d5f803e3d5ffd5b505050506109d060015f55565b5050565b6109dc611706565b6001600160a01b038116610a215760405162461bcd60e51b815260206004820152600c60248201526b5a65726f206164647265737360a01b604482015260640161083a565b600380546001600160a01b0319166001600160a01b0383169081179091556040519081527fd2d2441eacaf3dcd0129b6f23fb6d6ec9d2e5dd72567aae100f6efd7ae4cc93c9060200160405180910390a150565b610a7d611706565b8583148015610a8b57508581145b610ad75760405162461bcd60e51b815260206004820152601c60248201527f496e707574206172726179206c656e67746873206d69736d6174636800000000604482015260640161083a565b60ff8086165f8181526006602052604090206003549092600160a01b909104161015610b355760405162461bcd60e51b815260206004820152600d60248201526c496e76616c696420737461676560981b604482015260640161083a565b5f5b87811015610d71575f898983818110610b5257610b526121b8565b9050602002016020810190610b679190611f53565b90505f878784818110610b7c57610b7c6121b8565b9050602002013590505f868685818110610b9857610b986121b8565b9050602002013590508160075f856001600160a01b03166001600160a01b031681526020019081526020015f205f8c60ff1660ff1681526020019081526020015f205f015f828254610bea91906121cc565b90915550506001600160a01b0383165f90815260076020908152604080832060ff8e16845290915281206001018054839290610c279084906121cc565b9250508190555081856008015f828254610c4191906121cc565b9250508190555080856007015f828254610c5b91906121cc565b925050819055508060045f828254610c7391906121cc565b925050819055508160055f828254610c8b91906121cc565b90915550506003546001600160a01b031615610d0c5760035460405163c137598b60e01b81526001600160a01b03858116600483015260ff8d166024830152604482018490529091169063c137598b906064015f604051808303815f87803b158015610cf5575f80fd5b505af1158015610d07573d5f803e3d5ffd5b505050505b6040805160ff8c168152602081018390529081018390526001600160a01b038416907f78408fb808ae2018d121a91ae47221eb4b85530dc14522ce2ddcb93083e269d69060600160405180910390a25050508080610d69906121df565b915050610b37565b505050505050505050565b610d84611706565b818111610dc85760405162461bcd60e51b8152602060048201526012602482015271496e76616c69642074696d652072616e676560701b604482015260640161083a565b60ff8088165f90815260066020819052604090912001541615610e1c5760405162461bcd60e51b815260206004820152600c60248201526b53746167652065786973747360a01b604482015260640161083a565b6040518061012001604052808781526020018681526020018581526020018481526020018381526020018281526020015f151581526020015f81526020015f81525060065f8960ff1660ff1681526020019081526020015f205f820151815f01556020820151816001015560408201518160020155606082015181600301556080820151816004015560a0820151816005015560c0820151816006015f6101000a81548160ff02191690831515021790555060e0820151816007015561010082015181600801559050508660ff167f67aed7802b6d7a32c8323f00822f16d9d4fa9b1524a6cb04a342ab220a45757960405160405180910390a250505050505050565b610f27611706565b6040516001600160a01b038216904780156108fc02915f818181858888f193505050501580156109d0573d5f803e3d5ffd5b610f61611706565b60ff81165f818152600660208190526040808320909101805460ff19169055517f39e4226586de8be982b0e2158606b9f33981dc3e17bf2dbd1099ccea6c2e293f9190a250565b610fb0611706565b610fb95f611e8e565b565b5f807f0000000000000000000000005f4ec3df9cbd43714fe2740f5e3616155c5b84196001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015611019573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061103d9190612210565b509195945050505050565b611050611733565b5f811161108d5760405162461bcd60e51b815260206004820152600b60248201526a16995c9bc8185b5bdd5b9d60aa1b604482015260640161083a565b60035460ff600160a01b90910481165f9081526006602081905260409091209081015490911680156110c25750806005015442105b6110de5760405162461bcd60e51b815260040161083a90612146565b5f6110ee8364e8d4a51000612182565b90506110fa813361178a565b6002546040516323b872dd60e01b81523360048201526001600160a01b039182166024820152604481018590527f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7909116906323b872dd906064016020604051808303815f875af1158015611171573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111959190612127565b6111d85760405162461bcd60e51b81526020600482015260146024820152731554d115081d1c985b9cd9995c8819985a5b195960621b604482015260640161083a565b50506111e360015f55565b50565b6111ee611733565b5f811161122b5760405162461bcd60e51b815260206004820152600b60248201526a16995c9bc8185b5bdd5b9d60aa1b604482015260640161083a565b60035460ff600160a01b90910481165f9081526006602081905260409091209081015490911680156112605750806005015442105b61127c5760405162461bcd60e51b815260040161083a90612146565b5f61128c8364e8d4a51000612182565b9050611298813361178a565b6002546040516323b872dd60e01b81523360048201526001600160a01b039182166024820152604481018590527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48909116906323b872dd906064016020604051808303815f875af115801561130f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113339190612127565b6111d85760405162461bcd60e51b81526020600482015260146024820152731554d110c81d1c985b9cd9995c8819985a5b195960621b604482015260640161083a565b6040805180820182525f80825260209182018190526001600160a01b03851681526007825282812060ff85168252825282902082518084019093528054835260010154908201525b92915050565b6113cc611706565b6040516370a0823160e01b81523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa158015611410573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611434919061225c565b90505f811161147d5760405162461bcd60e51b81526020600482015260156024820152744e6f20746f6b656e7320746f20776974686472617760581b604482015260640161083a565b816001600160a01b031663a9059cbb61149e6001546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303815f875af11580156114e8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061150c9190612127565b505050565b611519611706565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b611543611706565b60ff81165f908152600660205260409020600401544210156115935760405162461bcd60e51b8152602060048201526009602482015268546f6f206561726c7960b81b604482015260640161083a565b60ff8082165f908152600660208190526040909120015416156115e95760405162461bcd60e51b815260206004820152600e60248201526d416c72656164792061637469766560901b604482015260640161083a565b60ff81165f818152600660208190526040808320909101805460ff1916600117905560038054600160a01b850260ff60a01b19909116179055517fd9b49a8c92834df9e82f431ffa0edb0672f6821c38f5909500b9876ee4ac87c29190a250565b611652611706565b6001600160a01b03811661167b57604051631e4fbdf760e01b81525f600482015260240161083a565b6111e381611e8e565b61168c611706565b47806116cf5760405162461bcd60e51b81526020600482015260126024820152714e6f2045544820746f20776974686472617760701b604482015260640161083a565b6001546040516001600160a01b039091169082156108fc029083905f818181858888f193505050501580156109d0573d5f803e3d5ffd5b6001546001600160a01b03163314610fb95760405163118cdaa760e01b815233600482015260240161083a565b60025f54036117845760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161083a565b60025f55565b60035460ff600160a01b909104165f8181526006602090815260409182902082518381526008818501526714dd1859d948125160c21b60608201529182019390935290515f805160206123908339815191529181900360800190a15f80516020612390833981519152816003015460405161182f91906040808252600d908201526c14dd1859d94810d85c081554d1609a1b6060820152602081019190915260800190565b60405180910390a15f805160206123908339815191528160080154604051611884919060408082526010908201526f14dd1859d94814985a5cd959081554d160821b6060820152602081019190915260800190565b60405180910390a160408051818152600c818301526b125b98dbdb5a5b99c81554d160a21b60608201526020810185905290515f805160206123908339815191529181900360800190a180600301548382600801546118e391906121cc565b11156119235760405162461bcd60e51b815260206004820152600f60248201526e12185c9918d85c081c995858da1959608a1b604482015260640161083a565b5f7f00000000000000000000000062217f8c102a33b6112c8b5b897bb9ee400737a56001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611980573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119a49190612273565b6119af90600a61236e565b90505f80516020612390833981519152816040516119f891906040808252600e908201526d546f6b656e20446563696d616c7360901b6060820152602081019190915260800190565b60405180910390a181545f90611a0e8387612182565b611a189190612199565b90505f80516020612390833981519152835f0154604051611a6191906040808252600b908201526a546f6b656e20507269636560a81b6060820152602081019190915260800190565b60405180910390a16040805181815260128183015271546f6b656e7320546f20416c6c6f6361746560701b60608201526020810183905290515f805160206123908339815191529181900360800190a15f8051602061239083398151915283600701548460020154611ad3919061237c565b604051611b0d919060408082526010908201526f546f6b656e732052656d61696e696e6760801b6060820152602081019190915260800190565b60405180910390a182600701548360020154611b29919061237c565b811115611b6c5760405162461bcd60e51b81526020600482015260116024820152704e6f7420656e6f75676820746f6b656e7360781b604482015260640161083a565b6001600160a01b0384165f908152600760209081526040808320600354600160a01b900460ff16845290915281208054879290611baa9084906121cc565b90915550506001600160a01b0384165f908152600760209081526040808320600354600160a01b900460ff16845290915281206001018054839290611bf09084906121cc565b9250508190555084836008015f828254611c0a91906121cc565b9250508190555080836007015f828254611c2491906121cc565b90915550506004546040515f8051602061239083398151915291611c7691604080825260129082015271476c6f62616c20536f6c64204265666f726560701b6060820152602081019190915260800190565b60405180910390a15f80516020612390833981519152600554604051611ccd9190604080825260149082015273476c6f62616c20526169736564204265666f726560601b6060820152602081019190915260800190565b60405180910390a18060045f828254611ce691906121cc565b925050819055508460055f828254611cfe91906121cc565b909155505060035460408051600160a01b90920460ff1682526020820183905281018690526001600160a01b038516907f78408fb808ae2018d121a91ae47221eb4b85530dc14522ce2ddcb93083e269d69060600160405180910390a26003546001600160a01b031615611ddd5760035460405163c137598b60e01b81526001600160a01b038681166004830152600160a01b830460ff166024830152604482018490529091169063c137598b906064015f604051808303815f87803b158015611dc6575f80fd5b505af1158015611dd8573d5f803e3d5ffd5b505050505b5f80516020612390833981519152600454604051611e29919060408082526011908201527023b637b130b61029b7b6321020b33a32b960791b6060820152602081019190915260800190565b60405180910390a15f80516020612390833981519152600554604051611e7f919060408082526013908201527223b637b130b6102930b4b9b2b21020b33a32b960691b6060820152602081019190915260800190565b60405180910390a15050505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b80356001600160a01b0381168114611ef5575f80fd5b919050565b5f805f60608486031215611f0c575f80fd5b611f1584611edf565b9250611f2360208501611edf565b9150604084013590509250925092565b5f8060408385031215611f44575f80fd5b50508035926020909101359150565b5f60208284031215611f63575f80fd5b611f6c82611edf565b9392505050565b60ff811681146111e3575f80fd5b5f60208284031215611f91575f80fd5b8135611f6c81611f73565b5f8083601f840112611fac575f80fd5b50813567ffffffffffffffff811115611fc3575f80fd5b6020830191508360208260051b8501011115611fdd575f80fd5b9250929050565b5f805f805f805f6080888a031215611ffa575f80fd5b873567ffffffffffffffff80821115612011575f80fd5b61201d8b838c01611f9c565b909950975060208a0135915061203282611f73565b90955060408901359080821115612047575f80fd5b6120538b838c01611f9c565b909650945060608a013591508082111561206b575f80fd5b506120788a828b01611f9c565b989b979a50959850939692959293505050565b5f805f805f805f60e0888a0312156120a1575f80fd5b87356120ac81611f73565b9960208901359950604089013598606081013598506080810135975060a0810135965060c00135945092505050565b5f602082840312156120eb575f80fd5b5035919050565b5f8060408385031215612103575f80fd5b61210c83611edf565b9150602083013561211c81611f73565b809150509250929050565b5f60208284031215612137575f80fd5b81518015158114611f6c575f80fd5b6020808252600e908201526d537461676520696e61637469766560901b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176113be576113be61216e565b5f826121b357634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b808201808211156113be576113be61216e565b5f600182016121f0576121f061216e565b5060010190565b805169ffffffffffffffffffff81168114611ef5575f80fd5b5f805f805f60a08688031215612224575f80fd5b61222d866121f7565b9450602086015193506040860151925060608601519150612250608087016121f7565b90509295509295909350565b5f6020828403121561226c575f80fd5b5051919050565b5f60208284031215612283575f80fd5b8151611f6c81611f73565b600181815b808511156122c857815f19048211156122ae576122ae61216e565b808516156122bb57918102915b93841c9390800290612293565b509250929050565b5f826122de575060016113be565b816122ea57505f6113be565b8160018114612300576002811461230a57612326565b60019150506113be565b60ff84111561231b5761231b61216e565b50506001821b6113be565b5060208310610133831016604e8410600b8410161715612349575081810a6113be565b612353838361228e565b805f19048211156123665761236661216e565b029392505050565b5f611f6c60ff8416836122d0565b818103818111156113be576113be61216e56fe2c78221d853bf45521bf53ad2802eb4470185a3cad34373f42e4639a8fdeb197a26469706673582212209d571bbac2241f6cea6c0afe299c11095f7ae2b112063ce6982b8150ccfe6ca864736f6c63430008140033
Verified Source Code Partial Match
Compiler: v0.8.20+commit.a1b79de6
EVM: shanghai
Optimization: Yes (200 runs)
MediCoinPresale.sol 672 lines
// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
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;
}
}
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File: @chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(
uint80 _roundId
) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
// File: MediCoinPresale.sol
pragma solidity ^0.8.20;
interface IMediCoin {
function presaleTransfer(address to, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
}
interface IVestingManager {
function recordVesting(address user, uint8 stageRaw, uint256 amount) external;
}
contract MediCoinPresale is ReentrancyGuard, Ownable {
IERC20 public immutable USDT;
IERC20 public immutable USDC;
IMediCoin public immutable SaleToken;
AggregatorV3Interface public immutable ETHOracle;
address public fundReceiver;
address public vestingManager; // 🔌 Plug-in for VestingManager.sol
uint8 public currentStage = 0;
uint256 public constant USDT_DECIMALS = 1e6;
uint256 public constant USD_SCALE = 1e18;
uint256 public tokensSold;
uint256 public amountRaised;
struct Stage {
uint256 price;
uint256 nextPrice;
uint256 tokensToSell;
uint256 usdHardcap;
uint256 start;
uint256 end;
bool active;
uint256 sold;
uint256 amountRaised;
}
struct User {
uint256 investedUSD;
uint256 tokensAllocated;
}
mapping(uint8 => Stage) public stages;
mapping(address => mapping(uint8 => User)) public userInfo;
event TokensPurchased(address indexed buyer, uint8 stage, uint256 tokens, uint256 usdAmount);
event StageAdded(uint8 indexed stageId);
event StageActivated(uint8 indexed stageId);
event StagePaused(uint8 indexed stageId);
event VestingManagerUpdated(address newManager);
event DebugUint(string label, uint256 value);
constructor(
address _token,
address _usdt,
address _usdc,
address _oracle,
address _fundReceiver
) Ownable(msg.sender) {
SaleToken = IMediCoin(_token);
USDT = IERC20(_usdt);
USDC = IERC20(_usdc);
ETHOracle = AggregatorV3Interface(_oracle);
fundReceiver = _fundReceiver;
}
// -------------------- Admin --------------------
function addStage(
uint8 _id,
uint256 _price,
uint256 _nextPrice,
uint256 _tokensToSell,
uint256 _usdHardcap,
uint256 _start,
uint256 _end
) external onlyOwner {
require(_end > _start, "Invalid time range");
require(!stages[_id].active, "Stage exists");
stages[_id] = Stage({
price: _price,
nextPrice: _nextPrice,
tokensToSell: _tokensToSell,
usdHardcap: _usdHardcap,
start: _start,
end: _end,
active: false,
sold: 0,
amountRaised: 0
});
emit StageAdded(_id);
}
function activateStage(uint8 _id) external onlyOwner {
require(block.timestamp >= stages[_id].start, "Too early");
require(!stages[_id].active, "Already active");
stages[_id].active = true;
currentStage = _id;
emit StageActivated(_id);
}
function pauseStage(uint8 _id) external onlyOwner {
stages[_id].active = false;
emit StagePaused(_id);
}
function setFundReceiver(address _receiver) external onlyOwner {
fundReceiver = _receiver;
}
function setVestingManager(address _vestingManager) external onlyOwner {
require(_vestingManager != address(0), "Zero address");
vestingManager = _vestingManager;
emit VestingManagerUpdated(_vestingManager);
}
function withdrawToken(address token, address to, uint256 amount) external onlyOwner {
IERC20(token).transfer(to, amount);
}
function withdrawETH(address to) external onlyOwner {
payable(to).transfer(address(this).balance);
}
// -------------------- Legacy Migration --------------------
function injectLegacySale(
address[] calldata users,
uint8 stage,
uint256[] calldata usdAmounts,
uint256[] calldata tokenAmounts
) external onlyOwner {
require(
users.length == usdAmounts.length && users.length == tokenAmounts.length,
"Input array lengths mismatch"
);
Stage storage s = stages[stage];
require(stage <= currentStage, "Invalid stage");
for (uint256 i = 0; i < users.length; i++) {
address user = users[i];
uint256 usd = usdAmounts[i];
uint256 tokens = tokenAmounts[i];
userInfo[user][stage].investedUSD += usd;
userInfo[user][stage].tokensAllocated += tokens;
s.amountRaised += usd;
s.sold += tokens;
// NEW: Update total project totals
tokensSold += tokens;
amountRaised += usd;
if (vestingManager != address(0)) {
IVestingManager(vestingManager).recordVesting(user, stage, tokens);
}
emit TokensPurchased(user, stage, tokens, usd);
}
}
// -------------------- Emergency Withdraw --------------------
function withdrawStuckETH() external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, "No ETH to withdraw");
payable(owner()).transfer(balance);
}
function withdrawStuckTokens(address token) external onlyOwner {
uint256 balance = IERC20(token).balanceOf(address(this));
require(balance > 0, "No tokens to withdraw");
IERC20(token).transfer(owner(), balance);
}
// -------------------- Buying Logic --------------------
function buyWithETH(uint256 userProvidedPrice, uint256 deadline) external payable nonReentrant {
require(msg.value > 0, "No ETH sent");
require(block.timestamp <= deadline, "Price expired");
Stage storage s = stages[currentStage];
require(s.active && block.timestamp < s.end, "Stage inactive");
uint256 chainlinkPrice = getLatestETHPrice(); // 8 decimals
require(
chainlinkPrice >= (userProvidedPrice * 99) / 100 &&
chainlinkPrice <= (userProvidedPrice * 101) / 100,
"Price deviation too high"
);
uint256 usdAmount = (msg.value * chainlinkPrice) / 1e8;
_processPurchase(usdAmount, msg.sender);
payable(fundReceiver).transfer(msg.value);
}
function buyWithUSDT(uint256 amount) external nonReentrant {
require(amount > 0, "Zero amount");
Stage storage s = stages[currentStage];
require(s.active && block.timestamp < s.end, "Stage inactive");
uint256 usdAmount = amount * 1e12;
_processPurchase(usdAmount, msg.sender);
require(USDT.transferFrom(msg.sender, fundReceiver, amount), "USDT transfer failed");
}
function buyWithUSDC(uint256 amount) external nonReentrant {
require(amount > 0, "Zero amount");
Stage storage s = stages[currentStage];
require(s.active && block.timestamp < s.end, "Stage inactive");
uint256 usdAmount = amount * 1e12;
_processPurchase(usdAmount, msg.sender);
require(USDC.transferFrom(msg.sender, fundReceiver, amount), "USDC transfer failed");
}
function _processPurchase(uint256 usdAmount, address buyer) internal {
Stage storage s = stages[currentStage];
emit DebugUint("Stage ID", currentStage);
emit DebugUint("Stage Cap USD", s.usdHardcap);
emit DebugUint("Stage Raised USD", s.amountRaised);
emit DebugUint("Incoming USD", usdAmount);
require(s.amountRaised + usdAmount <= s.usdHardcap, "Hardcap reached");
uint256 decimals = 10 ** IERC20Metadata(address(SaleToken)).decimals();
emit DebugUint("Token Decimals", decimals);
uint256 tokens = (usdAmount * decimals) / s.price;
emit DebugUint("Token Price", s.price);
emit DebugUint("Tokens To Allocate", tokens);
emit DebugUint("Tokens Remaining", s.tokensToSell - s.sold);
require(tokens <= s.tokensToSell - s.sold, "Not enough tokens");
userInfo[buyer][currentStage].investedUSD += usdAmount;
userInfo[buyer][currentStage].tokensAllocated += tokens;
s.amountRaised += usdAmount;
s.sold += tokens;
// Optional debug before affecting global state
emit DebugUint("Global Sold Before", tokensSold);
emit DebugUint("Global Raised Before", amountRaised);
tokensSold += tokens;
amountRaised += usdAmount;
emit TokensPurchased(buyer, currentStage, tokens, usdAmount);
if (vestingManager != address(0)) {
IVestingManager(vestingManager).recordVesting(buyer, currentStage, tokens);
}
// Final confirmation
emit DebugUint("Global Sold After", tokensSold);
emit DebugUint("Global Raised After", amountRaised);
}
function getLatestETHPrice() public view returns (uint256) {
(, int256 price, , ,) = ETHOracle.latestRoundData();
return uint256(price); // 8 decimals
}
// -------------------- View --------------------
function getUserInfo(address user, uint8 stage) external view returns (User memory) {
return userInfo[user][stage];
}
function getStageInfo(uint8 _id)
external
view
returns (
uint256 price,
uint256 nextPrice,
uint256 tokensToSell,
uint256 usdHardcap,
uint256 start,
uint256 end,
bool active,
uint256 sold,
uint256 stageAmountRaised
)
{
Stage memory s = stages[_id];
return (
s.price,
s.nextPrice,
s.tokensToSell,
s.usdHardcap,
s.start,
s.end,
s.active,
s.sold,
s.amountRaised
);
}
receive() external payable {}
}
Read Contract
ETHOracle 0x3b7d7704 → address
SaleToken 0x833cde52 → address
USDC 0x89a30271 → address
USDT 0xc54e44eb → address
USDT_DECIMALS 0xef2cfd1a → uint256
USD_SCALE 0xf96d0baa → uint256
amountRaised 0x7b3e5e7b → uint256
currentStage 0x5bf5d54c → uint8
fundReceiver 0xfb4aa0a1 → address
getLatestETHPrice 0x777e0d86 → uint256
getStageInfo 0x9d104770 → uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256, uint256
getUserInfo 0xb325d14e → tuple
owner 0x8da5cb5b → address
stages 0x1e88b2aa → uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256, uint256
tokensSold 0x518ab2a8 → uint256
userInfo 0xb1c97194 → uint256, uint256
vestingManager 0xdb27b8dd → address
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
activateStage 0xf1e13fda
uint8 _id
addStage 0x53ee4647
uint8 _id
uint256 _price
uint256 _nextPrice
uint256 _tokensToSell
uint256 _usdHardcap
uint256 _start
uint256 _end
buyWithETH 0x0bc37e69
uint256 userProvidedPrice
uint256 deadline
buyWithUSDC 0xaeccf735
uint256 amount
buyWithUSDT 0xa7c60160
uint256 amount
injectLegacySale 0x2220033e
address[] users
uint8 stage
uint256[] usdAmounts
uint256[] tokenAmounts
pauseStage 0x6af57dd7
uint8 _id
renounceOwnership 0x715018a6
No parameters
setFundReceiver 0xe37242f9
address _receiver
setVestingManager 0x15d7b2c4
address _vestingManager
transferOwnership 0xf2fde38b
address newOwner
withdrawETH 0x690d8320
address to
withdrawStuckETH 0xf5648a4f
No parameters
withdrawStuckTokens 0xcb963728
address token
withdrawToken 0x01e33667
address token
address to
uint256 amount
Recent Transactions
No transactions found for this address