Skip to content

Commit

Permalink
Rename variables to make them more consistent and understandable
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell authored and Jake Hartnell committed Mar 26, 2024
1 parent 0db6203 commit 71832ce
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 79 deletions.
8 changes: 4 additions & 4 deletions contracts/external/cw-abc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ Example Instantiation message:
"min": "10000000",
"max": "100000000000"
},
"initial_allocation_ratio": "0.25",
"exit_tax": "0.10"
"entry_fee": "0.25",
"exit_fee": "0.10"
},
"open": {
"exit_tax": "0.01",
"allocation_percentage": "0.01"
"exit_fee": "0.01",
"entry_fee": "0.01"
},
"closed": {}
},
Expand Down
40 changes: 20 additions & 20 deletions contracts/external/cw-abc/schema/cw-abc.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@
"type": "object",
"required": [
"contribution_limits",
"exit_tax",
"initial_allocation_ratio",
"exit_fee",
"entry_fee",
"initial_raise"
],
"properties": {
Expand All @@ -246,15 +246,15 @@
}
]
},
"exit_tax": {
"exit_fee": {
"description": "Exit tax for the hatch phase",
"allOf": [
{
"$ref": "#/definitions/Decimal"
}
]
},
"initial_allocation_ratio": {
"entry_fee": {
"description": "The initial allocation (θ), percentage of the initial raise allocated to the Funding Pool",
"allOf": [
{
Expand Down Expand Up @@ -331,19 +331,19 @@
"OpenConfig": {
"type": "object",
"required": [
"allocation_percentage",
"exit_tax"
"entry_fee",
"exit_fee"
],
"properties": {
"allocation_percentage": {
"entry_fee": {
"description": "Percentage of capital put into the Reserve Pool during the Open phase when buying from the curve.",
"allOf": [
{
"$ref": "#/definitions/Decimal"
}
]
},
"exit_tax": {
"exit_fee": {
"description": "Exit taxation ratio",
"allOf": [
{
Expand Down Expand Up @@ -838,7 +838,7 @@
}
]
},
"exit_tax": {
"exit_fee": {
"anyOf": [
{
"$ref": "#/definitions/Decimal"
Expand All @@ -848,7 +848,7 @@
}
]
},
"initial_allocation_ratio": {
"entry_fee": {
"anyOf": [
{
"$ref": "#/definitions/Decimal"
Expand Down Expand Up @@ -884,7 +884,7 @@
"open": {
"type": "object",
"properties": {
"allocation_percentage": {
"entry_fee": {
"anyOf": [
{
"$ref": "#/definitions/Decimal"
Expand All @@ -894,7 +894,7 @@
}
]
},
"exit_tax": {
"exit_fee": {
"anyOf": [
{
"$ref": "#/definitions/Decimal"
Expand Down Expand Up @@ -1396,8 +1396,8 @@
"type": "object",
"required": [
"contribution_limits",
"exit_tax",
"initial_allocation_ratio",
"exit_fee",
"entry_fee",
"initial_raise"
],
"properties": {
Expand All @@ -1409,15 +1409,15 @@
}
]
},
"exit_tax": {
"exit_fee": {
"description": "Exit tax for the hatch phase",
"allOf": [
{
"$ref": "#/definitions/Decimal"
}
]
},
"initial_allocation_ratio": {
"entry_fee": {
"description": "The initial allocation (θ), percentage of the initial raise allocated to the Funding Pool",
"allOf": [
{
Expand Down Expand Up @@ -1456,19 +1456,19 @@
"OpenConfig": {
"type": "object",
"required": [
"allocation_percentage",
"exit_tax"
"entry_fee",
"exit_fee"
],
"properties": {
"allocation_percentage": {
"entry_fee": {
"description": "Percentage of capital put into the Reserve Pool during the Open phase when buying from the curve.",
"allOf": [
{
"$ref": "#/definitions/Decimal"
}
]
},
"exit_tax": {
"exit_fee": {
"description": "Exit taxation ratio",
"allOf": [
{
Expand Down
24 changes: 12 additions & 12 deletions contracts/external/cw-abc/src/abc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub struct HatchConfig {
/// The initial raise range (min, max) in the reserve token
pub initial_raise: MinMax,
/// The initial allocation (θ), percentage of the initial raise allocated to the Funding Pool
pub initial_allocation_ratio: StdDecimal,
pub entry_fee: StdDecimal,
/// Exit tax for the hatch phase
pub exit_tax: StdDecimal,
pub exit_fee: StdDecimal,
}

impl HatchConfig {
Expand All @@ -65,14 +65,14 @@ impl HatchConfig {
);

ensure!(
self.initial_allocation_ratio <= StdDecimal::percent(100u64),
self.entry_fee <= StdDecimal::percent(100u64),
ContractError::HatchPhaseConfigError(
"Initial allocation percentage must be between 0 and 100.".to_string()
)
);

ensure!(
self.exit_tax <= StdDecimal::percent(100u64),
self.exit_fee <= StdDecimal::percent(100u64),
ContractError::HatchPhaseConfigError(
"Exit taxation percentage must be less than or equal to 100.".to_string()
)
Expand All @@ -86,23 +86,23 @@ impl HatchConfig {
pub struct OpenConfig {
/// Percentage of capital put into the Reserve Pool during the Open phase
/// when buying from the curve.
pub allocation_percentage: StdDecimal,
pub entry_fee: StdDecimal,
/// Exit taxation ratio
pub exit_tax: StdDecimal,
pub exit_fee: StdDecimal,
}

impl OpenConfig {
/// Validate the open config
pub fn validate(&self) -> Result<(), ContractError> {
ensure!(
self.allocation_percentage <= StdDecimal::percent(100u64),
self.entry_fee <= StdDecimal::percent(100u64),
ContractError::OpenPhaseConfigError(
"Reserve percentage must be between 0 and 100.".to_string()
)
);

ensure!(
self.exit_tax <= StdDecimal::percent(100u64),
self.exit_fee <= StdDecimal::percent(100u64),
ContractError::OpenPhaseConfigError(
"Exit taxation percentage must be between 0 and 100.".to_string()
)
Expand Down Expand Up @@ -243,12 +243,12 @@ mod unit_tests {
min: Uint128::one(),
max: Uint128::from(1000000u128),
},
initial_allocation_ratio: StdDecimal::percent(10u64),
exit_tax: StdDecimal::percent(10u64),
entry_fee: StdDecimal::percent(10u64),
exit_fee: StdDecimal::percent(10u64),
},
open: OpenConfig {
allocation_percentage: StdDecimal::percent(10u64),
exit_tax: StdDecimal::percent(10u64),
entry_fee: StdDecimal::percent(10u64),
exit_fee: StdDecimal::percent(10u64),
},
closed: ClosedConfig {},
};
Expand Down
44 changes: 21 additions & 23 deletions contracts/external/cw-abc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ pub fn execute_buy(deps: DepsMut<TokenFactoryQuery>, _env: Env, info: MessageInf
PHASE.save(deps.storage, &phase)?;
}

calculate_reserved_and_funded(payment, hatch_config.initial_allocation_ratio)
}
CommonsPhase::Open => {
calculate_reserved_and_funded(payment, phase_config.open.allocation_percentage)
calculate_reserved_and_funded(payment, hatch_config.entry_fee)
}
CommonsPhase::Open => calculate_reserved_and_funded(payment, phase_config.open.entry_fee),
CommonsPhase::Closed => {
return Err(ContractError::CommonsClosed {});
}
Expand Down Expand Up @@ -202,7 +200,7 @@ pub fn execute_sell(deps: DepsMut<TokenFactoryQuery>, _env: Env, info: MessageIn
.map_err(StdError::overflow)?;

// Calculate the exit tax
let taxed_amount = calculate_exit_tax(deps.storage, released_reserve)?;
let taxed_amount = calculate_exit_fee(deps.storage, released_reserve)?;

// Update the curve state
curve_state.reserve = new_reserve;
Expand Down Expand Up @@ -248,26 +246,26 @@ pub fn execute_sell(deps: DepsMut<TokenFactoryQuery>, _env: Env, info: MessageIn
}

/// Calculate the exit taxation for the sell amount based on the phase
fn calculate_exit_tax(storage: &dyn Storage, sell_amount: Uint128) -> CwAbcResult<Uint128> {
fn calculate_exit_fee(storage: &dyn Storage, sell_amount: Uint128) -> CwAbcResult<Uint128> {
// Load the phase config and phase
let phase = PHASE.load(storage)?;
let phase_config = PHASE_CONFIG.load(storage)?;

// Calculate the exit tax based on the phase
let exit_tax = match &phase {
CommonsPhase::Hatch => phase_config.hatch.exit_tax,
CommonsPhase::Open => phase_config.open.exit_tax,
let exit_fee = match &phase {
CommonsPhase::Hatch => phase_config.hatch.exit_fee,
CommonsPhase::Open => phase_config.open.exit_fee,
CommonsPhase::Closed => return Ok(Uint128::zero()),
};

// TODO more normal check?
debug_assert!(
exit_tax <= StdDecimal::percent(100),
exit_fee <= StdDecimal::percent(100),
"Exit tax must be <= 100%"
);

// This won't ever overflow because it's checked
let taxed_amount = sell_amount * exit_tax;
let taxed_amount = sell_amount * exit_fee;
Ok(taxed_amount)
}

Expand Down Expand Up @@ -386,9 +384,9 @@ pub fn update_phase_config(

match update_phase_config_msg {
UpdatePhaseConfigMsg::Hatch {
exit_tax,
exit_fee,
initial_raise,
initial_allocation_ratio,
entry_fee,
contribution_limits,
} => {
// Check we are in the hatch phase
Expand All @@ -398,14 +396,14 @@ pub fn update_phase_config(
if let Some(contribution_limits) = contribution_limits {
phase_config.hatch.contribution_limits = contribution_limits;
}
if let Some(exit_tax) = exit_tax {
phase_config.hatch.exit_tax = exit_tax;
if let Some(exit_fee) = exit_fee {
phase_config.hatch.exit_fee = exit_fee;
}
if let Some(initial_raise) = initial_raise {
phase_config.hatch.initial_raise = initial_raise;
}
if let Some(initial_allocation_ratio) = initial_allocation_ratio {
phase_config.hatch.initial_allocation_ratio = initial_allocation_ratio;
if let Some(entry_fee) = entry_fee {
phase_config.hatch.entry_fee = entry_fee;
}

// Validate config
Expand All @@ -415,18 +413,18 @@ pub fn update_phase_config(
Ok(Response::new().add_attribute("action", "update_hatch_phase_config"))
}
UpdatePhaseConfigMsg::Open {
exit_tax,
allocation_percentage,
exit_fee,
entry_fee,
} => {
// Check we are in the open phase
phase.expect_open()?;

// Update the hatch config if new values are provided
if let Some(allocation_percentage) = allocation_percentage {
phase_config.open.allocation_percentage = allocation_percentage;
if let Some(entry_fee) = entry_fee {
phase_config.open.entry_fee = entry_fee;
}
if let Some(exit_tax) = exit_tax {
phase_config.hatch.exit_tax = exit_tax;
if let Some(exit_fee) = exit_fee {
phase_config.hatch.exit_fee = exit_fee;
}

// Validate config
Expand Down
8 changes: 4 additions & 4 deletions contracts/external/cw-abc/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub enum UpdatePhaseConfigMsg {
/// Update the hatch phase configuration
Hatch {
contribution_limits: Option<MinMax>,
exit_tax: Option<StdDecimal>,
// TODO what is the minimum used for?
initial_raise: Option<MinMax>,
initial_allocation_ratio: Option<StdDecimal>,
entry_fee: Option<StdDecimal>,
exit_fee: Option<StdDecimal>,
},
/// Update the open phase configuration.
Open {
exit_tax: Option<StdDecimal>,
allocation_percentage: Option<StdDecimal>,
exit_fee: Option<StdDecimal>,
entry_fee: Option<StdDecimal>,
},
/// Update the closed phase configuration.
/// TODO Set the curve type to be used on close?
Expand Down
16 changes: 8 additions & 8 deletions contracts/external/cw-abc/src/test_tube/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ fn test_happy_path() {
min: Uint128::from(10u128),
max: Uint128::from(1000000u128),
},
initial_allocation_ratio: Decimal::percent(10u64),
exit_tax: Decimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
open: OpenConfig {
allocation_percentage: Decimal::percent(10u64),
exit_tax: Decimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
closed: ClosedConfig {},
}
Expand Down Expand Up @@ -302,12 +302,12 @@ fn test_allowlist() {
min: Uint128::from(10u128),
max: Uint128::from(1000000u128),
},
initial_allocation_ratio: Decimal::percent(10u64),
exit_tax: Decimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
open: OpenConfig {
allocation_percentage: Decimal::percent(10u64),
exit_tax: Decimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
closed: ClosedConfig {},
},
Expand Down
Loading

0 comments on commit 71832ce

Please sign in to comment.