Skip to content

feat: frontend data provider #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ Note that Devnet deployments are ephemeral. Once you kill your Devnet instance,

| Module | Address |
| ------ | --------|
| Abbot | `0x6352de997a7fde3bc733675180e843b5fe585b7ef464a2987a76fae454af78d` |
| Absorber | `0x48deaee30965a88184619f8b3b30b805727654468ae9b42b483a84831b9e5ea` |
| Allocator | `0xa7b142b8937cb31507fe598252d44a516f2bc64eb285f1807163461d6c208e` |
| Caretaker | `0xeab066a1083f32ff92e3ac9696dc847928fa0f4035bda93dacc34df1cef604` |
| Controller | `0x3297c2080d6c565055ca1c7695b9b6e458600515ebd76101ec4221bcea877ce` |
| Equalizer | `0x43d5cd32847304e168fca09feef5620aaf7c3a0e6fa1689416541be95d8d183` |
| Flash Mint | `0x2c6c7acedfbb6607ecc33cd6b2134f3dea2f16998b44219067063ae4ccb6e42` |
| Gate[ETH] | `0x20ee25588aa6225c58a55110fc5f5b983d074d4ed5b1d98788825a9d3305ac0` |
| Gate[STRK] | `0x594f653061a2181514fad04dc005f7eb8210786a45b577f416029e0ffb01cd7` |
| Pragma | `0x71415935245134eaa125de2df12772443726d5a149a4995f60208c28653a54f` |
| Purger | `0x67f57eec3ce8ba9781985cafcb774283d6450662906691b65d882e13dc59934` |
| Seer | `0x14dac867b21b5b6645cc046e0125cca8e81e8dd9d95ca5dd8e756fa053a2984` |
| Sentinel | `0x2f1778912ef186e2434dfe0957e00ed2122dd48f3aa2e8bc46173fd67bdd065` |
| Shrine | `0x4b3bfe81472b5a01dc3c1fba3456bb0979852deaca43da49d406189371d09e6` |
| Abbot | `0x55753ea07d7c53b0d512dd14aa1fb536b02efc179907905610619eecaac1e97` |
| Absorber | `0x32e5f6bfc937e239e9f1c7c2c30f0d8ce59d7d703d82bc69382b4d2b0be1e4e` |
| Allocator | `0x470ad58d601501eab46479e69c0d9367e2b429aca88a1775114e3b074b2117b` |
| Caretaker | `0x1461305951ac7fb7af835a9a19b99ae5e135ba1fb64477d4b92a871fb85a2b1` |
| Controller | `0x5c4d4b9ce7f54dc50354b99dfca29c3ba3935501e5244e048fa87b83043ddc2` |
| Equalizer | `0x54b46ed341533fe4da0116f27e201276165e3a3fd030ac391b6e9967668996d` |
| Flash Mint | `0x6f1577c508f95e633d22eaa65c5781442651336d30a95ba149a80fd85db29bc` |
| Frontend Data Provider | `0x6f7cf629552047a337324712571068b3f8f2deddcc0454533596ef5dfa192d` |
| Gate[ETH] | `0x23dbc80de342f86f2b33b27d5593c259809961d9ecbd9f69b7088babba1016f` |
| Gate[STRK] | `0x2918116ed1154cfe378eaefa5ee83914c9bed787815cdb5a82d25185737dad` |
| Pragma | `0xa163eb702f1cba67680cb67a2ad018dd6d349b76ebc9d85102a83857948304` |
| Purger | `0x1e188c4223245660e692e7f0b9834d11687cec5aa37da0889cbe2e2e2743c28` |
| Seer | `0x1ba77782ba5dea67bcf4f71c2b98849b598d030df02952bf8f62e3eb6b5b192` |
| Sentinel | `0x255e43013fd414520d27a0491c64aa03705e6f728999d0ceb44e395ac5c9c1d` |
| Shrine | `0x7d2a06078ee45540e9507a0daf01ac94f0550b675958dda88cbbc6fc8993708` |
1 change: 1 addition & 0 deletions scripts/deploy/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build-external-contracts = [
"opus::mock::erc20_mintable::erc20_mintable",
"opus::mock::mock_pragma::mock_pragma",
"opus::mock::mock_switchboard::mock_switchboard",
"opus::periphery::frontend_data_provider::frontend_data_provider",
]

[scripts]
Expand Down
464 changes: 243 additions & 221 deletions scripts/deploy/deploy_sepolia_alpha-sepolia_state.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/deploy/src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::{ClassHash, ContractAddress};

