Skip to content

Commit

Permalink
BCI-2625: add TypeAndVersion interface and usage (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Feb 19, 2024
1 parent 00cac1d commit e1051e3
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 33 deletions.
13 changes: 6 additions & 7 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod AccessController {

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);
Expand Down Expand Up @@ -42,13 +43,11 @@ mod AccessController {
self.access_control.initializer();
}

///
/// Upgradeable
///

// #[view]
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
}
}

#[external(v0)]
Expand Down
12 changes: 8 additions & 4 deletions contracts/src/emergency/sequencer_uptime_feed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod SequencerUptimeFeed {
use chainlink::libraries::ownable::{OwnableComponent, IOwnable};
use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::access_control::AccessControlComponent::InternalTrait as AccessControlInternalTrait;
use chainlink::libraries::type_and_version::ITypeAndVersion;
use chainlink::ocr2::aggregator::Round;
use chainlink::ocr2::aggregator::IAggregator;
use chainlink::ocr2::aggregator::{Transmission};
Expand Down Expand Up @@ -108,6 +109,13 @@ mod SequencerUptimeFeed {
to_address: EthAddress
}

#[abi(embed_v0)]
impl TypeAndVersion of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'SequencerUptimeFeed 1.0.0'
}
}

#[external(v0)]
impl AggregatorImpl of IAggregator<ContractState> {
fn latest_round_data(self: @ContractState) -> Round {
Expand Down Expand Up @@ -143,10 +151,6 @@ mod SequencerUptimeFeed {
fn decimals(self: @ContractState) -> u8 {
0_u8
}

fn type_and_version(self: @ContractState) -> felt252 {
'SequencerUptimeFeed 1.0.0'
}
}

#[constructor]
Expand Down
1 change: 1 addition & 0 deletions contracts/src/libraries.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mod access_control;
mod token;
mod upgradeable;
mod mocks;
mod type_and_version;
4 changes: 4 additions & 0 deletions contracts/src/libraries/type_and_version.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[starknet::interface]
trait ITypeAndVersion<TContractState> {
fn type_and_version(self: @TContractState) -> felt252;
}
13 changes: 8 additions & 5 deletions contracts/src/multisig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ trait IMultisig<TContractState> {
fn is_confirmed(self: @TContractState, nonce: u128, signer: ContractAddress) -> bool;
fn is_executed(self: @TContractState, nonce: u128) -> bool;
fn get_transaction(self: @TContractState, nonce: u128) -> (Transaction, Array::<felt252>);
fn type_and_version(self: @TContractState) -> felt252;
fn submit_transaction(
ref self: TContractState,
to: ContractAddress,
Expand Down Expand Up @@ -92,6 +91,7 @@ mod Multisig {
use starknet::storage_write_syscall;
use starknet::class_hash::ClassHash;

use chainlink::libraries::type_and_version::ITypeAndVersion;
use chainlink::libraries::upgradeable::{Upgradeable, IUpgradeable};

#[event]
Expand Down Expand Up @@ -161,6 +161,13 @@ mod Multisig {
self._set_threshold(threshold);
}

#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState,) -> felt252 {
'Multisig 1.0.0'
}
}

#[external(v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
Expand Down Expand Up @@ -215,10 +222,6 @@ mod Multisig {
(transaction, calldata)
}

fn type_and_version(self: @ContractState,) -> felt252 {
'Multisig 1.0.0'
}

/// Externals

fn submit_transaction(
Expand Down
13 changes: 8 additions & 5 deletions contracts/src/ocr2/aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ trait IAggregator<TContractState> {
fn round_data(self: @TContractState, round_id: u128) -> Round;
fn description(self: @TContractState) -> felt252;
fn decimals(self: @TContractState) -> u8;
fn type_and_version(self: @TContractState) -> felt252;
}

#[derive(Copy, Drop, Serde)]
Expand Down Expand Up @@ -205,6 +204,7 @@ mod Aggregator {
use chainlink::libraries::access_control::{
IAccessControllerDispatcher, IAccessControllerDispatcherTrait
};
use chainlink::libraries::type_and_version::ITypeAndVersion;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: AccessControlComponent, storage: access_control, event: AccessControlEvent);
Expand Down Expand Up @@ -326,6 +326,13 @@ mod Aggregator {
}
}

#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'ocr2/aggregator.cairo 1.0.0'
}
}

#[external(v0)]
impl AggregatorImpl of super::IAggregator<ContractState> {
fn latest_round_data(self: @ContractState) -> Round {
Expand Down Expand Up @@ -362,10 +369,6 @@ mod Aggregator {
self._require_read_access();
self._decimals.read()
}

fn type_and_version(self: @ContractState) -> felt252 {
'ocr2/aggregator.cairo 1.0.0'
}
}

// ---
Expand Down
9 changes: 7 additions & 2 deletions contracts/src/ocr2/aggregator_proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ trait IAggregatorProxy<TContractState> {
fn round_data(self: @TContractState, round_id: felt252) -> Round;
fn description(self: @TContractState) -> felt252;
fn decimals(self: @TContractState) -> u8;
fn type_and_version(self: @TContractState) -> felt252;
}

#[starknet::interface]
Expand Down Expand Up @@ -53,6 +52,9 @@ mod AggregatorProxy {
use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::access_control::AccessControlComponent::InternalTrait as AccessControlInternalTrait;
use chainlink::utils::split_felt;
use chainlink::libraries::type_and_version::{
ITypeAndVersion, ITypeAndVersionDispatcher, ITypeAndVersionDispatcherTrait
};
use chainlink::libraries::upgradeable::{Upgradeable, IUpgradeable};

const SHIFT: felt252 = 0x100000000000000000000000000000000;
Expand Down Expand Up @@ -148,10 +150,13 @@ mod AggregatorProxy {
let aggregator = IAggregatorDispatcher { contract_address: phase.aggregator };
aggregator.decimals()
}
}

#[abi(embed_v0)]
impl TypeAndVersion of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
let phase = self._current_phase.read();
let aggregator = IAggregatorDispatcher { contract_address: phase.aggregator };
let aggregator = ITypeAndVersionDispatcher { contract_address: phase.aggregator };
aggregator.type_and_version()
}
}
Expand Down
12 changes: 8 additions & 4 deletions contracts/src/ocr2/mocks/mock_aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod MockAggregator {
use chainlink::ocr2::aggregator::IAggregator;
use chainlink::ocr2::aggregator::Aggregator::{Transmission, NewTransmission};
use chainlink::ocr2::aggregator::Round;
use chainlink::libraries::type_and_version::ITypeAndVersion;

#[event]
use chainlink::ocr2::aggregator::Aggregator::Event;
Expand Down Expand Up @@ -83,6 +84,13 @@ mod MockAggregator {
}
}

