Skip to content

Commit

Permalink
chore: Merge branch 'release/v2_contracts' into feat/bonding-manager-…
Browse files Browse the repository at this point in the history
…whale-lair
  • Loading branch information
0xFable committed Apr 26, 2024
2 parents 30712fb + 75794fe commit 27f7776
Show file tree
Hide file tree
Showing 19 changed files with 730 additions and 67 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fee-distributor-mock = { path = "./contracts/liquidity_hub/fee-distributor-mock"
incentive-factory = { path = "./contracts/liquidity_hub/pool-network/incentive_factory" }
terraswap-token = { path = "./contracts/liquidity_hub/pool-network/terraswap_token" }
terraswap-pair = { path = "./contracts/liquidity_hub/pool-network/terraswap_pair" }

epoch-manager = { path = "./contracts/liquidity_hub/epoch-manager" }
incentive-manager = { path = "./contracts/liquidity_hub/incentive-manager" }

[workspace.metadata.dylint]
libraries = [{ git = "https://github.com/0xFable/cw-lint" }]
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity_hub/incentive-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn instantiate(

let config = Config {
epoch_manager_addr: deps.api.addr_validate(&msg.epoch_manager_addr)?,
whale_lair_addr: deps.api.addr_validate(&msg.whale_lair_addr)?,
whale_lair_addr: deps.api.addr_validate(&msg.bonding_manager_addr)?,
create_incentive_fee: msg.create_incentive_fee,
max_concurrent_incentives: msg.max_concurrent_incentives,
max_incentive_epoch_buffer: msg.max_incentive_epoch_buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl TestingSuite {
#[allow(clippy::too_many_arguments)]
pub(crate) fn instantiate(
&mut self,
whale_lair_addr: String,
bonding_manager_addr: String,
epoch_manager_addr: String,
create_incentive_fee: Coin,
max_concurrent_incentives: u32,
Expand All @@ -213,7 +213,7 @@ impl TestingSuite {
let msg = InstantiateMsg {
owner: self.creator().to_string(),
epoch_manager_addr,
whale_lair_addr,
bonding_manager_addr,
create_incentive_fee,
max_concurrent_incentives,
max_incentive_epoch_buffer,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl TestingSuite {
#[allow(clippy::too_many_arguments)]
pub(crate) fn instantiate_err(
&mut self,
whale_lair_addr: String,
bonding_manager_addr: String,
epoch_manager_addr: String,
create_incentive_fee: Coin,
max_concurrent_incentives: u32,
Expand All @@ -257,7 +257,7 @@ impl TestingSuite {
let msg = InstantiateMsg {
owner: self.creator().to_string(),
epoch_manager_addr,
whale_lair_addr,
bonding_manager_addr,
create_incentive_fee,
max_concurrent_incentives,
max_incentive_epoch_buffer,
Expand Down
2 changes: 2 additions & 0 deletions contracts/liquidity_hub/pool-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ cw-multi-test.workspace = true
anyhow.workspace = true
test-case.workspace = true
whale-lair.workspace = true
incentive-manager.workspace = true
epoch-manager.workspace = true
white-whale-testing.workspace = true
48 changes: 41 additions & 7 deletions contracts/liquidity_hub/pool-manager/schema/pool-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"fee_collector_addr",
"bonding_manager_addr",
"incentive_manager_addr",
"pool_creation_fee"
],
"properties": {
"fee_collector_addr": {
"bonding_manager_addr": {
"type": "string"
},
"incentive_manager_addr": {
"type": "string"
},
"pool_creation_fee": {
Expand Down Expand Up @@ -105,6 +109,13 @@
"pair_identifier"
],
"properties": {
"lock_position_identifier": {
"description": "The identifier of the position to lock the LP tokens in the incentive manager, if any.",
"type": [
"string",
"null"
]
},
"pair_identifier": {
"type": "string"
},
Expand All @@ -123,6 +134,15 @@
"type": "null"
}
]
},
"unlocking_duration": {
"description": "The amount of time in seconds to unlock tokens if taking part on the incentives. If not passed, the tokens will not be locked and the LP tokens will be returned to the user.",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1033,19 +1053,33 @@
"Config": {
"type": "object",
"required": [
"bonding_manager_addr",
"feature_toggle",
"pool_creation_fee",
"whale_lair_addr"
"incentive_manager_addr",
"pool_creation_fee"
],
"properties": {
"bonding_manager_addr": {
"description": "The address of the bonding manager contract.",
"allOf": [
{
"$ref": "#/definitions/Addr"
}
]
},
"feature_toggle": {
"$ref": "#/definitions/FeatureToggle"
},
"incentive_manager_addr": {
"description": "The address of the incentive manager contract.",
"allOf": [
{
"$ref": "#/definitions/Addr"
}
]
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
},
"whale_lair_addr": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
Expand Down
16 changes: 16 additions & 0 deletions contracts/liquidity_hub/pool-manager/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
"pair_identifier"
],
"properties": {
"lock_position_identifier": {
"description": "The identifier of the position to lock the LP tokens in the incentive manager, if any.",
"type": [
"string",
"null"
]
},
"pair_identifier": {
"type": "string"
},
Expand All @@ -80,6 +87,15 @@
"type": "null"
}
]
},
"unlocking_duration": {
"description": "The amount of time in seconds to unlock tokens if taking part on the incentives. If not passed, the tokens will not be locked and the LP tokens will be returned to the user.",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"fee_collector_addr",
"bonding_manager_addr",
"incentive_manager_addr",
"pool_creation_fee"
],
"properties": {
"fee_collector_addr": {
"bonding_manager_addr": {
"type": "string"
},
"incentive_manager_addr": {
"type": "string"
},
"pool_creation_fee": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,33 @@
"Config": {
"type": "object",
"required": [
"bonding_manager_addr",
"feature_toggle",
"pool_creation_fee",
"whale_lair_addr"
"incentive_manager_addr",
"pool_creation_fee"
],
"properties": {
"bonding_manager_addr": {
"description": "The address of the bonding manager contract.",
"allOf": [
{
"$ref": "#/definitions/Addr"
}
]
},
"feature_toggle": {
"$ref": "#/definitions/FeatureToggle"
},
"incentive_manager_addr": {
"description": "The address of the incentive manager contract.",
"allOf": [
{
"$ref": "#/definitions/Addr"
}
]
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
},
"whale_lair_addr": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
Expand Down
7 changes: 6 additions & 1 deletion contracts/liquidity_hub/pool-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub fn instantiate(
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let config: Config = Config {
whale_lair_addr: deps.api.addr_validate(&msg.fee_collector_addr)?,
bonding_manager_addr: deps.api.addr_validate(&msg.bonding_manager_addr)?,
incentive_manager_addr: deps.api.addr_validate(&msg.incentive_manager_addr)?,
// We must set a creation fee on instantiation to prevent spamming of pools
pool_creation_fee: msg.pool_creation_fee,
feature_toggle: FeatureToggle {
Expand Down Expand Up @@ -72,13 +73,17 @@ pub fn execute(
slippage_tolerance,
receiver,
pair_identifier,
unlocking_duration,
lock_position_identifier,
} => liquidity::commands::provide_liquidity(
deps,
env,
info,
slippage_tolerance,
receiver,
pair_identifier,
unlocking_duration,
lock_position_identifier,
),
ExecuteMsg::Swap {
offer_asset,
Expand Down
50 changes: 40 additions & 10 deletions contracts/liquidity_hub/pool-manager/src/liquidity/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cosmwasm_std::{BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response};
use cosmwasm_std::{
coins, wasm_execute, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response,
};
use white_whale_std::pool_network::asset::PairType;

use crate::{
Expand All @@ -20,16 +22,16 @@ pub const MAX_ASSETS_PER_POOL: usize = 4;

// todo allow providing liquidity with a single asset

//todo allow passing an optional locking period for the LP once the liquidity is provided, so tokens
// are locked in the incentive manager

#[allow(clippy::too_many_arguments)]
pub fn provide_liquidity(
deps: DepsMut,
env: Env,
info: MessageInfo,
slippage_tolerance: Option<Decimal>,
receiver: Option<String>,
pair_identifier: String,
unlocking_duration: Option<u64>,
lock_position_identifier: Option<String>,
) -> Result<Response, ContractError> {
let config = MANAGER_CONFIG.load(deps.storage)?;
// check if the deposit feature is enabled
Expand Down Expand Up @@ -145,12 +147,40 @@ pub fn provide_liquidity(
// mint LP token to sender
let receiver = receiver.unwrap_or_else(|| info.sender.to_string());

messages.push(white_whale_std::lp_common::mint_lp_token_msg(
liquidity_token,
&info.sender,
&env.contract.address,
share,
)?);
// if the unlocking duration is set, lock the LP tokens in the incentive manager
if let Some(unlocking_duration) = unlocking_duration {
// mint the lp tokens to the contract
messages.push(white_whale_std::lp_common::mint_lp_token_msg(
liquidity_token.clone(),
&env.contract.address,
&env.contract.address,
share,
)?);

// lock the lp tokens in the incentive manager on behalf of the receiver
messages.push(
wasm_execute(
config.incentive_manager_addr,
&white_whale_std::incentive_manager::ExecuteMsg::ManagePosition {
action: white_whale_std::incentive_manager::PositionAction::Fill {
identifier: lock_position_identifier,
unlocking_duration,
receiver: Some(receiver.clone()),
},
},
coins(share.u128(), liquidity_token),
)?
.into(),
);
} else {
// if not, just mint the LP tokens to the receiver
messages.push(white_whale_std::lp_common::mint_lp_token_msg(
liquidity_token,
&info.sender,
&env.contract.address,
share,
)?);
}

pair.assets = pool_assets.clone();
PAIRS.save(deps.storage, &pair_identifier, &pair)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn create_pair(

// send pair creation fee to whale lair i.e the new fee_collector
messages.push(fill_rewards_msg_coin(
config.whale_lair_addr.into_string(),
config.bonding_manager_addr.into_string(),
creation_fee,
)?);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn update_config(
MANAGER_CONFIG.update(deps.storage, |mut config| {
if let Some(whale_lair_addr) = whale_lair_addr {
let whale_lair_addr = deps.api.addr_validate(&whale_lair_addr)?;
config.whale_lair_addr = whale_lair_addr;
config.bonding_manager_addr = whale_lair_addr;
}

if let Some(pool_creation_fee) = pool_creation_fee {
Expand Down
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/pool-manager/src/router/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn execute_swap_operations(
}
if !swap_result.protocol_fee_asset.amount.is_zero() {
fee_messages.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: config.whale_lair_addr.to_string(),
contract_addr: config.bonding_manager_addr.to_string(),
msg: to_json_binary(&whale_lair::ExecuteMsg::FillRewardsCoin {
})?,
funds: vec![swap_result.protocol_fee_asset.clone()],
Expand All @@ -128,7 +128,7 @@ pub fn execute_swap_operations(
// todo remove, the swap_fee_asset stays in the pool
if !swap_result.swap_fee_asset.amount.is_zero() {
fee_messages.push(CosmosMsg::Bank(BankMsg::Send {
to_address: config.whale_lair_addr.to_string(),
to_address: config.bonding_manager_addr.to_string(),
amount: vec![swap_result.swap_fee_asset],
}));
}
Expand Down
Loading

0 comments on commit 27f7776

Please sign in to comment.