Skip to content

Commit

Permalink
refactor: add SimulationResponse and ReverseSimulationResponse to the…
Browse files Browse the repository at this point in the history
… pool_manager package
  • Loading branch information
kerber0x committed Apr 15, 2024
1 parent 62a82ed commit 0d3ac38
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 21 deletions.
62 changes: 54 additions & 8 deletions contracts/liquidity_hub/pool-manager/schema/pool-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -998,22 +1021,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down
31 changes: 27 additions & 4 deletions contracts/liquidity_hub/pool-manager/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,45 @@
]
},
"PoolFee": {
"description": "Fees used by the pools on the pool network",
"description": "Represents the fee structure for transactions within a pool.\n\n# Fields - `protocol_fee`: The fee percentage charged by the protocol on each transaction to support operational and developmental needs. - `swap_fee`: The fee percentage allocated to liquidity providers as a reward for supplying liquidity to the pool, incentivizing participation and ensuring pool health. - `burn_fee`: A fee percentage that is burned on each transaction, helping manage the token economy by reducing supply over time, potentially increasing token value. - `osmosis_fee` (optional): Specific to the Osmosis feature, this fee is charged on each transaction when the Osmosis feature is enabled, supporting specific ecosystem requirements. - `extra_fees`: A vector of custom fees allowing for extensible and adaptable fee structures to meet diverse and evolving needs. Validation ensures that the total of all fees does not exceed 100%, maintaining fairness and avoiding overcharging.\n\n# Features - `osmosis`: Enables the `osmosis_fee` field, integrating specific fee requirements for the Osmosis protocol within the pool's fee structure.",
"type": "object",
"required": [
"burn_fee",
"extra_fees",
"protocol_fee",
"swap_fee"
],
"properties": {
"burn_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage that is burned on each transaction. Burning a portion of the transaction fee helps in reducing the overall token supply.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"extra_fees": {
"description": "A list of custom, additional fees that can be defined for specific use cases or additional functionalities. This vector enables the flexibility to introduce new fees without altering the core fee structure. Total of all fees, including custom ones, is validated to not exceed 100%, ensuring a balanced and fair fee distribution.",
"type": "array",
"items": {
"$ref": "#/definitions/Fee"
}
},
"protocol_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage charged on each transaction for the protocol's benefit.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
},
"swap_fee": {
"$ref": "#/definitions/Fee"
"description": "Fee percentage allocated to liquidity providers on each swap.",
"allOf": [
{
"$ref": "#/definitions/Fee"
}
]
}
},
"additionalProperties": false
Expand Down
30 changes: 25 additions & 5 deletions packages/white-whale-std/src/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use std::fmt;

use crate::{
fee::PoolFee,
pool_network::{
asset::PairType,
factory::NativeTokenDecimalsResponse,
pair::{ReverseSimulationResponse, SimulationResponse},
},
pool_network::{asset::PairType, factory::NativeTokenDecimalsResponse},
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Coin, Decimal, Uint128};
Expand Down Expand Up @@ -246,3 +242,27 @@ pub enum QueryMsg {
#[returns(PairInfo)]
Pair { pair_identifier: String },
}

/// SimulationResponse returns swap simulation response
#[cw_serde]
pub struct SimulationResponse {
pub return_amount: Uint128,
pub spread_amount: Uint128,
pub swap_fee_amount: Uint128,
pub protocol_fee_amount: Uint128,
pub burn_fee_amount: Uint128,
#[cfg(feature = "osmosis")]
pub osmosis_fee_amount: Uint128,
}

/// ReverseSimulationResponse returns reverse swap simulation response
#[cw_serde]
pub struct ReverseSimulationResponse {
pub offer_amount: Uint128,
pub spread_amount: Uint128,
pub swap_fee_amount: Uint128,
pub protocol_fee_amount: Uint128,
pub burn_fee_amount: Uint128,
#[cfg(feature = "osmosis")]
pub osmosis_fee_amount: Uint128,
}

0 comments on commit 0d3ac38

Please sign in to comment.