Skip to content

Commit

Permalink
Merge pull request #363 from smartcontractkit/cairo2.5.x
Browse files Browse the repository at this point in the history
update contracts and tests for cairo 2.5.x
  • Loading branch information
archseer authored Feb 27, 2024
2 parents 6c48b26 + e156fd0 commit 0e7c67b
Show file tree
Hide file tree
Showing 35 changed files with 326 additions and 572 deletions.
4 changes: 2 additions & 2 deletions .github/actions/install-cairo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: A composite action that installs cairo and scarb binaries
inputs:
cairo_version:
description: Cairo release version
default: "v2.4.3"
default: "v2.5.4"
required: false
scarb_version:
description: Scarb release version
default: "v2.4.3"
default: "v2.5.4"
required: false

runs:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mockery 2.22.1
golangci-lint 1.55.0
actionlint 1.6.12
shellcheck 0.8.0
scarb 0.7.0
scarb 2.5.4

# Kubernetes
k3d 5.4.4
Expand Down
4 changes: 2 additions & 2 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies = [

[[package]]
name = "openzeppelin"
version = "0.8.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.8.0#c23e8e96de60e6e3159b1ff8591a1187269c0eb7"
version = "0.9.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.9.0#861fc416f87addbe23a3b47f9d19ab27c10d5dc8"
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sierra = "cairo-compile . -r"
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=1.3.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.8.0" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.9.0" }

[lib]

Expand Down
9 changes: 5 additions & 4 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ mod AccessController {
use starknet::ContractAddress;
use starknet::class_hash::ClassHash;

use openzeppelin::access::ownable::ownable::OwnableComponent;

use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::ownable::{OwnableComponent, IOwnable};
use chainlink::libraries::type_and_version::ITypeAndVersion;
use chainlink::libraries::upgradeable::{Upgradeable, IUpgradeable};

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: AccessControlComponent, storage: access_control, event: AccessControlEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl InternalImpl = OwnableComponent::InternalImpl<ContractState>;
impl OwnableImpl = OwnableComponent::OwnableTwoStepImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl AccessControlImpl =
Expand Down Expand Up @@ -50,7 +51,7 @@ mod AccessController {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
self.ownable.assert_only_owner();
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/account.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// copied from https://github.com/OpenZeppelin/cairo-contracts/blob/v0.8.1/src/presets/account.cairo
// copied from https://raw.githubusercontent.com/OpenZeppelin/cairo-contracts/861fc416f87addbe23a3b47f9d19ab27c10d5dc8/src/presets/account.cairo (0.9.0)

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.8.1 (presets/account.cairo)
// OpenZeppelin Contracts for Cairo v0.9.0 (presets/account.cairo)

/// # Account Preset
///
Expand Down
11 changes: 6 additions & 5 deletions contracts/src/emergency/sequencer_uptime_feed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ mod SequencerUptimeFeed {
use option::OptionTrait;
use zeroable::Zeroable;

use chainlink::libraries::ownable::{OwnableComponent, IOwnable};
use openzeppelin::access::ownable::ownable::OwnableComponent;

use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::access_control::AccessControlComponent::InternalTrait as AccessControlInternalTrait;
use chainlink::libraries::type_and_version::ITypeAndVersion;
Expand All @@ -40,7 +41,7 @@ mod SequencerUptimeFeed {
component!(path: AccessControlComponent, storage: access_control, event: AccessControlEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl OwnableImpl = OwnableComponent::OwnableTwoStepImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
Expand Down Expand Up @@ -116,7 +117,7 @@ mod SequencerUptimeFeed {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl AggregatorImpl of IAggregator<ContractState> {
fn latest_round_data(self: @ContractState) -> Round {
self._require_read_access();
Expand Down Expand Up @@ -189,7 +190,7 @@ mod SequencerUptimeFeed {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl SequencerUptimeFeedImpl of super::ISequencerUptimeFeed<ContractState> {
fn set_l1_sender(ref self: ContractState, address: EthAddress) {
self.ownable.assert_only_owner();
Expand Down Expand Up @@ -220,7 +221,7 @@ mod SequencerUptimeFeed {
/// Upgradeable
///
#[external(v0)]
#[abi(embed_v0)]
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
self.ownable.assert_only_owner();
Upgradeable::upgrade(new_impl)
Expand Down
1 change: 0 additions & 1 deletion contracts/src/libraries.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod ownable;
mod access_control;
mod token;
mod upgradeable;
Expand Down
11 changes: 6 additions & 5 deletions contracts/src/libraries/access_control.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ mod AccessControlComponent {
use starknet::class_hash::ClassHash;
use zeroable::Zeroable;

use chainlink::libraries::ownable::{OwnableComponent};
use openzeppelin::access::ownable::ownable::OwnableComponent;

use OwnableComponent::InternalImpl as OwnableInternalImpl;

#[storage]
Expand Down Expand Up @@ -90,7 +91,7 @@ mod AccessControlComponent {
}

fn add_access(ref self: ComponentState<TContractState>, user: ContractAddress) {
get_dep_component!(self, Ownable).assert_only_owner();
get_dep_component!(@self, Ownable).assert_only_owner();
let has_access = self._access_list.read(user);
if !has_access {
self._access_list.write(user, true);
Expand All @@ -99,7 +100,7 @@ mod AccessControlComponent {
}

fn remove_access(ref self: ComponentState<TContractState>, user: ContractAddress) {
get_dep_component!(self, Ownable).assert_only_owner();
get_dep_component!(@self, Ownable).assert_only_owner();
let has_access = self._access_list.read(user);
if has_access {
self._access_list.write(user, false);
Expand All @@ -108,7 +109,7 @@ mod AccessControlComponent {
}

fn enable_access_check(ref self: ComponentState<TContractState>) {
get_dep_component!(self, Ownable).assert_only_owner();
get_dep_component!(@self, Ownable).assert_only_owner();
let check_enabled = self._check_enabled.read();
if !check_enabled {
self._check_enabled.write(true);
Expand All @@ -117,7 +118,7 @@ mod AccessControlComponent {
}

fn disable_access_check(ref self: ComponentState<TContractState>) {
get_dep_component!(self, Ownable).assert_only_owner();
get_dep_component!(@self, Ownable).assert_only_owner();
let check_enabled = self._check_enabled.read();
if check_enabled {
self._check_enabled.write(false);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/libraries/mocks/mock_non_upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod MockNonUpgradeable {
#[constructor]
fn constructor(ref self: ContractState) {}

#[external(v0)]
#[abi(embed_v0)]
impl MockNonUpgradeableImpl of super::IMockNonUpgradeable<ContractState> {
fn bar(self: @ContractState) -> bool {
true
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/libraries/mocks/mock_upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod MockUpgradeable {
#[constructor]
fn constructor(ref self: ContractState) {}

#[external(v0)]
#[abi(embed_v0)]
impl MockUpgradeableImpl of super::IMockUpgradeable<ContractState> {
fn foo(self: @ContractState) -> bool {
true
Expand Down
155 changes: 0 additions & 155 deletions contracts/src/libraries/ownable.cairo

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/src/multisig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ mod Multisig {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
self._require_multisig();
Upgradeable::upgrade(new_impl)
}
}

#[external(v0)]
#[abi(embed_v0)]
impl MultisigImpl of super::IMultisig<ContractState> {
/// Views
Expand Down
Loading

0 comments on commit 0e7c67b

Please sign in to comment.