Skip to content

Commit

Permalink
chore: add function to aggregate pool fees
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Jan 10, 2024
1 parent ac41765 commit 2efeff4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/white-whale/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "white-whale"
version = "1.1.1"
version = "1.1.2"
edition.workspace = true
authors = ["Kerber0x <[email protected]>"]
description = "Common White Whale types and utils"
Expand Down
25 changes: 24 additions & 1 deletion packages/white-whale/src/pool_network/pair.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -160,6 +160,29 @@ impl PoolFee {

Ok(())
}

/// aggregates all the fees into a single decimal
pub fn aggregate(&self) -> StdResult<Decimal> {
let total_fee = {
let base_fee = self
.protocol_fee
.share
.checked_add(self.swap_fee.share)?
.checked_add(self.burn_fee.share)?;

Check warning on line 171 in packages/white-whale/src/pool_network/pair.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/pair.rs#L165-L171

Added lines #L165 - L171 were not covered by tests

#[cfg(feature = "osmosis")]
{
base_fee.checked_add(self.osmosis_fee.share)?

Check warning on line 175 in packages/white-whale/src/pool_network/pair.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/pair.rs#L175

Added line #L175 was not covered by tests
}

#[cfg(not(feature = "osmosis"))]
{
base_fee

Check warning on line 180 in packages/white-whale/src/pool_network/pair.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/pair.rs#L180

Added line #L180 was not covered by tests
}
};

Ok(total_fee)

Check warning on line 184 in packages/white-whale/src/pool_network/pair.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/pair.rs#L184

Added line #L184 was not covered by tests
}
}

#[cw_serde]
Expand Down
23 changes: 23 additions & 0 deletions packages/white-whale/src/pool_network/trio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ impl PoolFee {

Ok(())
}

/// aggregates all the fees into a single decimal
pub fn aggregate(&self) -> StdResult<Decimal> {
let total_fee = {
let base_fee = self
.protocol_fee
.share
.checked_add(self.swap_fee.share)?
.checked_add(self.burn_fee.share)?;

Check warning on line 187 in packages/white-whale/src/pool_network/trio.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/trio.rs#L181-L187

Added lines #L181 - L187 were not covered by tests

#[cfg(feature = "osmosis")]
{
base_fee.checked_add(self.osmosis_fee.share)?

Check warning on line 191 in packages/white-whale/src/pool_network/trio.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/trio.rs#L191

Added line #L191 was not covered by tests
}

#[cfg(not(feature = "osmosis"))]
{
base_fee

Check warning on line 196 in packages/white-whale/src/pool_network/trio.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/trio.rs#L196

Added line #L196 was not covered by tests
}
};

Ok(total_fee)

Check warning on line 200 in packages/white-whale/src/pool_network/trio.rs

View check run for this annotation

Codecov / codecov/patch

packages/white-whale/src/pool_network/trio.rs#L200

Added line #L200 was not covered by tests
}
}

#[cw_serde]
Expand Down

0 comments on commit 2efeff4

Please sign in to comment.