// Constants for deployment
pub const MAX_FEE: felt252 = 999999999999999;
pub const MAX_FEE: felt252 = 9999999999999999;
pub const SALT: felt252 = 0x3;

// Constants for Shrine
Expand Down
13 changes: 8 additions & 5 deletions scripts/deploy/src/deploy_devnet.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use deployment::constants::{MAX_FEE, SALT};
use deployment::constants;
use deployment::core_deployment;
use deployment::mock_deployment;
use deployment::mock_utils;
use deployment::utils;
use deployment::{constants, core_deployment, mock_deployment, mock_utils, periphery_deployment, utils};
use opus::constants::{ETH_USD_PAIR_ID, PRAGMA_DECIMALS, STRK_USD_PAIR_ID, WBTC_DECIMALS, WBTC_USD_PAIR_ID};
use opus::core::roles::{absorber_roles, sentinel_roles, seer_roles, shrine_roles};
use opus::utils::math::wad_to_fixed_point;
Expand Down Expand Up @@ -174,6 +170,12 @@ fn main() {
utils::set_yang_pair_id_for_oracle(switchboard, wbtc, WBTC_USD_PAIR_ID);
utils::set_yang_pair_id_for_oracle(switchboard, strk, STRK_USD_PAIR_ID);

// Peripheral deployment
println!("Deploying periphery contracts");
let frontend_data_provider: ContractAddress = periphery_deployment::deploy_frontend_data_provider(
admin, shrine, sentinel
);

// Print summary table of deployed contracts
println!("-------------------------------------------------\n");
println!("Deployed addresses");
Expand All @@ -184,6 +186,7 @@ fn main() {
println!("Controller: {}", controller);
println!("Equalizer: {}", equalizer);
println!("Flash Mint: {}", flash_mint);
println!("Frontend Data Provider: {}", frontend_data_provider);
println!("Gate[ETH]: {}", eth_gate);
println!("Gate[STRK]: {}", strk_gate);
println!("Gate[WBTC]: {}", wbtc_gate);
Expand Down
11 changes: 9 additions & 2 deletions scripts/deploy/src/deploy_sepolia.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use deployment::constants::MAX_FEE;
use deployment::{constants, core_deployment, utils};
use deployment::{constants, core_deployment, periphery_deployment, utils};
use opus::constants::{ETH_USD_PAIR_ID, STRK_USD_PAIR_ID};
use opus::core::roles;
use sncast_std::{
Expand All @@ -13,7 +13,7 @@ fn main() {

println!("Deploying core contracts");
//let shrine: ContractAddress = core_deployment::deploy_shrine(admin);
let shrine: ContractAddress = 0x4b3bfe81472b5a01dc3c1fba3456bb0979852deaca43da49d406189371d09e6.try_into().unwrap();
let shrine: ContractAddress = core_deployment::deploy_shrine(admin);
let flash_mint: ContractAddress = core_deployment::deploy_flash_mint(shrine);
let sentinel: ContractAddress = core_deployment::deploy_sentinel(admin, shrine);
let seer: ContractAddress = core_deployment::deploy_seer(admin, shrine, sentinel);
Expand Down Expand Up @@ -112,6 +112,12 @@ fn main() {
utils::set_yang_pair_id_for_oracle(pragma, eth, ETH_USD_PAIR_ID);
utils::set_yang_pair_id_for_oracle(pragma, strk, STRK_USD_PAIR_ID);

// Peripheral deployment
println!("Deploying periphery contracts");
let frontend_data_provider: ContractAddress = periphery_deployment::deploy_frontend_data_provider(
admin, shrine, sentinel
);

println!("-------------------------------------------------\n");
println!("Abbot: {}", abbot);
println!("Absorber: {}", absorber);
Expand All @@ -120,6 +126,7 @@ fn main() {
println!("Controller: {}", controller);
println!("Equalizer: {}", equalizer);
println!("Flash Mint: {}", flash_mint);
println!("Frontend Data Provider: {}", frontend_data_provider);
println!("Gate[ETH]: {}", eth_gate);
println!("Gate[STRK]: {}", strk_gate);
println!("Pragma: {}", pragma);
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ mod deploy_devnet;
mod deploy_sepolia;
pub mod mock_deployment;
pub mod mock_utils;
pub mod periphery_deployment;
pub mod utils;
29 changes: 29 additions & 0 deletions scripts/deploy/src/periphery_deployment.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use deployment::constants::MAX_FEE;
use sncast_std::{
declare, DeclareResult, deploy, DeployResult, DisplayClassHash, DisplayContractAddress, invoke, InvokeResult,
ScriptCommandError
};
use starknet::{ClassHash, ContractAddress};

//
// Deployment helpers
//

pub fn deploy_frontend_data_provider(
admin: ContractAddress, shrine: ContractAddress, sentinel: ContractAddress
) -> ContractAddress {
let declare_frontend_data_provider = declare("frontend_data_provider", Option::Some(MAX_FEE), Option::None)
.expect('failed FDP declare');
let frontend_data_provider_calldata: Array<felt252> = array![admin.into(), shrine.into(), sentinel.into()];
let deploy_frontend_data_provider = deploy(
declare_frontend_data_provider.class_hash,
frontend_data_provider_calldata,
Option::None,
true,
Option::Some(MAX_FEE),
Option::None
)
.expect('failed FDP deploy');

deploy_frontend_data_provider.contract_address
}
16 changes: 8 additions & 8 deletions src/core/sentinel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod sentinel {

// Helper constant to set the starting index for iterating over the
// yangs in the order they were added
const LOOP_START: u64 = 1;
const LOOP_START: u32 = 1;

//
// Storage
Expand All @@ -42,10 +42,10 @@ pub mod sentinel {
// mapping between a yang address and our deployed Gate
yang_to_gate: LegacyMap::<ContractAddress, IGateDispatcher>,
// length of the yang_addresses array
yang_addresses_count: u64,
yang_addresses_count: u32,
// array of yang addresses added to the Shrine via this Sentinel
// starts from index 1
yang_addresses: LegacyMap::<u64, ContractAddress>,
yang_addresses: LegacyMap::<u32, ContractAddress>,
// The Shrine associated with this Sentinel
shrine: IShrineDispatcher,
// mapping between a yang address and the cap on the yang's asset in the
Expand Down Expand Up @@ -119,8 +119,8 @@ pub mod sentinel {
}

fn get_yang_addresses(self: @ContractState) -> Span<ContractAddress> {
let mut idx: u64 = LOOP_START;
let loop_end: u64 = self.yang_addresses_count.read() + LOOP_START;
let mut idx: u32 = LOOP_START;
let loop_end: u32 = self.yang_addresses_count.read() + LOOP_START;
let mut addresses: Array<ContractAddress> = ArrayTrait::new();
loop {
if idx == loop_end {
Expand All @@ -131,11 +131,11 @@ pub mod sentinel {
}
}

fn get_yang_addresses_count(self: @ContractState) -> u64 {
fn get_yang_addresses_count(self: @ContractState) -> u32 {
self.yang_addresses_count.read()
}

fn get_yang(self: @ContractState, idx: u64) -> ContractAddress {
fn get_yang(self: @ContractState, idx: u32) -> ContractAddress {
self.yang_addresses.read(idx)
}

Expand Down Expand Up @@ -190,7 +190,7 @@ pub mod sentinel {
let gate = IGateDispatcher { contract_address: gate };
assert(gate.get_asset() == yang, 'SE: Asset of gate is not yang');

let index: u64 = self.yang_addresses_count.read() + 1;
let index: u32 = self.yang_addresses_count.read() + 1;
self.yang_addresses_count.write(index);
self.yang_addresses.write(index, yang);
self.yang_to_gate.write(yang, gate);
Expand Down
80 changes: 40 additions & 40 deletions src/core/shrine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,46 @@ pub mod shrine {
self.deposits.read((yang_id, trove_id))
}

// Returns an ordered array of the `YangBalance` struct for a trove's deposits.
// Starts from yang ID 1.
// Note that zero values are added to the return array because downstream
// computation assumes the full array of yangs.
fn get_trove_deposits(self: @ContractState, trove_id: u64) -> Span<YangBalance> {
let mut yang_balances: Array<YangBalance> = ArrayTrait::new();

let mut current_yang_id: u32 = START_YANG_IDX;
let loop_end: u32 = self.yangs_count.read() + START_YANG_IDX;
loop {
if current_yang_id == loop_end {
break yang_balances.span();
}

let deposited: Wad = self.deposits.read((current_yang_id, trove_id));
yang_balances.append(YangBalance { yang_id: current_yang_id, amount: deposited });

current_yang_id += 1;
}
}

// Returns an ordered array of the `YangBalance` struct for the total deposited yangs in the Shrine.
// Starts from yang ID 1.
fn get_shrine_deposits(self: @ContractState) -> Span<YangBalance> {
let mut yang_balances: Array<YangBalance> = ArrayTrait::new();

let mut current_yang_id: u32 = START_YANG_IDX;
let loop_end: u32 = self.yangs_count.read() + START_YANG_IDX;
loop {
if current_yang_id == loop_end {
break yang_balances.span();
}

let yang_total: Wad = self.yang_total.read(current_yang_id);
yang_balances.append(YangBalance { yang_id: current_yang_id, amount: yang_total });

current_yang_id += 1;
}
}

fn get_budget(self: @ContractState) -> SignedWad {
self.budget.read()
}
Expand Down Expand Up @@ -1410,46 +1450,6 @@ pub mod shrine {
}
}

// Returns an ordered array of the `YangBalance` struct for a trove's deposits.
// Starts from yang ID 1.
// Note that zero values are added to the return array because downstream
// computation assumes the full array of yangs.
fn get_trove_deposits(self: @ContractState, trove_id: u64) -> Span<YangBalance> {
let mut yang_balances: Array<YangBalance> = ArrayTrait::new();

let mut current_yang_id: u32 = START_YANG_IDX;
let loop_end: u32 = self.yangs_count.read() + START_YANG_IDX;
loop {
if current_yang_id == loop_end {
break yang_balances.span();
}

let deposited: Wad = self.deposits.read((current_yang_id, trove_id));
yang_balances.append(YangBalance { yang_id: current_yang_id, amount: deposited });

current_yang_id += 1;
}
}

// Returns an ordered array of the `YangBalance` struct for the total deposited yangs in the Shrine.
// Starts from yang ID 1.
fn get_shrine_deposits(self: @ContractState) -> Span<YangBalance> {
let mut yang_balances: Array<YangBalance> = ArrayTrait::new();

let mut current_yang_id: u32 = START_YANG_IDX;
let loop_end: u32 = self.yangs_count.read() + START_YANG_IDX;
loop {
if current_yang_id == loop_end {
break yang_balances.span();
}

let yang_total: Wad = self.yang_total.read(current_yang_id);
yang_balances.append(YangBalance { yang_id: current_yang_id, amount: yang_total });

current_yang_id += 1;
}
}

// Returns a tuple of:
// 1. the custom threshold (maximum LTV before liquidation)
// 2. the total value of the yangs, at a given interval
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/ISentinel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub trait ISentinel<TContractState> {
fn get_gate_address(self: @TContractState, yang: ContractAddress) -> ContractAddress;
fn get_gate_live(self: @TContractState, yang: ContractAddress) -> bool;
fn get_yang_addresses(self: @TContractState) -> Span<ContractAddress>;
fn get_yang_addresses_count(self: @TContractState) -> u64;
fn get_yang(self: @TContractState, idx: u64) -> ContractAddress;
fn get_yang_addresses_count(self: @TContractState) -> u32;
fn get_yang(self: @TContractState, idx: u32) -> ContractAddress;
fn get_yang_asset_max(self: @TContractState, yang: ContractAddress) -> u128;
fn get_asset_amt_per_yang(self: @TContractState, yang: ContractAddress) -> Wad;
// external
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IShrine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub trait IShrine<TContractState> {
fn get_protocol_owned_troves_debt(self: @TContractState) -> Wad;
fn get_yangs_count(self: @TContractState) -> u32;
fn get_deposit(self: @TContractState, yang: ContractAddress, trove_id: u64) -> Wad;
fn get_trove_deposits(self: @TContractState, trove_id: u64) -> Span<YangBalance>;
fn get_shrine_deposits(self: @TContractState) -> Span<YangBalance>;
fn get_budget(self: @TContractState) -> SignedWad;
fn get_yang_price(self: @TContractState, yang: ContractAddress, interval: u64) -> (Wad, Wad);
fn get_yang_rate(self: @TContractState, yang: ContractAddress, rate_era: u64) -> Ray;
Expand Down
8 changes: 8 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ pub mod utils {
pub mod exp;
pub mod math;
pub mod reentrancy_guard;
pub mod upgradeable;
}

mod periphery {
pub mod frontend_data_provider;
pub mod interfaces;
pub mod roles;
pub mod types;
}

// mock used for local devnet deployment
Expand Down
Loading
Loading