Skip to content

Commit

Permalink
fix clippy warnings, run make build
Browse files Browse the repository at this point in the history
  • Loading branch information
foxpy committed Mar 3, 2023
1 parent abfd583 commit 310544d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 58 deletions.
2 changes: 1 addition & 1 deletion contracts/auction/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"type": "string"
},
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"CallbackMsg": {
Expand Down
14 changes: 8 additions & 6 deletions contracts/lockdrop/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@
"type": "string"
},
"Asset": {
"title": "Description",
"description": "This enum describes a Terra asset (native or CW20).",
"type": "object",
"required": [
Expand All @@ -387,10 +386,11 @@
}
]
}
}
},
"additionalProperties": false
},
"AssetInfo": {
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"terra...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"stake...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"oneOf": [
{
"description": "Non-native Token",
Expand All @@ -408,7 +408,8 @@
"contract_addr": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -429,15 +430,16 @@
"denom": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>",
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"CallbackMsg": {
Expand Down
8 changes: 5 additions & 3 deletions contracts/lockdrop/schema/lock_up_info_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"type": "string"
},
"AssetInfo": {
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"terra...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"stake...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"oneOf": [
{
"description": "Non-native Token",
Expand All @@ -142,7 +142,8 @@
"contract_addr": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -163,7 +164,8 @@
"denom": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
8 changes: 5 additions & 3 deletions contracts/lockdrop/schema/pool_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"type": "string"
},
"AssetInfo": {
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"terra...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"stake...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"oneOf": [
{
"description": "Non-native Token",
Expand All @@ -92,7 +92,8 @@
"contract_addr": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -113,7 +114,8 @@
"denom": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
8 changes: 5 additions & 3 deletions contracts/lockdrop/schema/user_info_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"type": "string"
},
"AssetInfo": {
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"terra...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"description": "This enum describes available Token types. ## Examples ``` # use cosmwasm_std::Addr; # use astroport::asset::AssetInfo::{NativeToken, Token}; Token { contract_addr: Addr::unchecked(\"stake...\") }; NativeToken { denom: String::from(\"uluna\") }; ```",
"oneOf": [
{
"description": "Non-native Token",
Expand All @@ -77,7 +77,8 @@
"contract_addr": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -98,7 +99,8 @@
"denom": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
74 changes: 35 additions & 39 deletions contracts/lockdrop/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,39 +1093,36 @@ pub fn handle_increase_lockup(

let lockup_key = (&terraswap_lp_token, &user_address, duration);

let lockup_info = match LOCKUP_INFO.compatible_may_load(
deps.as_ref(),
lockup_key.clone(),
&config.generator,
)? {
Some(mut li) => {
li.lp_units_locked = li.lp_units_locked.checked_add(amount)?;
li
}
None => {
if config.max_positions_per_user == user_info.lockup_positions_index {
return Err(StdError::generic_err(format!(
"Users can only have max {} lockup positions",
config.max_positions_per_user
)));
let lockup_info =
match LOCKUP_INFO.compatible_may_load(deps.as_ref(), lockup_key, &config.generator)? {
Some(mut li) => {
li.lp_units_locked = li.lp_units_locked.checked_add(amount)?;
li
}
// Update number of lockup positions the user is having
user_info.lockup_positions_index += 1;

LockupInfoV2 {
lp_units_locked: amount,
astroport_lp_transferred: None,
astro_rewards: Uint128::zero(),
unlock_timestamp: config.init_timestamp
+ config.deposit_window
+ config.withdrawal_window
+ (duration * SECONDS_PER_WEEK),
generator_astro_debt: Uint128::zero(),
generator_proxy_debt: Default::default(),
withdrawal_flag: false,
None => {
if config.max_positions_per_user == user_info.lockup_positions_index {
return Err(StdError::generic_err(format!(
"Users can only have max {} lockup positions",
config.max_positions_per_user
)));
}
// Update number of lockup positions the user is having
user_info.lockup_positions_index += 1;

LockupInfoV2 {
lp_units_locked: amount,
astroport_lp_transferred: None,
astro_rewards: Uint128::zero(),
unlock_timestamp: config.init_timestamp
+ config.deposit_window
+ config.withdrawal_window
+ (duration * SECONDS_PER_WEEK),
generator_astro_debt: Uint128::zero(),
generator_proxy_debt: Default::default(),
withdrawal_flag: false,
}
}
}
};
};

// SAVE UPDATED STATE
LOCKUP_INFO.save(deps.storage, lockup_key, &lockup_info)?;
Expand Down Expand Up @@ -1178,7 +1175,7 @@ pub fn handle_withdraw_from_lockup(
let user_address = info.sender;
let lockup_key = (&terraswap_lp_token, &user_address, duration);
let mut lockup_info =
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key.clone(), &config.generator)?;
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key, &config.generator)?;

// CHECK :: Has user already withdrawn LP tokens once post the deposit window closure state
if lockup_info.withdrawal_flag {
Expand Down Expand Up @@ -1394,8 +1391,7 @@ pub fn handle_claim_rewards_and_unlock_for_lockup(

// Check is there lockup or not ?
let lockup_key = (&terraswap_lp_token, &user_address, duration);
let lockup_info =
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key.clone(), &config.generator)?;
let lockup_info = LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key, &config.generator)?;

// CHECK :: Can the Lockup position be unlocked or not ?
if withdraw_lp_stake && env.block.time.seconds() < lockup_info.unlock_timestamp {
Expand Down Expand Up @@ -1726,7 +1722,7 @@ pub fn callback_withdraw_user_rewards_for_lockup_optional_withdraw(
let mut pool_info = ASSET_POOLS.load(deps.storage, &terraswap_lp_token)?;
let lockup_key = (&terraswap_lp_token, &user_address, duration);
let mut lockup_info =
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key.clone(), &config.generator)?;
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key, &config.generator)?;

let mut user_info = USER_INFO
.may_load(deps.storage, &user_address)?
Expand Down Expand Up @@ -2002,7 +1998,7 @@ pub fn callback_deposit_liquidity_in_astroport(
contract_addr: astroport_pool.to_string(),
funds: coins,
msg: to_binary(&astroport::pair::ExecuteMsg::ProvideLiquidity {
assets: assets.clone().try_into().unwrap(),
assets: assets.clone(),
slippage_tolerance,
auto_stake: None,
receiver: None,
Expand Down Expand Up @@ -2080,7 +2076,7 @@ fn callback_distribute_asset_reward(
let mut user_reward = Uint128::zero();
// get only lockups that have not yet been withdrawn
let lockup_info_opt = LOCKUP_INFO
.compatible_may_load(deps.as_ref(), lockup_key.clone(), &config.generator)?
.compatible_may_load(deps.as_ref(), lockup_key, &config.generator)?
.filter(|lock_info| lock_info.astroport_lp_transferred.is_none());
if let Some(lockup_info) = lockup_info_opt {
let user_index_lp_path = USERS_ASSET_REWARD_INDEX.key(lockup_key);
Expand Down Expand Up @@ -2396,7 +2392,7 @@ pub fn query_pending_asset_reward(
let lockup_key = (&terraswap_lp_token, &user_address, duration);

let lockup_info_opt = LOCKUP_INFO
.compatible_may_load(deps, lockup_key.clone(), &config.generator)?
.compatible_may_load(deps, lockup_key, &config.generator)?
.filter(|lock_info| lock_info.astroport_lp_transferred.is_none());

let mut user_reward = Uint128::zero();
Expand Down Expand Up @@ -2595,7 +2591,7 @@ fn update_user_lockup_positions_and_calc_rewards(
let pool_info = ASSET_POOLS.load(deps.storage, &pool)?;
let lockup_key = (&pool, user_address, duration);
let mut lockup_info =
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key.clone(), &config.generator)?;
LOCKUP_INFO.compatible_load(deps.as_ref(), lockup_key, &config.generator)?;

if lockup_info.astro_rewards == Uint128::zero() {
// Weighted lockup balance (using terraswap LP units to calculate as pool's total weighted balance is calculated on terraswap LP deposits summed over each deposit tx)
Expand Down
6 changes: 3 additions & 3 deletions contracts/lockdrop/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl CompatibleLoader<(&Addr, &Addr, U64Key), LockupInfoV2>
key: (&Addr, &Addr, U64Key),
generator: &Option<Addr>,
) -> StdResult<LockupInfoV2> {
self.load(deps.storage, key.clone()).or_else(|_| {
let old_lockup_info = OLD_LOCKUP_INFO.load(deps.storage, key.clone())?;
self.load(deps.storage, key).or_else(|_| {
let old_lockup_info = OLD_LOCKUP_INFO.load(deps.storage, key)?;
let mut generator_proxy_debt = RestrictedVector::default();
let generator = generator.as_ref().expect("Generator should be set!");

Expand Down Expand Up @@ -96,7 +96,7 @@ impl CompatibleLoader<(&Addr, &Addr, U64Key), LockupInfoV2>
key: (&Addr, &Addr, U64Key),
generator: &Option<Addr>,
) -> StdResult<Option<LockupInfoV2>> {
if !OLD_LOCKUP_INFO.has(deps.storage, key.clone()) {
if !OLD_LOCKUP_INFO.has(deps.storage, key) {
return Ok(None);
}
Some(self.compatible_load(deps, key, generator)).transpose()
Expand Down

0 comments on commit 310544d

Please sign in to comment.