Skip to content

Commit

Permalink
Merge pull request #1099 from rainlanguage/2024-12-19-apy-fix
Browse files Browse the repository at this point in the history
optional apy property
  • Loading branch information
hardyjosh authored Dec 19, 2024
2 parents 5a51354 + 2b2f18a commit 8f294ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
40 changes: 16 additions & 24 deletions crates/subgraph/src/performance/apy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub struct APYDetails {
pub net_vol: U256,
#[cfg_attr(target_family = "wasm", tsify(type = "string"))]
pub capital: U256,
#[cfg_attr(target_family = "wasm", tsify(type = "string"))]
pub apy: U256,
#[cfg_attr(target_family = "wasm", tsify(type = "string | undefined"))]
pub apy: Option<U256>,
pub is_neg: bool,
}

Expand Down Expand Up @@ -144,26 +144,18 @@ pub fn get_vaults_apy(
};

// this token vault apy
if let Some(apy) = apy {
token_vaults_apy.push(VaultAPY {
id: vol.id.clone(),
token: vol.token.clone(),
apy_details: Some(APYDetails {
start_time: start,
end_time: end,
apy,
is_neg: vol.is_net_vol_negative(),
net_vol: vol.vol_details.net_vol,
capital: starting_capital,
}),
});
} else {
token_vaults_apy.push(VaultAPY {
id: vol.id.clone(),
token: vol.token.clone(),
apy_details: None,
});
}
token_vaults_apy.push(VaultAPY {
id: vol.id.clone(),
token: vol.token.clone(),
apy_details: Some(APYDetails {
start_time: start,
end_time: end,
apy,
is_neg: vol.is_net_vol_negative(),
net_vol: vol.vol_details.net_vol,
capital: starting_capital,
}),
});
}

Ok(token_vaults_apy)
Expand Down Expand Up @@ -218,7 +210,7 @@ mod test {
net_vol: U256::from_str("1000000000000000000").unwrap(),
capital: U256::from_str("5000000000000000000").unwrap(),
// (1/5) / (10000001_end - 1_start / 31_536_00_year)
apy: U256::from_str("630720000000000000").unwrap(),
apy: Some(U256::from_str("630720000000000000").unwrap()),
is_neg: false,
}),
},
Expand All @@ -231,7 +223,7 @@ mod test {
net_vol: U256::from_str("2000000000000000000").unwrap(),
capital: U256::from_str("5000000000000000000").unwrap(),
// (2/5) / ((10000001_end - 1_start) / 31_536_00_year)
apy: U256::from_str("1261440000000000000").unwrap(),
apy: Some(U256::from_str("1261440000000000000").unwrap()),
is_neg: false,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/subgraph/src/performance/order_performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ mod test {
end_time: 10000001,
net_vol: U256::from_str("5000000000000000000").unwrap(),
capital: U256::from_str("5000000000000000000").unwrap(),
apy: U256::from_str("3153600000000000000").unwrap(),
apy: Some(U256::from_str("3153600000000000000").unwrap()),
is_neg: false,
}),
vol_details: VolumeDetails {
Expand All @@ -723,7 +723,7 @@ mod test {
end_time: 10000001,
net_vol: U256::from_str("3000000000000000000").unwrap(),
capital: U256::from_str("5000000000000000000").unwrap(),
apy: U256::from_str("1892160000000000000").unwrap(),
apy: Some(U256::from_str("1892160000000000000").unwrap()),
is_neg: false,
}),
vol_details: VolumeDetails {
Expand Down

0 comments on commit 8f294ad

Please sign in to comment.