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 31 commits into
base: main
Choose a base branch
from
Open

apy #945

wants to merge 31 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
Copy link
Contributor

@thedavidmeister thedavidmeister left a comment

Choose a reason for hiding this comment

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

missing screenshots on the PR

@rouzwelt
Copy link
Contributor Author

IMG_20241022_200842_688.jpg

IMG_20241022_200849_635.jpg

crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
mod order_id;
mod slice_list;

pub use order_id::*;
pub use slice_list::*;

pub const DAY: u64 = 60 * 60 * 24;
Copy link
Contributor

Choose a reason for hiding this comment

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

using u64 for times is kinda dangerous because it's really easy for someone to mistake whether it is seconds, millis, nanos, etc.

why not just use the time functionality in rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used rust chrono::TimeDelta

import { formatUnits } from 'viem';
import OrderApy from './OrderAPY.svelte';

function formatApyToPercentage(value: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have an ad hoc function for this instead of a standard way to format numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to a relevant place and made it to be more general, so can be used elsewhere when there is a nee to convert a bigint to a percentage

@rouzwelt
Copy link
Contributor Author

@thedavidmeister btw can show each individual token vault apy in its own denomination ofc, in a sep table/chart if that's desirable, apart from the order's whole APY

crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/utils/mod.rs Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
crates/subgraph/src/apy.rs Outdated Show resolved Hide resolved
}

/// Returns annual rate as 18 point decimals as I256
pub fn annual_rate(start: u64, end: u64) -> I256 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this function just take two 18 decimal values and calculate the rate?

the way it is now, it complects a bunch of stuff

  • converting u64 to i256
  • rescaling decimal 0 to decimal 18
  • ad hoc inlined 18 decimal devision

Ok(self
.input_as_18_decimals()?
.get_absolute()
.saturating_mul(one_18().get_absolute())
Copy link
Contributor

Choose a reason for hiding this comment

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

same as below

pub fn inverse_ratio(&self) -> Result<U256, ParseNumberError> {
Ok(
TryInto::<U256>::try_into(self.output_as_18_decimals()?.get_signed().saturating_neg())?
.saturating_mul(one_18().get_absolute())
Copy link
Contributor

Choose a reason for hiding this comment

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

same as below

}

/// Converts this trade's output to 18 point decimals in U256/I256
pub fn output_as_18_decimals(&self) -> Result<ParseUnits, ParseNumberError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic basically duplicates the input one

.and_then(|amount| {
to_18_decimals(
ParseUnits::U256(amount),
vault_balance_change
Copy link
Contributor

Choose a reason for hiding this comment

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

not using impl

(!starting_capital.is_zero())
.then_some(
vol.net_vol
.saturating_mul(one_18().get_signed())
Copy link
Contributor

Choose a reason for hiding this comment

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

inline rescaling

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