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

wants to merge 55 commits into from

Conversation

rouzwelt
Copy link
Contributor

@rouzwelt rouzwelt commented Oct 16, 2024

Motivation

resolves #908

Solution

  • - logic
  • - UI

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs

@rouzwelt rouzwelt added Tauri Tauri app ui/ux UI/UX updates new feature Added a new feature rust Related to rust crates subgraph Related to subgraph labels Oct 16, 2024
@rouzwelt rouzwelt self-assigned this Oct 16, 2024
@rouzwelt rouzwelt changed the title any apy Oct 18, 2024
@rouzwelt rouzwelt removed the subgraph Related to subgraph label Oct 18, 2024
tauri-app/src/lib/components/tables/OrderAPY.svelte Outdated Show resolved Hide resolved
tauri-app/src/lib/components/charts/APYTimeFilters.svelte Outdated Show resolved Hide resolved
tauri-app/src/lib/components/charts/APYTimeFilters.svelte Outdated Show resolved Hide resolved
tauri-app/src/lib/components/charts/APYTimeFilters.svelte Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/utils/mod.rs Outdated Show resolved Hide resolved
crates/subgraph/src/types/impls.rs Outdated Show resolved Hide resolved
crates/subgraph/src/types/impls.rs Outdated Show resolved Hide resolved
crates/subgraph/src/types/impls.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
@rouzwelt rouzwelt mentioned this pull request Oct 31, 2024
4 tasks
/// Calculates the trade's O/I ratio (inverse)
pub fn inverse_ratio(&self) -> Result<U256, PerformanceError> {
let (input, output) = self.scale_18_io()?;
if output.is_zero() && input.is_zero() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by zero is an error

let (input, output) = self.scale_18_io()?;
if output.is_zero() && input.is_zero() {
Ok(U256::ZERO)
} else if input.is_zero() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by zero is error

}

#[test]
fn test_inverse_ratio() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added if cases in the inverse ratio fn and didn't test them

let (input, output) = self.scale_18_io()?;
if output.is_zero() && input.is_zero() {
Ok(U256::ZERO)
} else if output.is_zero() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by zero is error

/// Calculates the trade's I/O ratio
pub fn ratio(&self) -> Result<U256, PerformanceError> {
let (input, output) = self.scale_18_io()?;
if output.is_zero() && input.is_zero() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by zero is error


#[test]
fn test_ratio() {
let result = get_trade().ratio().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cases in the fn not covered in tests

self.input_vault_balance_change
.vault
.token
.decimals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fallback logic for decimals should be an impl and reused, i can just see someone falling back to 0 somewhere in the app and this falling back to 18 and that being inconsistent across the app, this code duplication on the decimal handling needs to be centralised somewhere in the codebase

pub fn scale_18(&self) -> Result<VaultVolume, PerformanceError> {
let token_decimals: u8 = self
.token
.decimals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as below

* @param valueDecimals - The bigint string value decimals point
* @param decimalPoint - (optional) The number of digits to keep after "." in final result, defaults to valueDecimals
*/
export function bigintStringToPercentage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing tests

export const TIME_DELTA_30_DAYS = TIME_DELTA_24_HOURS * 30;
export const TIME_DELTA_1_YEAR = TIME_DELTA_24_HOURS * 365;

export function nowTimestamp(): number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually with time, because it's non deterministic, we'd have a function that handles times, and then we would pass "now" to it, then a single "now" can be used consistently across upstream scopes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Added a new feature rust Related to rust crates Tauri Tauri app ui/ux UI/UX updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

display net volumes as APYs
2 participants