Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed May 16, 2024
1 parent b75374a commit 1dcbd7b
Show file tree
Hide file tree
Showing 20 changed files with 490 additions and 172 deletions.
39 changes: 24 additions & 15 deletions contracts/liquidity_hub/bonding-manager/schema/bonding-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
"additionalProperties": false
},
{
"description": "Returns the weight of the address. Returns the global index of the contract.",
"description": "Returns the global index of the contract.",
"type": "object",
"required": [
"global_index"
Expand All @@ -497,8 +497,8 @@
"global_index": {
"type": "object",
"properties": {
"epoch_id": {
"description": "The epoch id to check for the global index. If none is provided, the current global index is returned.",
"reward_bucket_id": {
"description": "The reward bucket id to check for the global index. If none is provided, the current global index is returned.",
"type": [
"integer",
"null"
Expand Down Expand Up @@ -678,8 +678,8 @@
"bonded_amount",
"bonded_assets",
"epoch_id",
"updated_last",
"weight"
"last_updated",
"last_weight"
],
"properties": {
"bonded_amount": {
Expand All @@ -703,14 +703,14 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the total bond was updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The total weight of the bond at the given block height.",
"last_weight": {
"description": "The total weight of the contract at the given updated_last epoch id.",
"allOf": [
{
"$ref": "#/definitions/Uint128"
Expand Down Expand Up @@ -863,8 +863,8 @@
"bonded_amount",
"bonded_assets",
"epoch_id",
"updated_last",
"weight"
"last_updated",
"last_weight"
],
"properties": {
"bonded_amount": {
Expand All @@ -888,14 +888,14 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the total bond was updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The total weight of the bond at the given block height.",
"last_weight": {
"description": "The total weight of the contract at the given updated_last epoch id.",
"allOf": [
{
"$ref": "#/definitions/Uint128"
Expand Down Expand Up @@ -1094,7 +1094,7 @@
"required": [
"asset",
"created_at_epoch",
"updated_last",
"last_updated",
"weight"
],
"properties": {
Expand All @@ -1112,12 +1112,21 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the bond was last time updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"unbonded_at": {
"description": "The time at which the Bond was unbonded.",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The weight of the bond at the given block height.",
"allOf": [
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/bonding-manager/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"additionalProperties": false
},
{
"description": "Returns the weight of the address. Returns the global index of the contract.",
"description": "Returns the global index of the contract.",
"type": "object",
"required": [
"global_index"
Expand All @@ -116,8 +116,8 @@
"global_index": {
"type": "object",
"properties": {
"epoch_id": {
"description": "The epoch id to check for the global index. If none is provided, the current global index is returned.",
"reward_bucket_id": {
"description": "The reward bucket id to check for the global index. If none is provided, the current global index is returned.",
"type": [
"integer",
"null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"bonded_amount",
"bonded_assets",
"epoch_id",
"updated_last",
"weight"
"last_updated",
"last_weight"
],
"properties": {
"bonded_amount": {
Expand All @@ -62,14 +62,14 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the total bond was updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The total weight of the bond at the given block height.",
"last_weight": {
"description": "The total weight of the contract at the given updated_last epoch id.",
"allOf": [
{
"$ref": "#/definitions/Uint128"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"bonded_amount",
"bonded_assets",
"epoch_id",
"updated_last",
"weight"
"last_updated",
"last_weight"
],
"properties": {
"bonded_amount": {
Expand All @@ -31,14 +31,14 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the total bond was updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The total weight of the bond at the given block height.",
"last_weight": {
"description": "The total weight of the contract at the given updated_last epoch id.",
"allOf": [
{
"$ref": "#/definitions/Uint128"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"required": [
"asset",
"created_at_epoch",
"updated_last",
"last_updated",
"weight"
],
"properties": {
Expand All @@ -49,12 +49,21 @@
"format": "uint64",
"minimum": 0.0
},
"updated_last": {
"last_updated": {
"description": "The epoch id at which the bond was last time updated.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"unbonded_at": {
"description": "The time at which the Bond was unbonded.",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"weight": {
"description": "The weight of the bond at the given block height.",
"allOf": [
Expand Down
13 changes: 4 additions & 9 deletions contracts/liquidity_hub/bonding-manager/src/bonding/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ pub(crate) fn bond(
_env: Env,
asset: Coin,
) -> Result<Response, ContractError> {
println!("----bond----");
helpers::validate_buckets_not_empty(&deps)?;
//todo maybe claim for the user
helpers::validate_claimed(&deps, &info)?;
helpers::validate_bonding_for_current_epoch(&deps)?;

Expand All @@ -43,7 +41,7 @@ pub(crate) fn bond(
..Bond::default()
});

// update local values
// update bond values
bond = update_bond_weight(&mut deps, info.sender.clone(), current_epoch.epoch.id, bond)?;
bond.asset.amount = bond.asset.amount.checked_add(asset.amount)?;
bond.weight = bond.weight.checked_add(asset.amount)?;
Expand All @@ -52,12 +50,8 @@ pub(crate) fn bond(

// update global values
let mut global_index = GLOBAL.load(deps.storage)?;
// include time term in the weight

println!("bonding global_index: {:?}", global_index);

global_index = update_global_weight(&mut deps, current_epoch.epoch.id, global_index.clone())?;

global_index.last_weight = global_index.last_weight.checked_add(asset.amount)?;
global_index.bonded_amount = global_index.bonded_amount.checked_add(asset.amount)?;
global_index.bonded_assets =
Expand Down Expand Up @@ -105,7 +99,7 @@ pub(crate) fn unbond(
&white_whale_std::epoch_manager::epoch_manager::QueryMsg::CurrentEpoch {},
)?;

// update local values, decrease the bond
// update bond values, decrease the bond
unbond = update_bond_weight(
&mut deps,
info.sender.clone(),
Expand All @@ -125,12 +119,13 @@ pub(crate) fn unbond(
// record the unbonding
UNBOND.save(
deps.storage,
(&info.sender, &asset.denom, env.block.time.nanos()),
(&info.sender, &asset.denom, env.block.time.seconds()),
&Bond {
asset: asset.clone(),
weight: Uint128::zero(),
last_updated: current_epoch.epoch.id,
created_at_epoch: current_epoch.epoch.id,
unbonded_at: Some(env.block.time.seconds()),
},
)?;
// update global values
Expand Down
6 changes: 3 additions & 3 deletions contracts/liquidity_hub/bonding-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
// global_index,
// )?)?)
// }
QueryMsg::GlobalIndex { epoch_id } => Ok(to_json_binary(&queries::query_global_index(
deps, epoch_id,
)?)?),
QueryMsg::GlobalIndex { reward_bucket_id } => Ok(to_json_binary(
&queries::query_global_index(deps, reward_bucket_id)?,
)?),
QueryMsg::Claimable { address } => {
Ok(to_json_binary(&queries::query_claimable(&deps, address)?)?)
}
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/bonding-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,19 @@ pub fn validate_bonding_for_current_epoch(deps: &DepsMut) -> Result<(), Contract
// If we do get some LP tokens to withdraw they could be swapped to whale in the reply
pub fn handle_lp_tokens_rewards(
deps: &DepsMut,
funds: &Vec<Coin>,
funds: &[Coin],
config: &Config,
submessages: &mut Vec<SubMsg>,
) -> Result<(), ContractError> {
println!("funds: {:?}", funds);
let lp_tokens: Vec<&Coin> = funds
.iter()
.filter(|coin| coin.denom.contains(".pool.") | coin.denom.contains(LP_SYMBOL))
.collect();

println!("lp_tokens: {:?}", lp_tokens);

for lp_token in lp_tokens {
let pool_identifier =
extract_pool_identifier(&lp_token.denom).ok_or(ContractError::AssetMismatch)?;

println!("pool_identifier: {:?}", pool_identifier);

// make sure a pool with the given identifier exists
let pool: StdResult<PoolInfoResponse> = deps.querier.query_wasm_smart(
config.pool_manager_addr.to_string(),
Expand Down Expand Up @@ -305,7 +300,7 @@ pub fn calculate_rewards(
deps,
reward_bucket.id,
address.to_string(),
Some(reward_bucket.global_index.clone()),
reward_bucket.global_index.clone(),
)?;

// sanity check, if the user has no share in the bucket, skip it
Expand Down
Loading

0 comments on commit 1dcbd7b

Please sign in to comment.