Skip to content

Commit

Permalink
cairo-format
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Aug 10, 2023
1 parent d4ce9a7 commit c794ef2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
12 changes: 3 additions & 9 deletions examples/contracts/aggregator-consumer/src/ocr2/consumer.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[contract]
mod AggregatorConsumer {
use starknet::ContractAddress;
Expand All @@ -10,7 +9,7 @@ mod AggregatorConsumer {
use chainlink::ocr2::aggregator_proxy::IAggregatorDispatcherTrait;

struct Storage {
_ocr_address: ContractAddress,
_ocr_address: ContractAddress,
}

#[constructor]
Expand All @@ -20,16 +19,11 @@ mod AggregatorConsumer {

#[view]
fn read_latest_round() -> Round {
IAggregatorDispatcher {
contract_address: _ocr_address::read()
}.latest_round_data()
IAggregatorDispatcher { contract_address: _ocr_address::read() }.latest_round_data()
}

#[view]
fn read_decimals() -> u8 {
IAggregatorDispatcher {
contract_address: _ocr_address::read()
}.decimals()
IAggregatorDispatcher { contract_address: _ocr_address::read() }.decimals()
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[contract]
mod AggregatorPriceConsumerWithSequencer {
use box::BoxTrait;
Expand Down Expand Up @@ -31,15 +30,15 @@ mod AggregatorPriceConsumerWithSequencer {
#[view]
fn get_latest_price() -> u128 {
assert_sequencer_healthy();
let round = IAggregatorDispatcher{
let round = IAggregatorDispatcher {
contract_address: _aggregator_address::read()
}.latest_round_data();
round.answer
}

#[external]
fn assert_sequencer_healthy() {
let round = IAggregatorDispatcher{
let round = IAggregatorDispatcher {
contract_address: _uptime_feed_address::read()
}.latest_round_data();
let timestamp = starknet::info::get_block_info().unbox().block_timestamp;
Expand All @@ -58,8 +57,5 @@ mod AggregatorPriceConsumerWithSequencer {
}
}
}



}

56 changes: 36 additions & 20 deletions examples/contracts/proxy-consumer/src/proxy_consumer.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[contract]
mod ProxyConsumer {
use zeroable::Zeroable;
Expand Down Expand Up @@ -28,25 +27,34 @@ mod ProxyConsumer {
)?;
let answer = storage_read_syscall(
address_domain, storage_address_from_base_and_offset(base, 1_u8)
)?.try_into().unwrap();
)?
.try_into()
.unwrap();
let block_num = storage_read_syscall(
address_domain, storage_address_from_base_and_offset(base, 2_u8)
)?.try_into().unwrap();
)?
.try_into()
.unwrap();
let started_at = storage_read_syscall(
address_domain, storage_address_from_base_and_offset(base, 3_u8)
)?.try_into().unwrap();
)?
.try_into()
.unwrap();
let updated_at = storage_read_syscall(
address_domain, storage_address_from_base_and_offset(base, 4_u8)
)?.try_into().unwrap();

)?
.try_into()
.unwrap();

Result::Ok(Round {
round_id: round_id,
answer: answer,
block_num: block_num,
started_at: started_at,
updated_at: updated_at
})
Result::Ok(
Round {
round_id: round_id,
answer: answer,
block_num: block_num,
started_at: started_at,
updated_at: updated_at
}
)
}

fn write(
Expand All @@ -56,16 +64,24 @@ mod ProxyConsumer {
address_domain, storage_address_from_base_and_offset(base, 0_u8), value.round_id
)?;
storage_write_syscall(
address_domain, storage_address_from_base_and_offset(base, 1_u8), value.answer.into()
address_domain,
storage_address_from_base_and_offset(base, 1_u8),
value.answer.into()
)?;
storage_write_syscall(
address_domain, storage_address_from_base_and_offset(base, 2_u8), value.block_num.into()
address_domain,
storage_address_from_base_and_offset(base, 2_u8),
value.block_num.into()
)?;
storage_write_syscall(
address_domain, storage_address_from_base_and_offset(base, 3_u8), value.started_at.into()
address_domain,
storage_address_from_base_and_offset(base, 3_u8),
value.started_at.into()
)?;
storage_write_syscall(
address_domain, storage_address_from_base_and_offset(base, 4_u8), value.updated_at.into()
storage_write_syscall(
address_domain,
storage_address_from_base_and_offset(base, 4_u8),
value.updated_at.into()
)
}
}
Expand All @@ -80,11 +96,11 @@ mod ProxyConsumer {
assert(!proxy_address.is_zero(), 'proxy address 0');
_proxy_address::write(proxy_address);
get_latest_round_data();
}
}

#[external]
fn get_latest_round_data() -> Round {
let round = IAggregatorDispatcher{
let round = IAggregatorDispatcher {
contract_address: _proxy_address::read()
}.latest_round_data();
_feed_data::write(round);
Expand Down

0 comments on commit c794ef2

Please sign in to comment.