#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'mock_aggregator.cairo 1.0.0'
}
}

#[external(v0)]
impl Aggregator of IAggregator<ContractState> {
fn round_data(self: @ContractState, round_id: u128) -> Round {
Expand All @@ -109,9 +117,5 @@ mod MockAggregator {
fn description(self: @ContractState) -> felt252 {
'mock'
}

fn type_and_version(self: @ContractState) -> felt252 {
'mock_aggregator.cairo 1.0.0'
}
}
}
12 changes: 6 additions & 6 deletions contracts/src/token/link_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod LinkToken {
use openzeppelin::token::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};
use chainlink::libraries::token::erc677::ERC677Component;
use chainlink::libraries::ownable::{OwnableComponent, IOwnable};
use chainlink::libraries::type_and_version::ITypeAndVersion;
use chainlink::libraries::upgradeable::{Upgradeable, IUpgradeable};

use openzeppelin::token::erc20::ERC20Component;
Expand Down Expand Up @@ -94,14 +95,13 @@ mod LinkToken {
self._minter.read()
}

// TODO #[view]
fn type_and_version(self: @ContractState) -> felt252 {
'LinkToken 1.0.0'
#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'LinkToken 1.0.0'
}
}

//
// Upgradeable
//
#[external(v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
Expand Down

0 comments on commit e1051e3

Please sign in to comment.