cairo-contracts
cairo-contracts copied to clipboard
Add `assert_not_initialized` and `assert_initialized` to initializable.cairo
🧐 Motivation It is easy to import Initializable library and is used often especially with proxys but lacks these assert functions
I don't think that's present even in the solidity version of OpenZeppelin Contracts. Can you share an example of how would you use this feature?
Sure, when I'm deploying a proxy contract I want to get rid of the constructor in the library contract. So I replace it with an initialize function. In that initialize function I then want to check that the contract hasn't been previously initialized like this:
func setup_pool{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
router : felt, name : felt, symbol : felt, decimals : felt):
assert_not_initialized()
# set lp token name, symbol, and decimals
ERC20.initializer(name, symbol, decimals)
# set factory as owner
Ownable.initializer(router)
# set as initialized
Initializable.initialize()
return ()
end
So currently to do this I"m importing the Initialized library and the storage var and then creating the assert function myself. It would be nice to just import the library and call the assert functions there.
Ah, this made me go look at the initialize function again and I see it performs this check internally. I guess the only time this would actually be useful is to make sure that other functions aren't called before the contract is initialized. Probably not as important as I thought. Thanks for your reply!
Closing this since it will not be relevant anymore after the ongoing Cairo 1.0 migration. If you think this is a mistake, feel free to open a new issue.