Skip to content

Commit

Permalink
Merge pull request #315 from smartcontractkit/cairo-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer authored Aug 8, 2023
2 parents d2c9567 + 97526ae commit 93dbe83
Show file tree
Hide file tree
Showing 51 changed files with 2,778 additions and 2,893 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: "v1.1.0"
default: "v2.1.0"
required: false
scarb_version:
description: Scarb release version
default: "v0.4.0"
default: "v0.6.0"
required: false

runs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-tests-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
TTL: 3h
TEST_DURATION: 15m
NODE_COUNT: 5
INTERNAL_DOCKER_REPO: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com
permissions:
checks: write
pull-requests: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-tests-soak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
TEST_SUITE: soak
TEST_ARGS: -test.timeout ${{ github.event.inputs.ttl }}
TEST_LOG_LEVEL: debug
INTERNAL_DOCKER_REPO: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com
permissions:
checks: write
pull-requests: write
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,14 @@ format-go-mod-tidy:

.PHONY: format-cairo
format-cairo:
find ./contracts/src -name "*.cairo" -type f \
-exec cairo-format -i {} +
find ./examples -name "*.cairo" -type f \
-exec cairo-format -i {} +
cairo-format -i ./contracts/src/**/*.cairo
cairo-format -i ./examples/**/*.cairo

.PHONY: format-cairo-check
format-cairo-check:
find ./contracts/src -name "*.cairo" -type f \
-exec cairo-format -c {} +
cairo-format -c ./contracts/src/**/*.cairo
# TODO: re-enable once examples are rewritten
# find ./examples -name "*.cairo" -type f \
# -exec cairo-format -c {} +
# cairo-format -c ./examples/**/*.cairo

.PHONY: format-ts
format-ts:
Expand Down Expand Up @@ -268,7 +264,7 @@ build-cairo-contracts:

.PHONY: test-cairo-contracts
test-cairo-contracts:
cd contracts && scarb run test
cd contracts && scarb test

# TODO: this script needs to be replaced with a predefined K8s enviroment
.PHONY: env-devnet-hardhat
Expand Down
5 changes: 2 additions & 3 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ homepage = "https://github.com/smartcontractkit/chainlink-starknet"

[scripts]
sierra = "cairo-compile . -r"
test = "cairo-test --starknet ."
# Add your own custom commands and run them with scarb run <command>

# Uncomment if you want to use dependencies
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=1.0.0"
# quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "495ed8a" } # latest cairo-2 branch

[[target.starknet-contract]]
sierra = true
Expand All @@ -27,4 +26,4 @@ casm-add-pythonic-hints = true
allowed-libfuncs-deny = true

# TODO: change the allowlist to 'audited' when cairo v2 is released
allowed-libfuncs-list.name = "experimental_v0.1.0"
allowed-libfuncs-list.name = "audited"
4 changes: 2 additions & 2 deletions contracts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ecdsa
fastecdsa
sympy
cairo-lang>=0.11.1.1
starknet-devnet>=0.5.3
cairo-lang>=0.12.1a0
starknet-devnet>=0.6.0a0
145 changes: 76 additions & 69 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
@@ -1,99 +1,106 @@
use starknet::ContractAddress;

#[abi]
trait IAccessController {
fn has_access(user: ContractAddress, data: Array<felt252>) -> bool;
fn add_access(user: ContractAddress);
fn remove_access(user: ContractAddress);
fn enable_access_check();
fn disable_access_check();
}

#[contract]
#[starknet::contract]
mod AccessController {
use starknet::ContractAddress;
use starknet::class_hash::ClassHash;

use chainlink::libraries::access_control::AccessControl;
use chainlink::libraries::ownable::Ownable;
use chainlink::libraries::access_control::{AccessControl, IAccessController};
use chainlink::libraries::ownable::{Ownable, IOwnable};
use chainlink::libraries::upgradeable::Upgradeable;

#[constructor]
fn constructor(owner_address: ContractAddress) {
Ownable::initializer(owner_address);
AccessControl::initializer();
}

#[view]
fn has_access(user: ContractAddress, data: Array<felt252>) -> bool {
AccessControl::has_access(user, data)
}

#[external]
fn add_access(user: ContractAddress) {
Ownable::assert_only_owner();
AccessControl::add_access(user);
}

#[external]
fn remove_access(user: ContractAddress) {
Ownable::assert_only_owner();
AccessControl::remove_access(user);
}
#[storage]
struct Storage {}

#[external]
fn enable_access_check() {
Ownable::assert_only_owner();
AccessControl::enable_access_check();
#[constructor]
fn constructor(ref self: ContractState, owner_address: ContractAddress) {
let mut ownable = Ownable::unsafe_new_contract_state();
Ownable::constructor(ref ownable, owner_address);
let mut access_control = AccessControl::unsafe_new_contract_state();
AccessControl::constructor(ref access_control);
}

#[external]
fn disable_access_check() {
Ownable::assert_only_owner();
AccessControl::disable_access_check();
#[external(v0)]
impl AccessControllerImpl of IAccessController<ContractState> {
fn has_access(self: @ContractState, user: ContractAddress, data: Array<felt252>) -> bool {
let state = AccessControl::unsafe_new_contract_state();
AccessControl::has_access(@state, user, data)
}

fn add_access(ref self: ContractState, user: ContractAddress) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::add_access(ref state, user);
}

fn remove_access(ref self: ContractState, user: ContractAddress) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::remove_access(ref state, user);
}

fn enable_access_check(ref self: ContractState) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::enable_access_check(ref state);
}

fn disable_access_check(ref self: ContractState) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::disable_access_check(ref state);
}
}

///
/// Ownable
///

#[view]
fn owner() -> ContractAddress {
Ownable::owner()
}

#[view]
fn proposed_owner() -> ContractAddress {
Ownable::proposed_owner()
}

#[external]
fn transfer_ownership(new_owner: ContractAddress) {
Ownable::transfer_ownership(new_owner);
}

#[external]
fn accept_ownership() {
Ownable::accept_ownership();
}

#[external]
fn renounce_ownership() {
Ownable::renounce_ownership();
#[external(v0)]
impl OwnableImpl of IOwnable<ContractState> {
fn owner(self: @ContractState) -> ContractAddress {
let state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::owner(@state)
}

fn proposed_owner(self: @ContractState) -> ContractAddress {
let state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::proposed_owner(@state)
}

fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::transfer_ownership(ref state, new_owner)
}

fn accept_ownership(ref self: ContractState) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::accept_ownership(ref state)
}

fn renounce_ownership(ref self: ContractState) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::renounce_ownership(ref state)
}
}

///
/// Upgradeable
///

#[view]
fn type_and_version() -> felt252 {
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
}

#[external]
fn upgrade(new_impl: ClassHash) {
Ownable::assert_only_owner();
#[external(v0)]
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
Upgradeable::upgrade(new_impl);
}
}
2 changes: 0 additions & 2 deletions contracts/src/account.cairo

This file was deleted.

Loading

0 comments on commit 93dbe83

Please sign in to comment.