/
pair_concentrated.rs
162 lines (154 loc) · 5.88 KB
/
pair_concentrated.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Decimal, Decimal256, Uint128, Uint64};
use crate::asset::PairInfo;
use crate::asset::{Asset, AssetInfo};
use crate::observation::OracleObservation;
use crate::pair::{
ConfigResponse, CumulativePricesResponse, FeeShareConfig, PoolResponse,
ReverseSimulationResponse, SimulationResponse,
};
/// This structure holds concentrated pool parameters.
#[cw_serde]
pub struct ConcentratedPoolParams {
/// Amplification coefficient affects trades close to price_scale
pub amp: Decimal,
/// Affects how gradual the curve changes from constant sum to constant product
/// as price moves away from price scale. Low values mean more gradual.
pub gamma: Decimal,
/// The minimum fee, charged when pool is fully balanced
pub mid_fee: Decimal,
/// The maximum fee, charged when pool is imbalanced
pub out_fee: Decimal,
/// Parameter that defines how gradual the fee changes from fee_mid to fee_out
/// based on distance from price_scale.
pub fee_gamma: Decimal,
/// Minimum profit before initiating a new repeg
pub repeg_profit_threshold: Decimal,
/// Minimum amount to change price_scale when repegging.
pub min_price_scale_delta: Decimal,
/// 1 x\[0] = price_scale * x\[1].
pub price_scale: Decimal,
/// Half-time used for calculating the price oracle.
pub ma_half_time: u64,
/// Whether asset balances are tracked over blocks or not.
/// They will not be tracked if the parameter is ignored.
/// It can not be disabled later once enabled.
pub track_asset_balances: Option<bool>,
/// The config for swap fee sharing
pub fee_share: Option<FeeShareConfig>,
}
/// This structure holds concentrated pool parameters which can be changed immediately.
#[cw_serde]
pub struct UpdatePoolParams {
pub mid_fee: Option<Decimal>,
pub out_fee: Option<Decimal>,
pub fee_gamma: Option<Decimal>,
pub repeg_profit_threshold: Option<Decimal>,
pub min_price_scale_delta: Option<Decimal>,
pub ma_half_time: Option<u64>,
}
/// Amp and gamma should be changed gradually. This structure holds all necessary parameters.
#[cw_serde]
pub struct PromoteParams {
pub next_amp: Decimal,
pub next_gamma: Decimal,
pub future_time: u64,
}
/// This enum intended for parameters update.
#[cw_serde]
pub enum ConcentratedPoolUpdateParams {
/// Allows to update fee parameters as well as repeg_profit_threshold, min_price_scale_delta and EMA interval.
Update(UpdatePoolParams),
/// Starts gradual (de/in)crease of Amp or Gamma parameters. Can handle an update of both of them.
Promote(PromoteParams),
/// Stops Amp and Gamma update and stores current values.
StopChangingAmpGamma {},
/// Enable asset balances tracking
EnableAssetBalancesTracking {},
/// Enables the sharing of swap fees with an external party.
EnableFeeShare {
/// The fee shared with the fee_share_address
fee_share_bps: u16,
/// The fee_share_bps is sent to this address on every swap
fee_share_address: String,
},
DisableFeeShare,
}
/// This structure stores a CL pool's configuration.
#[cw_serde]
pub struct ConcentratedPoolConfig {
/// Amplification coefficient affects trades close to price_scale
pub amp: Decimal,
/// Affects how gradual the curve changes from constant sum to constant product
/// as price moves away from price scale. Low values mean more gradual.
pub gamma: Decimal,
/// The minimum fee, charged when pool is fully balanced
pub mid_fee: Decimal,
/// The maximum fee, charged when pool is imbalanced
pub out_fee: Decimal,
/// Parameter that defines how gradual the fee changes from fee_mid to fee_out
/// based on distance from price_scale.
pub fee_gamma: Decimal,
/// Minimum profit before initiating a new repeg
pub repeg_profit_threshold: Decimal,
/// Minimum amount to change price_scale when repegging.
pub min_price_scale_delta: Decimal,
/// 1 x\[0] = price_scale * x\[1].
pub price_scale: Decimal,
/// Half-time used for calculating the price oracle.
pub ma_half_time: u64,
/// Whether asset balances are tracked over blocks or not.
pub track_asset_balances: bool,
/// The config for swap fee sharing
pub fee_share: Option<FeeShareConfig>,
}
/// This structure describes the query messages available in the contract.
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Returns information about a pair
#[returns(PairInfo)]
Pair {},
/// Returns information about a pool
#[returns(PoolResponse)]
Pool {},
/// Returns contract configuration
#[returns(ConfigResponse)]
Config {},
/// Returns information about the share of the pool in a vector that contains objects of type [`Asset`].
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
/// Returns information about a swap simulation
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
/// Returns information about a reverse swap simulation
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
/// Returns information about the cumulative prices
#[returns(CumulativePricesResponse)]
CumulativePrices {},
/// Returns current D invariant
#[returns(Decimal256)]
ComputeD {},
/// Query LP token virtual price
#[returns(Decimal256)]
LpPrice {},
/// Returns the balance of the specified asset that was in the pool just preceding the moment
/// of the specified block height creation.
#[returns(Option<Uint128>)]
AssetBalanceAt {
asset_info: AssetInfo,
block_height: Uint64,
},
/// Query price from observations
#[returns(OracleObservation)]
Observe { seconds_ago: u64 },
}
#[cw_serde]
pub struct MigrateMsg {}