Skip to content

Commit

Permalink
✨ yield_curve + vrf
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Dec 6, 2023
1 parent d274267 commit 24bb4da
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
125 changes: 124 additions & 1 deletion src/abi.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::{ContractAddress, ClassHash};
use pragma_lib::types::{
DataType, AggregationMode, Currency, Pair, PossibleEntries, Checkpoint, SimpleDataType,
PragmaPricesResponse
PragmaPricesResponse, YieldPoint, FutureKeyStatus, RequestStatus
};

#[starknet::interface]
Expand Down Expand Up @@ -110,3 +110,126 @@ trait ISummaryStatsABI<TContractState> {

fn get_oracle_address(self: @TContractState) -> ContractAddress;
}

#[starknet::interface]
trait IYieldCurveABI<TContractState> {
fn get_yield_points(self: @TContractState, decimals: u32) -> Span<YieldPoint>;
fn get_admin_address(self: @TContractState,) -> ContractAddress;
fn get_oracle_address(self: @TContractState,) -> ContractAddress;
fn get_future_spot_pragma_source_key(self: @TContractState,) -> felt252;
fn get_pair_id(self: @TContractState, idx: u64) -> felt252;
fn get_pair_id_is_active(self: @TContractState, pair_id: felt252) -> bool;
fn get_pair_ids(self: @TContractState,) -> Span<felt252>;
fn get_future_expiry_timestamp(self: @TContractState, pair_id: felt252, idx: u64) -> u64;
fn get_future_expiry_timestamps(self: @TContractState, pair_id: felt252) -> Span<u64>;
fn get_on_key(self: @TContractState, idx: u64) -> felt252;
fn get_on_key_is_active(self: @TContractState, on_key: felt252) -> bool;
fn get_on_keys(self: @TContractState,) -> Span<felt252>;
fn get_future_expiry_timestamp_status(
self: @TContractState, pair_id: felt252, future_expiry_timestamp: u64
) -> FutureKeyStatus;
fn get_future_expiry_timestamp_is_active(
self: @TContractState, pair_id: felt252, future_expiry_timestamp: u64
) -> bool;
fn get_future_expiry_timestamp_expiry(
self: @TContractState, pair_id: felt252, future_expiry_timestamp: u64
) -> u64;

//
// Setters
//

fn set_admin_address(ref self: TContractState, new_address: ContractAddress);
fn set_future_spot_pragma_source_key(ref self: TContractState, new_source_key: felt252);
fn set_oracle_address(ref self: TContractState, oracle_address: ContractAddress);
fn add_pair_id(ref self: TContractState, pair_id: felt252, is_active: bool);
fn set_pair_id_is_active(ref self: TContractState, pair_id: felt252, is_active: bool);
fn add_future_expiry_timestamp(
ref self: TContractState,
pair_id: felt252,
future_expiry_timestamp: u64,
is_active: bool,
expiry_timestamp: u64
);
fn set_future_expiry_timestamp_status(
ref self: TContractState,
pair_id: felt252,
future_expiry_timestamp: u64,
new_future_expiry_timestamp_status: FutureKeyStatus,
);

fn set_future_expiry_timestamp_is_active(
ref self: TContractState,
pair_id: felt252,
future_expiry_timestamp: u64,
new_is_active: bool
);

fn add_on_key(ref self: TContractState, on_key: felt252, is_active: bool);

fn set_on_key_is_active(ref self: TContractState, on_key: felt252, is_active: bool);
}

#[starknet::interface]
trait IRandomness<TContractState> {
fn update_status(
ref self: TContractState,
requestor_address: ContractAddress,
request_id: u64,
new_status: RequestStatus
);
fn request_random(
ref self: TContractState,
seed: u64,
callback_address: ContractAddress,
callback_fee_limit: u128,
publish_delay: u64,
num_words: u64
) -> u64;
fn cancel_random_request(
ref self: TContractState,
request_id: u64,
requestor_address: ContractAddress,
seed: u64,
minimum_block_number: u64,
callback_address: ContractAddress,
callback_fee_limit: u128,
num_words: u64
);
fn submit_random(
ref self: TContractState,
request_id: u64,
requestor_address: ContractAddress,
seed: u64,
minimum_block_number: u64,
callback_address: ContractAddress,
callback_fee_limit: u128,
callback_fee: u128,
random_words: Span<felt252>,
proof: Span<felt252>,
);
fn get_pending_requests(
self: @TContractState, requestor_address: ContractAddress, offset: u64, max_len: u64
) -> Span<felt252>;

fn get_request_status(
self: @TContractState, requestor_address: ContractAddress, request_id: u64
) -> RequestStatus;
fn requestor_current_index(self: @TContractState, requestor_address: ContractAddress) -> u64;
fn get_public_key(self: @TContractState, requestor_address: ContractAddress) -> felt252;
fn get_payment_token(self: @TContractState) -> ContractAddress;
fn set_payment_token(ref self: TContractState, token_contract: ContractAddress);
fn upgrade(ref self: TContractState, impl_hash: ClassHash);
fn refund_operation(ref self: TContractState, caller_address: ContractAddress, request_id: u64);
fn get_total_fees(
self: @TContractState, caller_address: ContractAddress, request_id: u64
) -> u256;
fn get_out_of_gas_requests(
self: @TContractState, requestor_address: ContractAddress,
) -> Span<u64>;
fn withdraw_funds(ref self: TContractState, receiver_address: ContractAddress);
fn get_contract_balance(self: @TContractState) -> u256;
fn compute_premium_fee(self: @TContractState, caller_address: ContractAddress) -> u128;
fn get_admin_address(self: @TContractState,) -> ContractAddress;
fn set_admin_address(ref self: TContractState, new_admin_address: ContractAddress);
}
29 changes: 29 additions & 0 deletions src/types.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
use starknet::{ContractAddress, ClassHash};

#[derive(Serde, Drop, Copy, PartialEq, starknet::Store)]
enum RequestStatus {
UNINITIALIZED: (),
RECEIVED: (),
FULFILLED: (),
CANCELLED: (),
OUT_OF_GAS: (),
REFUNDED: (),
}

#[derive(Serde, Drop, Copy, starknet::Store)]
struct YieldPoint {
expiry_timestamp: u64,
capture_timestamp: u64, // timestamp of data capture
// (1 day for overnight rates and expiration date for futures)
rate: u128, // The calculated yield rate: either overnight rate
// or max(0, ((future/spot) - 1) * (365/days to future expiry))
source: felt252, // An indicator for the source (str_to_felt encode uppercase one of:
// "ON" (overnight rate),
// "FUTURE/SPOT" (future/spot rate),
// "OTHER" (for future additional data sources))
}

#[derive(Serde, Drop, Copy, starknet::Store)]
struct FutureKeyStatus {
is_active: bool,
expiry_timestamp: u64,
}

#[derive(Copy, Drop, Serde, starknet::Store)]
struct BaseEntry {
timestamp: u64,
Expand Down

0 comments on commit 24bb4da

Please sign in to comment.