From 2efeff481723b8d05f193ddde8439e0509b841a3 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Wed, 10 Jan 2024 11:56:54 +0000 Subject: [PATCH] chore: add function to aggregate pool fees --- Cargo.lock | 2 +- packages/white-whale/Cargo.toml | 2 +- packages/white-whale/src/pool_network/pair.rs | 25 ++++++++++++++++++- packages/white-whale/src/pool_network/trio.rs | 23 +++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a133957f..0f89a379 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1652,7 +1652,7 @@ dependencies = [ [[package]] name = "white-whale" -version = "1.1.1" +version = "1.1.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/packages/white-whale/Cargo.toml b/packages/white-whale/Cargo.toml index ff9e7900..6cb2cae6 100644 --- a/packages/white-whale/Cargo.toml +++ b/packages/white-whale/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "white-whale" -version = "1.1.1" +version = "1.1.2" edition.workspace = true authors = ["Kerber0x "] description = "Common White Whale types and utils" diff --git a/packages/white-whale/src/pool_network/pair.rs b/packages/white-whale/src/pool_network/pair.rs index 5ad9562c..b137c6d7 100644 --- a/packages/white-whale/src/pool_network/pair.rs +++ b/packages/white-whale/src/pool_network/pair.rs @@ -1,8 +1,8 @@ -use crate::fee::Fee; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Decimal, StdError, StdResult, Uint128}; use cw20::Cw20ReceiveMsg; +use crate::fee::Fee; use crate::pool_network::asset::{Asset, AssetInfo, PairInfo, PairType}; #[cw_serde] @@ -160,6 +160,29 @@ impl PoolFee { Ok(()) } + + /// aggregates all the fees into a single decimal + pub fn aggregate(&self) -> StdResult { + let total_fee = { + let base_fee = self + .protocol_fee + .share + .checked_add(self.swap_fee.share)? + .checked_add(self.burn_fee.share)?; + + #[cfg(feature = "osmosis")] + { + base_fee.checked_add(self.osmosis_fee.share)? + } + + #[cfg(not(feature = "osmosis"))] + { + base_fee + } + }; + + Ok(total_fee) + } } #[cw_serde] diff --git a/packages/white-whale/src/pool_network/trio.rs b/packages/white-whale/src/pool_network/trio.rs index a6d8b531..e8b24c87 100644 --- a/packages/white-whale/src/pool_network/trio.rs +++ b/packages/white-whale/src/pool_network/trio.rs @@ -176,6 +176,29 @@ impl PoolFee { Ok(()) } + + /// aggregates all the fees into a single decimal + pub fn aggregate(&self) -> StdResult { + let total_fee = { + let base_fee = self + .protocol_fee + .share + .checked_add(self.swap_fee.share)? + .checked_add(self.burn_fee.share)?; + + #[cfg(feature = "osmosis")] + { + base_fee.checked_add(self.osmosis_fee.share)? + } + + #[cfg(not(feature = "osmosis"))] + { + base_fee + } + }; + + Ok(total_fee) + } } #[cw_serde]