-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
358 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use starknet::{ContractAddress, ClassHash}; | ||
|
||
#[starknet::interface] | ||
trait IveCARM<TContractState> { | ||
fn name(self: @TContractState) -> felt252; | ||
fn symbol(self: @TContractState) -> felt252; | ||
fn decimals(self: @TContractState) -> u8; | ||
fn mint(ref self: TContractState, recipient: ContractAddress, amount: u256); | ||
fn burn(ref self: TContractState, account: ContractAddress, amount: u256); | ||
fn upgrade(ref self: TContractState, new_class_hash: ClassHash); | ||
} | ||
|
||
#[starknet::contract] | ||
mod MyToken { | ||
use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait; | ||
use starknet::ContractAddress; | ||
use starknet::ClassHash; | ||
use openzeppelin::token::erc20::ERC20Component; | ||
use openzeppelin::access::ownable::ownable::OwnableComponent; | ||
|
||
component!(path: ERC20Component, storage: erc20, event: ERC20Event); | ||
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); | ||
|
||
// ERC20 Component | ||
#[abi(embed_v0)] | ||
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>; | ||
|
||
#[abi(embed_v0)] | ||
impl SafeAllowanceImpl = ERC20Component::SafeAllowanceImpl<ContractState>; | ||
|
||
#[abi(embed_v0)] | ||
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>; | ||
|
||
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>; | ||
|
||
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>; | ||
|
||
// Ownable Component | ||
#[abi(embed_v0)] | ||
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>; | ||
|
||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
erc20: ERC20Component::Storage, | ||
#[substorage(v0)] | ||
ownable: OwnableComponent::Storage, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
Upgraded: Upgraded, | ||
// #[flat] | ||
ERC20Event: ERC20Component::Event, | ||
OwnableEvent: OwnableComponent::Event | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct Upgraded { | ||
class_hash: ClassHash | ||
} | ||
|
||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, owner: ContractAddress) { | ||
self.ownable.initializer(owner); | ||
} | ||
|
||
#[external(v0)] | ||
#[generate_trait] | ||
impl VeCARMImpl of IveCARM { | ||
// Did not import Erc20MetaData, so we can change decimals | ||
// so we need to define name, symbol and decimals ourselves | ||
fn name(self: @ContractState) -> felt252 { | ||
'vote escrowed Carmine Token' | ||
} | ||
|
||
fn symbol(self: @ContractState) -> felt252 { | ||
'veCARM' | ||
} | ||
|
||
fn decimals(self: @ContractState) -> u8 { | ||
18 | ||
} | ||
|
||
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) { | ||
self.ownable.assert_only_owner(); | ||
self.erc20._mint(recipient, amount); | ||
} | ||
|
||
fn burn(ref self: ContractState, account: ContractAddress, amount: u256) { | ||
self.ownable.assert_only_owner(); | ||
self.erc20._burn(account, amount); | ||
} | ||
|
||
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { | ||
self.ownable.assert_only_owner(); | ||
assert(!new_class_hash.is_zero(), 'Class hash cannot be zero'); | ||
starknet::replace_class_syscall(new_class_hash).unwrap(); | ||
self.emit(Upgraded { class_hash: new_class_hash }); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts for Cairo v0.8.0-beta.0 (access/ownable/ownable.cairo) | ||
|
||
/// # Ownable Component | ||
/// | ||
/// The Ownable component 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 can be set by using the `initializer` function in | ||
/// construction time. This can later be changed with `transfer_ownership`. | ||
#[starknet::component] | ||
mod OwnableComponent { | ||
use carmine_protocol::oz::access::interface; | ||
use starknet::ContractAddress; | ||
use starknet::get_caller_address; | ||
|
||
#[storage] | ||
struct Storage { | ||
Ownable_owner: ContractAddress | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
OwnershipTransferred: OwnershipTransferred | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct OwnershipTransferred { | ||
previous_owner: ContractAddress, | ||
new_owner: ContractAddress, | ||
} | ||
|
||
mod Errors { | ||
const NOT_OWNER: felt252 = 'Caller is not the owner'; | ||
const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address'; | ||
const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address'; | ||
} | ||
|
||
#[embeddable_as(OwnableImpl)] | ||
impl Ownable< | ||
TContractState, +HasComponent<TContractState> | ||
> of interface::IOwnable<ComponentState<TContractState>> { | ||
/// Returns the address of the current owner. | ||
fn owner(self: @ComponentState<TContractState>) -> ContractAddress { | ||
self.Ownable_owner.read() | ||
} | ||
|
||
/// Transfers ownership of the contract to a new address. | ||
fn transfer_ownership( | ||
ref self: ComponentState<TContractState>, new_owner: ContractAddress | ||
) { | ||
assert(!new_owner.is_zero(), Errors::ZERO_ADDRESS_OWNER); | ||
self.assert_only_owner(); | ||
self._transfer_ownership(new_owner); | ||
} | ||
|
||
/// Leaves the contract without owner. It will not be possible to call `assert_only_owner` | ||
/// functions anymore. Can only be called by the current owner. | ||
fn renounce_ownership(ref self: ComponentState<TContractState>) { | ||
self.assert_only_owner(); | ||
self._transfer_ownership(Zeroable::zero()); | ||
} | ||
} | ||
|
||
/// Adds camelCase support for `IOwnable`. | ||
#[embeddable_as(OwnableCamelOnlyImpl)] | ||
impl OwnableCamelOnly< | ||
TContractState, +HasComponent<TContractState> | ||
> of interface::IOwnableCamelOnly<ComponentState<TContractState>> { | ||
fn transferOwnership(ref self: ComponentState<TContractState>, newOwner: ContractAddress) { | ||
self.transfer_ownership(newOwner); | ||
} | ||
|
||
fn renounceOwnership(ref self: ComponentState<TContractState>) { | ||
self.renounce_ownership(); | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl InternalImpl< | ||
TContractState, +HasComponent<TContractState> | ||
> of InternalTrait<TContractState> { | ||
/// Sets the contract's initial owner. | ||
/// | ||
/// This function should be called at construction time. | ||
fn initializer(ref self: ComponentState<TContractState>, owner: ContractAddress) { | ||
self._transfer_ownership(owner); | ||
} | ||
|
||
/// Panics if called by any account other than the owner. Use this | ||
/// to restrict access to certain functions to the owner. | ||
fn assert_only_owner(self: @ComponentState<TContractState>) { | ||
let owner: ContractAddress = self.Ownable_owner.read(); | ||
let caller: ContractAddress = get_caller_address(); | ||
assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); | ||
assert(caller == owner, Errors::NOT_OWNER); | ||
} | ||
|
||
/// Transfers ownership of the contract to a new address. | ||
/// | ||
/// Internal function without access restriction. | ||
fn _transfer_ownership( | ||
ref self: ComponentState<TContractState>, new_owner: ContractAddress | ||
) { | ||
let previous_owner: ContractAddress = self.Ownable_owner.read(); | ||
self.Ownable_owner.write(new_owner); | ||
self | ||
.emit( | ||
OwnershipTransferred { previous_owner: previous_owner, new_owner: new_owner } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod vesting; |
Oops, something went wrong.