Skip to content
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

apy #945

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open

apy #945

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
79f5f40
init
rouzwelt Oct 16, 2024
22c3e03
Revert "init"
rouzwelt Oct 17, 2024
4fdb5a6
apy logic
rouzwelt Oct 18, 2024
c61d43b
ui
rouzwelt Oct 18, 2024
6edab3b
update
rouzwelt Oct 18, 2024
7968399
apply requested changes
rouzwelt Oct 19, 2024
6b27e3e
Update apy.rs
rouzwelt Oct 20, 2024
04155e8
Update apy.rs
rouzwelt Oct 20, 2024
621a180
Update apy.rs
rouzwelt Oct 20, 2024
c2804e4
Update apy.rs
rouzwelt Oct 20, 2024
4c69002
Update apy.rs
rouzwelt Oct 20, 2024
b88b0c2
Update apy.rs
rouzwelt Oct 20, 2024
59a2a39
Update apy.rs
rouzwelt Oct 20, 2024
f509d86
Update apy.rs
rouzwelt Oct 20, 2024
06cd19a
Update apy.rs
rouzwelt Oct 20, 2024
8fe210d
Update apy.rs
rouzwelt Oct 20, 2024
e5cae7d
Update apy.rs
rouzwelt Oct 20, 2024
931bf38
Update apy.rs
rouzwelt Oct 20, 2024
78abfc7
Update apy.rs
rouzwelt Oct 21, 2024
36a34f7
fix pick denomination
rouzwelt Oct 21, 2024
d4883d7
update [skip ci]
rouzwelt Oct 21, 2024
b659f5b
update
rouzwelt Oct 22, 2024
cdadbf5
Merge branch 'main' into 2024-10-16-apy
rouzwelt Oct 22, 2024
31f54d7
apply requested changes
rouzwelt Oct 23, 2024
54d21b3
update
rouzwelt Oct 23, 2024
5b65481
Update number.ts
rouzwelt Oct 23, 2024
51b5f86
Update number.ts
rouzwelt Oct 23, 2024
6aa1bcc
update
rouzwelt Oct 23, 2024
ad43d24
Merge branch 'main' into 2024-10-16-apy
thedavidmeister Oct 23, 2024
c5adc1c
apply requested changes
rouzwelt Oct 27, 2024
b32e441
Merge branch 'main' into 2024-10-16-apy
rouzwelt Oct 27, 2024
249f21f
Merge branch '2024-10-30-bigint-math-18' into 2024-10-16-apy
rouzwelt Nov 14, 2024
9eeb517
Delete error.rs
rouzwelt Nov 14, 2024
32df562
update
rouzwelt Nov 18, 2024
2588b55
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 18, 2024
dccd4ea
update
rouzwelt Nov 18, 2024
89932d5
Update vol.rs
rouzwelt Nov 18, 2024
f9cad84
Update impls.rs
rouzwelt Nov 18, 2024
0f1e192
Update OrderVaultsVolTable.svelte
rouzwelt Nov 18, 2024
b5c585b
Update OrderVaultsVolTable.test.ts
rouzwelt Nov 18, 2024
7a8659a
Update OrderVaultsVolTable.test.ts
rouzwelt Nov 18, 2024
2f7c4bd
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 21, 2024
b3f1193
update
rouzwelt Nov 21, 2024
b1b7d6f
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 21, 2024
f64c175
update
rouzwelt Nov 21, 2024
27a1b97
fix minor issues
rouzwelt Nov 21, 2024
0b8ae38
Update order_performance.rs
rouzwelt Nov 22, 2024
c285f5d
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 22, 2024
a3b5ed7
update
rouzwelt Nov 22, 2024
e2b0c92
Merge branch 'main' into 2024-10-16-apy
thedavidmeister Nov 22, 2024
6f9eb78
apply requested changes
rouzwelt Nov 22, 2024
5a17414
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 22, 2024
050ea35
fix
rouzwelt Nov 22, 2024
2bd4b59
lint
rouzwelt Nov 22, 2024
77cb6fc
Merge branch 'main' into 2024-10-16-apy
rouzwelt Nov 29, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/subgraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ serde = { workspace = true }
serde_json = { workspace = true }
alloy = { workspace = true, features = ["rand"] }
rain_orderbook_bindings = { workspace = true }
rain_orderbook_math = { workspace = true }
chrono = { workspace = true }
url = { workspace = true, features = ["serde"] }
cynic-introspection = "3.7.3"
once_cell = { workspace = true }
futures = "0.3.17"

[target.'cfg(target_family = "wasm")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/subgraph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mod cynic_client;
mod multi_orderbook_client;
mod orderbook_client;
mod pagination;
pub mod performance;
pub mod types;
pub mod utils;
pub mod validate;
mod vault_balance_changes_query;
pub mod vol;

#[cynic::schema("orderbook")]
pub mod schema {}
Expand Down
28 changes: 26 additions & 2 deletions crates/subgraph/src/orderbook_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::cynic_client::{CynicClient, CynicClientError};
use crate::pagination::{PaginationArgs, PaginationClient, PaginationClientError};
use crate::performance::vol::{get_vaults_vol, VaultVolume};
use crate::performance::OrderPerformance;
use crate::types::common::*;
use crate::types::order::{
BatchOrderDetailQuery, BatchOrderDetailQueryVariables, OrderDetailQuery, OrderIdList,
Expand All @@ -8,11 +10,10 @@ use crate::types::order::{
use crate::types::order_trade::{OrderTradeDetailQuery, OrderTradesListQuery};
use crate::types::vault::{VaultDetailQuery, VaultsListQuery};
use crate::vault_balance_changes_query::VaultBalanceChangesListPageQueryClient;
use crate::vol::{get_vaults_vol, VaultVolume};
use cynic::Id;
use reqwest::Url;
use std::num::ParseIntError;
use thiserror::Error;

#[cfg(target_family = "wasm")]
use wasm_bindgen::{JsError, JsValue};

Expand All @@ -30,6 +31,10 @@ pub enum OrderbookSubgraphClientError {
ParseError(#[from] alloy::primitives::ruint::ParseError),
#[error(transparent)]
UrlParseError(#[from] url::ParseError),
#[error(transparent)]
PerformanceError(#[from] crate::performance::PerformanceError),
#[error(transparent)]
ParseIntError(#[from] ParseIntError),
#[cfg(target_family = "wasm")]
#[error(transparent)]
SerdeWasmBindgenError(#[from] serde_wasm_bindgen::Error),
Expand Down Expand Up @@ -231,6 +236,25 @@ impl OrderbookSubgraphClient {
Ok(get_vaults_vol(&trades)?)
}

/// Fetches order data and measures an order's detailed performance (apy and vol)
pub async fn order_performance(
&self,
order_id: cynic::Id,
start_timestamp: Option<u64>,
end_timestamp: Option<u64>,
) -> Result<OrderPerformance, OrderbookSubgraphClientError> {
let order = self.order_detail(order_id.clone()).await?;
let trades = self
.order_trades_list_all(order_id, start_timestamp, end_timestamp)
.await?;
Ok(OrderPerformance::measure(
&order,
&trades,
start_timestamp,
end_timestamp,
)?)
}

/// Fetch single vault
pub async fn vault_detail(&self, id: Id) -> Result<Vault, OrderbookSubgraphClientError> {
let data = self
Expand Down
Loading
Loading