Skip to content

Commit

Permalink
Update apy.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Oct 20, 2024
1 parent 06cd19a commit 8fe210d
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions crates/subgraph/src/apy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn get_pairs_ratio(order_apy: &OrderAPY, trades: &[Trade]) -> HashMap<TokenPair,
.and_then(|latest_trade| {
// convert input and output amounts to 18 decimals point
// and then calculate the pair ratio
let input_amount = to_18_decimals(
to_18_decimals(
ParseUnits::U256(
U256::from_str(&latest_trade.input_vault_balance_change.amount.0)
.unwrap(),
Expand All @@ -393,42 +393,42 @@ fn get_pairs_ratio(order_apy: &OrderAPY, trades: &[Trade]) -> HashMap<TokenPair,
.map(|v| v.0.as_str())
.unwrap_or("18"),
)
.ok();
let output_amount = to_18_decimals(
ParseUnits::U256(
U256::from_str(
&latest_trade.output_vault_balance_change.amount.0[1..],
)
.unwrap(),
),
latest_trade
.output_vault_balance_change
.vault
.token
.decimals
.as_ref()
.map(|v| v.0.as_str())
.unwrap_or("18"),
.ok()
.zip(
to_18_decimals(
ParseUnits::U256(
U256::from_str(
&latest_trade.output_vault_balance_change.amount.0[1..],
)
.unwrap(),
),
latest_trade
.output_vault_balance_change
.vault
.token
.decimals
.as_ref()
.map(|v| v.0.as_str())
.unwrap_or("18"),
)
.ok(),
)
.ok();
input_amount
.zip(output_amount)
.map(|(input_amount, output_amount)| {
[
// io ratio
input_amount
.get_signed()
.saturating_mul(one())
.checked_div(output_amount.get_signed())
.unwrap_or(I256::MAX),
// oi ratio
output_amount
.get_signed()
.saturating_mul(one())
.checked_div(input_amount.get_signed())
.unwrap_or(I256::MAX),
]
})
.map(|(input_amount, output_amount)| {
[
// io ratio
input_amount
.get_signed()
.saturating_mul(one())
.checked_div(output_amount.get_signed())
.unwrap_or(I256::MAX),
// oi ratio
output_amount
.get_signed()
.saturating_mul(one())
.checked_div(input_amount.get_signed())
.unwrap_or(I256::MAX),
]
})
});

// io
Expand Down

0 comments on commit 8fe210d

Please sign in to comment.