-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
ff8e41d
commit 313ec2a
Showing
24 changed files
with
353 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod access_control; | ||
mod token; | ||
mod upgradeable; | ||
mod upgrades; | ||
mod mocks; | ||
mod type_and_version; | ||
mod enumerable_set; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod mock_upgradeable; | ||
mod mock_owner_upgradeable; | ||
mod mock_non_upgradeable; | ||
mod mock_multisig_target; | ||
mod mock_enumerable_set; |
66 changes: 66 additions & 0 deletions
66
contracts/src/libraries/mocks/mock_owner_upgradeable.cairo
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,66 @@ | ||
use starknet::class_hash::ClassHash; | ||
|
||
#[starknet::interface] | ||
trait IFoo<TContractState> { | ||
fn foo(self: @TContractState) -> bool; | ||
} | ||
|
||
#[starknet::contract] | ||
mod MockOwnerUpgradeable { | ||
use starknet::class_hash::ClassHash; | ||
use starknet::ContractAddress; | ||
|
||
use openzeppelin::access::ownable::OwnableComponent; | ||
use openzeppelin::upgrades::UpgradeableComponent; | ||
|
||
use chainlink::libraries::upgrades::v2::owner_upgradeable::OwnerUpgradeableComponent; | ||
|
||
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); | ||
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); | ||
component!( | ||
path: OwnerUpgradeableComponent, storage: owner_upgradeable, event: OwnerUpgradeableEvent | ||
); | ||
|
||
#[abi(embed_v0)] | ||
impl OwnableImpl = OwnableComponent::OwnableTwoStepImpl<ContractState>; | ||
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>; | ||
|
||
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>; | ||
|
||
#[abi(embed_v0)] | ||
impl OwnerUpgradeableImpl = | ||
OwnerUpgradeableComponent::OwnerUpgradeableImpl<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
ownable: OwnableComponent::Storage, | ||
#[substorage(v0)] | ||
upgradeable: UpgradeableComponent::Storage, | ||
#[substorage(v0)] | ||
owner_upgradeable: OwnerUpgradeableComponent::Storage | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
OwnableEvent: OwnableComponent::Event, | ||
#[flat] | ||
UpgradeableEvent: UpgradeableComponent::Event, | ||
#[flat] | ||
OwnerUpgradeableEvent: OwnerUpgradeableComponent::Event | ||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, owner: ContractAddress) { | ||
self.ownable.initializer(owner); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl FooImpl of super::IFoo<ContractState> { | ||
fn foo(self: @ContractState) -> bool { | ||
true | ||
} | ||
} | ||
} |
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,3 @@ | ||
mod v1; | ||
mod v2; | ||
mod utils; |
Empty file.
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 upgradeable; |
4 changes: 3 additions & 1 deletion
4
contracts/src/libraries/upgradeable.cairo → ...c/libraries/upgrades/v1/upgradeable.cairo
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 owner_upgradeable; |
41 changes: 41 additions & 0 deletions
41
contracts/src/libraries/upgrades/v2/owner_upgradeable.cairo
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,41 @@ | ||
#[starknet::component] | ||
mod OwnerUpgradeableComponent { | ||
use openzeppelin::{ | ||
access::ownable::{ | ||
OwnableComponent, OwnableComponent::InternalTrait as OwnableInternalTrait | ||
}, | ||
upgrades::{ | ||
upgradeable::{ | ||
UpgradeableComponent, | ||
UpgradeableComponent::InternalTrait as UpgradeableInternalTrait | ||
}, | ||
interface::IUpgradeable, | ||
}, | ||
}; | ||
use starknet::class_hash::ClassHash; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event {} | ||
|
||
#[embeddable_as(OwnerUpgradeableImpl)] | ||
pub impl OwnerUpgradeable< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
impl Ownable: OwnableComponent::HasComponent<TContractState>, | ||
impl Upgradeable: UpgradeableComponent::HasComponent<TContractState>, | ||
+Drop<TContractState> | ||
> of IUpgradeable<ComponentState<TContractState>> { | ||
fn upgrade(ref self: ComponentState<TContractState>, new_class_hash: ClassHash) { | ||
let mut ownable_component = get_dep_component_mut!(ref self, Ownable); | ||
ownable_component.assert_only_owner(); | ||
|
||
let mut upgradeable_component = get_dep_component_mut!(ref self, Upgradeable); | ||
upgradeable_component.upgrade(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
Oops, something went wrong.