From 26bb3c38ce416bfd4a846a603b1a139b7286765b Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Wed, 7 Jun 2023 19:39:41 +0300 Subject: [PATCH 01/23] add xyk to cl migrate handler for reserve contract --- Cargo.lock | 16 ++ contracts/tokenomics/reserve/Cargo.toml | 2 + contracts/tokenomics/reserve/src/contract.rs | 254 ++++++++++++++++++- contracts/tokenomics/reserve/src/error.rs | 12 +- contracts/tokenomics/reserve/src/msg.rs | 11 + contracts/tokenomics/reserve/src/state.rs | 23 ++ 6 files changed, 312 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa85f843..caeb31c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,6 +59,20 @@ dependencies = [ "uint", ] +[[package]] +name = "astroport" +version = "2.8.0" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.8.0#3b44a4044b823a145730f66ffaf7ae4205b2cd35" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw20 0.15.1", + "itertools", + "uint", +] + [[package]] name = "astroport-periphery" version = "1.1.0" @@ -1471,9 +1485,11 @@ dependencies = [ name = "neutron-reserve" version = "0.1.0" dependencies = [ + "astroport 2.8.0", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.0.1", + "cw20 0.13.4", "cwd-macros", "exec-control", "neutron-sdk 0.5.0", diff --git a/contracts/tokenomics/reserve/Cargo.toml b/contracts/tokenomics/reserve/Cargo.toml index ada84afe..ab7ede30 100644 --- a/contracts/tokenomics/reserve/Cargo.toml +++ b/contracts/tokenomics/reserve/Cargo.toml @@ -21,6 +21,8 @@ exec-control = { path = "../../../packages/exec-control" } serde = { version = "1.0.103", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } cwd-macros = { path = "../../../packages/cwd-macros" } +astroport = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } +cw20 = "0.13" [dev-dependencies] cosmwasm-schema = { version = "1.0.0", default-features = false } diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index cf6daae1..9ed0d79a 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -3,22 +3,36 @@ use crate::error::ContractError; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - coins, to_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, - StdResult, Uint128, WasmMsg, + coins, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, + Reply, Response, StdResult, SubMsg, Uint128, WasmMsg, }; use exec_control::pause::{ can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, }; use neutron_sdk::bindings::query::NeutronQuery; -use crate::msg::{DistributeMsg, ExecuteMsg, InstantiateMsg, QueryMsg, StatsResponse}; +use crate::msg::{DistributeMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, StatsResponse}; use crate::state::{ - Config, CONFIG, LAST_BURNED_COINS_AMOUNT, LAST_DISTRIBUTION_TIME, PAUSED_UNTIL, - TOTAL_DISTRIBUTED, TOTAL_RESERVED, + Config, ATOM_BALANCE_BEFORE_WITHDRAWAL, ATOM_DENOM, CONFIG, LAST_BURNED_COINS_AMOUNT, + LAST_DISTRIBUTION_TIME, NTRN_ATOM_CL_PAIR_ADDRESS, NTRN_BALANCE_BEFORE_WITHDRAWAL, + NTRN_USDC_CL_PAIR_ADDRESS, PAUSED_UNTIL, TOTAL_DISTRIBUTED, TOTAL_RESERVED, + USDC_BALANCE_BEFORE_WITHDRAWAL, USDC_DENOM, }; use crate::vesting::{ get_burned_coins, safe_burned_coins_for_period, update_distribution_stats, vesting_function, }; +use astroport::asset::{native_asset, PairInfo}; +use astroport::pair::{ + Cw20HookMsg as PairCw20HookMsg, ExecuteMsg as PairExecuteMsg, QueryMsg as PairQueryMsg, +}; +use cw20::{Cw20ExecuteMsg, Cw20QueryMsg}; + +/// A `reply` call code ID used for withdraw NTRN/ATOM liquidity sub-messages during migration. +const WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID: u64 = 1; +/// A `reply` call code ID used for withdraw NTRN/USDC liquidity sub-messages during migration. +const WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID: u64 = 2; +/// A `reply` call code ID used for balance check after providing liquidity to a CL pool. +const POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID: u64 = 3; //-------------------------------------------------------------------------------------------------- // Instantiation @@ -359,3 +373,233 @@ pub fn create_distribution_response( Ok(resp) } + +/// Withdraws liquidity from Astroport xyk pools and provides it to the concentrated liquidity ones. +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { + let mut resp: Response = Response::default(); + + NTRN_ATOM_CL_PAIR_ADDRESS.save(deps.storage, &msg.ntrn_atom_cl_pair_address)?; + NTRN_USDC_CL_PAIR_ADDRESS.save(deps.storage, &msg.ntrn_usdc_cl_pair_address)?; + ATOM_DENOM.save(deps.storage, &msg.atom_denom.clone())?; + USDC_DENOM.save(deps.storage, &msg.usdc_denom.clone())?; + + NTRN_BALANCE_BEFORE_WITHDRAWAL.save( + deps.storage, + &deps + .querier + .query_balance(env.contract.address.to_string(), "untrn")? + .amount, + )?; + ATOM_BALANCE_BEFORE_WITHDRAWAL.save( + deps.storage, + &deps + .querier + .query_balance(env.contract.address.to_string(), msg.atom_denom)? + .amount, + )?; + USDC_BALANCE_BEFORE_WITHDRAWAL.save( + deps.storage, + &deps + .querier + .query_balance(env.contract.address.to_string(), msg.usdc_denom)? + .amount, + )?; + + // get the NTRN/ATOM pair LP token address and contract's balance + let ntrn_atom_xyk_pair_info: PairInfo = deps.querier.query_wasm_smart( + msg.ntrn_atom_xyk_pair_address.clone(), + &to_binary(&PairQueryMsg::Pair {})?, + )?; + let ntrn_atom_xyk_pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( + ntrn_atom_xyk_pair_info.liquidity_token.clone(), + &Cw20QueryMsg::Balance { + address: env.contract.address.to_string(), + }, + )?; + + // get the NTRN/USDC pair LP token address and contract's balance + let ntrn_usdc_xyk_pair_info: PairInfo = deps.querier.query_wasm_smart( + msg.ntrn_usdc_xyk_pair_address.clone(), + &to_binary(&PairQueryMsg::Pair {})?, + )?; + let ntrn_usdc_xyk_pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( + ntrn_usdc_xyk_pair_info.liquidity_token.clone(), + &Cw20QueryMsg::Balance { + address: env.contract.address.to_string(), + }, + )?; + + // register submessages for liquidity withdrawal from both pools + resp = resp.add_submessages(vec![ + SubMsg { + id: WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID, + msg: CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: ntrn_atom_xyk_pair_info.liquidity_token.to_string(), + msg: to_binary(&Cw20ExecuteMsg::Send { + contract: msg.ntrn_atom_xyk_pair_address, + amount: ntrn_atom_xyk_pair_lp_token_share, + msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, + })?, + funds: vec![], + }), + gas_limit: None, + reply_on: cosmwasm_std::ReplyOn::Success, + }, + SubMsg { + id: WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID, + msg: CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: ntrn_usdc_xyk_pair_info.liquidity_token.to_string(), + msg: to_binary(&Cw20ExecuteMsg::Send { + contract: msg.ntrn_usdc_xyk_pair_address, + amount: ntrn_usdc_xyk_pair_lp_token_share, + msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, + })?, + funds: vec![], + }), + gas_limit: None, + reply_on: cosmwasm_std::ReplyOn::Success, + }, + ]); + + Ok(resp) +} + +/// The entry point to the contract for processing replies from submessages. +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result { + let mut resp = Response::default(); + match msg.id { + WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID => { + let atom_denom = ATOM_DENOM.load(deps.storage)?; + let ntrn_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), "untrn")? + .amount; + let atom_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), atom_denom.clone())? + .amount; + + // calc amount of assets that's been withdrawn + let withdrawn_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL + .load(deps.storage)? + .checked_sub(ntrn_balance_after_withdrawal)?; + let withdrawn_atom_amount = ATOM_BALANCE_BEFORE_WITHDRAWAL + .load(deps.storage)? + .checked_sub(atom_balance_after_withdrawal)?; + + // provide the withdrawn assets to the CL pair + resp = resp.add_submessage(SubMsg { + id: POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID, + msg: CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: NTRN_ATOM_CL_PAIR_ADDRESS.load(deps.storage)?, + msg: to_binary(&PairExecuteMsg::ProvideLiquidity { + assets: vec![ + native_asset(String::from("untrn"), withdrawn_ntrn_amount), + native_asset(atom_denom.clone(), withdrawn_atom_amount), + ], + slippage_tolerance: None, + auto_stake: None, + receiver: None, + })?, + funds: vec![ + Coin::new(withdrawn_ntrn_amount.into(), String::from("untrn")), + Coin::new(withdrawn_atom_amount.into(), atom_denom), + ], + }), + gas_limit: None, + reply_on: cosmwasm_std::ReplyOn::Never, + }); + } + + WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID => { + let usdc_denom = USDC_DENOM.load(deps.storage)?; + let ntrn_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), "untrn")? + .amount; + let usdc_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), usdc_denom.clone())? + .amount; + + // calc amount of assets that's been withdrawn + let withdrawn_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL + .load(deps.storage)? + .checked_sub(ntrn_balance_after_withdrawal)?; + let withdrawn_usdc_amount = USDC_BALANCE_BEFORE_WITHDRAWAL + .load(deps.storage)? + .checked_sub(usdc_balance_after_withdrawal)?; + + // provide the withdrawn assets to the CL pair + resp = resp.add_submessage(SubMsg { + id: POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID, + msg: CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: NTRN_USDC_CL_PAIR_ADDRESS.load(deps.storage)?, + msg: to_binary(&PairExecuteMsg::ProvideLiquidity { + assets: vec![ + native_asset(String::from("untrn"), withdrawn_ntrn_amount), + native_asset(usdc_denom.clone(), withdrawn_usdc_amount), + ], + slippage_tolerance: None, + auto_stake: None, + receiver: None, + })?, + funds: vec![ + Coin::new(withdrawn_ntrn_amount.into(), String::from("untrn")), + Coin::new(withdrawn_usdc_amount.into(), usdc_denom), + ], + }), + gas_limit: None, + reply_on: cosmwasm_std::ReplyOn::Never, + }); + } + + POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID => { + let atom_denom = ATOM_DENOM.load(deps.storage)?; + let usdc_denom = USDC_DENOM.load(deps.storage)?; + + let ntrn_balance = deps + .querier + .query_balance(env.contract.address.to_string(), "untrn")? + .amount; + let atom_balance = deps + .querier + .query_balance(env.contract.address.to_string(), atom_denom.clone())? + .amount; + let usdc_balance = deps + .querier + .query_balance(env.contract.address.to_string(), usdc_denom.clone())? + .amount; + + let initial_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; + let initial_atom_amount = ATOM_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; + let initial_usdc_amount = USDC_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; + + if !ntrn_balance.eq(&initial_ntrn_amount) { + return Err(ContractError::MigrationBalancesMismtach { + denom: String::from("untrn"), + initial_balance: initial_ntrn_amount, + intermediate_balance: ntrn_balance, + }); + } + if !atom_balance.eq(&initial_atom_amount) { + return Err(ContractError::MigrationBalancesMismtach { + denom: atom_denom, + initial_balance: initial_atom_amount, + intermediate_balance: atom_balance, + }); + } + if !usdc_balance.eq(&initial_usdc_amount) { + return Err(ContractError::MigrationBalancesMismtach { + denom: usdc_denom, + initial_balance: initial_usdc_amount, + intermediate_balance: usdc_balance, + }); + } + } + _ => return Err(ContractError::UnkownReplyID { reply_id: msg.id }), + } + Ok(resp) +} diff --git a/contracts/tokenomics/reserve/src/error.rs b/contracts/tokenomics/reserve/src/error.rs index 2bb2f131..0166ba6b 100644 --- a/contracts/tokenomics/reserve/src/error.rs +++ b/contracts/tokenomics/reserve/src/error.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{OverflowError, StdError}; +use cosmwasm_std::{OverflowError, StdError, Uint128}; use exec_control::pause::PauseError; use thiserror::Error; @@ -31,6 +31,16 @@ pub enum ContractError { #[error("no coins were burned, nothing to distribute")] NoBurnedCoins {}, + #[error("Unknown reply ID {reply_id}")] + UnkownReplyID { reply_id: u64 }, + + #[error("{denom} balance {intermediate_balance} after liquidity withdrawal and providing doesn't match the initial one {initial_balance}")] + MigrationBalancesMismtach { + denom: String, + initial_balance: Uint128, + intermediate_balance: Uint128, + }, + #[error("Overflow")] OverflowError(#[from] OverflowError), } diff --git a/contracts/tokenomics/reserve/src/msg.rs b/contracts/tokenomics/reserve/src/msg.rs index 3cea7af7..ec108b5a 100644 --- a/contracts/tokenomics/reserve/src/msg.rs +++ b/contracts/tokenomics/reserve/src/msg.rs @@ -64,3 +64,14 @@ pub struct StatsResponse { pub enum DistributeMsg { Fund {}, } + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct MigrateMsg { + pub atom_denom: String, + pub ntrn_atom_xyk_pair_address: String, + pub ntrn_atom_cl_pair_address: String, + pub usdc_denom: String, + pub ntrn_usdc_xyk_pair_address: String, + pub ntrn_usdc_cl_pair_address: String, +} diff --git a/contracts/tokenomics/reserve/src/state.rs b/contracts/tokenomics/reserve/src/state.rs index 689ff150..f72e6ac0 100644 --- a/contracts/tokenomics/reserve/src/state.rs +++ b/contracts/tokenomics/reserve/src/state.rs @@ -55,6 +55,29 @@ pub const CONFIG: Item = Item::new("config"); /// The height the contract is paused until. If it's None, the contract is not paused. pub const PAUSED_UNTIL: Item> = Item::new("paused_until"); +/// Denom of the IBC transferred ATOM. Used in migrate from xyk to concentrated liquidity pool. +pub const ATOM_DENOM: Item = Item::new("atom_denom"); +/// Denom of the IBC transferred USDC. Used in migrate from xyk to concentrated liquidity pool. +pub const USDC_DENOM: Item = Item::new("usdc_denom"); + +/// Contract's ntrn balance before withdraw liquidity call. Used in migrate from xyk to concentrated +/// liquidity pool. +pub const NTRN_BALANCE_BEFORE_WITHDRAWAL: Item = + Item::new("ntrn_balance_before_withdrawal"); +/// Contract's atom balance before withdraw liquidity call. Used in migrate from xyk to concentrated +/// liquidity pool. +pub const ATOM_BALANCE_BEFORE_WITHDRAWAL: Item = + Item::new("atom_balance_before_withdrawal"); +/// Contract's usdc balance before withdraw liquidity call. Used in migrate from xyk to concentrated +/// liquidity pool. +pub const USDC_BALANCE_BEFORE_WITHDRAWAL: Item = + Item::new("usdc_balance_before_withdrawal"); + +/// Address of the NTRN/ATOM pair of CL type. Used in migrate from xyk to concentrated liquidity pool. +pub const NTRN_ATOM_CL_PAIR_ADDRESS: Item = Item::new("ntrn_atom_cl_pair_address"); +/// Address of the NTRN/USDC pair of CL type. Used in migrate from xyk to concentrated liquidity pool. +pub const NTRN_USDC_CL_PAIR_ADDRESS: Item = Item::new("ntrn_usdc_cl_pair_address"); + #[cfg(test)] mod tests { use super::Config; From 81149f72f286d137bb3d8e4cc482b879cb294057 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Tue, 13 Jun 2023 18:05:08 +0300 Subject: [PATCH 02/23] refactor reserve migration using callbacks instead of submsgs --- .../reserve/schema/execute_msg.json | 122 +++++ contracts/tokenomics/reserve/src/contract.rs | 438 +++++++++--------- contracts/tokenomics/reserve/src/error.rs | 4 +- contracts/tokenomics/reserve/src/msg.rs | 44 +- contracts/tokenomics/reserve/src/state.rs | 23 - 5 files changed, 380 insertions(+), 251 deletions(-) diff --git a/contracts/tokenomics/reserve/schema/execute_msg.json b/contracts/tokenomics/reserve/schema/execute_msg.json index a2a736d8..53c0cc31 100644 --- a/contracts/tokenomics/reserve/schema/execute_msg.json +++ b/contracts/tokenomics/reserve/schema/execute_msg.json @@ -29,6 +29,7 @@ "additionalProperties": false }, { + "description": "Update config", "type": "object", "required": [ "update_config" @@ -86,6 +87,19 @@ }, "additionalProperties": false }, + { + "description": "Callbacks; only callable by the contract itself.", + "type": "object", + "required": [ + "callback" + ], + "properties": { + "callback": { + "$ref": "#/definitions/CallbackMsg" + } + }, + "additionalProperties": false + }, { "type": "object", "required": [ @@ -122,9 +136,117 @@ } ], "definitions": { + "CallbackMsg": { + "oneOf": [ + { + "type": "object", + "required": [ + "migrate_liquidity_to_cl_pair" + ], + "properties": { + "migrate_liquidity_to_cl_pair": { + "type": "object", + "required": [ + "cl_pair_address", + "ntrn_denom", + "paired_asset_denom", + "xyk_pair_address" + ], + "properties": { + "cl_pair_address": { + "type": "string" + }, + "ntrn_denom": { + "type": "string" + }, + "paired_asset_denom": { + "type": "string" + }, + "xyk_pair_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "provide_liquidity_to_cl_pair_after_withdrawal" + ], + "properties": { + "provide_liquidity_to_cl_pair_after_withdrawal": { + "type": "object", + "required": [ + "cl_pair_address", + "ntrn_denom", + "ntrn_init_balance", + "paired_asset_denom", + "paired_asset_init_balance" + ], + "properties": { + "cl_pair_address": { + "type": "string" + }, + "ntrn_denom": { + "type": "string" + }, + "ntrn_init_balance": { + "$ref": "#/definitions/Uint128" + }, + "paired_asset_denom": { + "type": "string" + }, + "paired_asset_init_balance": { + "$ref": "#/definitions/Uint128" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "post_migration_balances_check" + ], + "properties": { + "post_migration_balances_check": { + "type": "object", + "required": [ + "ntrn_denom", + "ntrn_init_balance", + "paired_asset_denom", + "paired_asset_init_balance" + ], + "properties": { + "ntrn_denom": { + "type": "string" + }, + "ntrn_init_balance": { + "$ref": "#/definitions/Uint128" + }, + "paired_asset_denom": { + "type": "string" + }, + "paired_asset_init_balance": { + "$ref": "#/definitions/Uint128" + } + } + } + }, + "additionalProperties": false + } + ] + }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" + }, + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" } } } diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index 9ed0d79a..414b9f07 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -3,20 +3,20 @@ use crate::error::ContractError; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - coins, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, - Reply, Response, StdResult, SubMsg, Uint128, WasmMsg, + coins, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, + MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use exec_control::pause::{ can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, }; use neutron_sdk::bindings::query::NeutronQuery; -use crate::msg::{DistributeMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, StatsResponse}; +use crate::msg::{ + CallbackMsg, DistributeMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, StatsResponse, +}; use crate::state::{ - Config, ATOM_BALANCE_BEFORE_WITHDRAWAL, ATOM_DENOM, CONFIG, LAST_BURNED_COINS_AMOUNT, - LAST_DISTRIBUTION_TIME, NTRN_ATOM_CL_PAIR_ADDRESS, NTRN_BALANCE_BEFORE_WITHDRAWAL, - NTRN_USDC_CL_PAIR_ADDRESS, PAUSED_UNTIL, TOTAL_DISTRIBUTED, TOTAL_RESERVED, - USDC_BALANCE_BEFORE_WITHDRAWAL, USDC_DENOM, + Config, CONFIG, LAST_BURNED_COINS_AMOUNT, LAST_DISTRIBUTION_TIME, PAUSED_UNTIL, + TOTAL_DISTRIBUTED, TOTAL_RESERVED, }; use crate::vesting::{ get_burned_coins, safe_burned_coins_for_period, update_distribution_stats, vesting_function, @@ -27,13 +27,6 @@ use astroport::pair::{ }; use cw20::{Cw20ExecuteMsg, Cw20QueryMsg}; -/// A `reply` call code ID used for withdraw NTRN/ATOM liquidity sub-messages during migration. -const WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID: u64 = 1; -/// A `reply` call code ID used for withdraw NTRN/USDC liquidity sub-messages during migration. -const WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID: u64 = 2; -/// A `reply` call code ID used for balance check after providing liquidity to a CL pool. -const POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID: u64 = 3; - //-------------------------------------------------------------------------------------------------- // Instantiation //-------------------------------------------------------------------------------------------------- @@ -182,6 +175,7 @@ pub fn execute( ), ExecuteMsg::Pause { duration } => execute_pause(deps, env, info.sender, duration), ExecuteMsg::Unpause {} => execute_unpause(deps, info.sender), + ExecuteMsg::Callback(msg) => _handle_callback(deps, env, info, msg), } } @@ -309,6 +303,61 @@ pub fn execute_distribute( .add_attribute("distributed", to_distribute)) } +fn _handle_callback( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: CallbackMsg, +) -> Result { + // Only the contract itself can call callbacks + if info.sender != env.contract.address { + return Err(ContractError::Unauthorized {}); + } + match msg { + CallbackMsg::MigrateLiquidityToClPair { + xyk_pair_address, + cl_pair_address, + ntrn_denom, + paired_asset_denom, + } => migrate_liquidity_to_cl_pair_callback( + deps, + env, + xyk_pair_address, + cl_pair_address, + ntrn_denom, + paired_asset_denom, + ), + CallbackMsg::ProvideLiquidityToClPairAfterWithdrawal { + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, + cl_pair_address, + } => provide_liquidity_to_cl_pair_after_withdrawal_callback( + deps, + env, + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, + cl_pair_address, + ), + CallbackMsg::PostMigrationBalancesCheck { + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, + } => post_migration_balances_check_callback( + deps, + env, + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, + ), + } +} + //-------------------------------------------------------------------------------------------------- // Queries //-------------------------------------------------------------------------------------------------- @@ -374,232 +423,173 @@ pub fn create_distribution_response( Ok(resp) } +//-------------------------------------------------------------------------------------------------- +// Migration +//-------------------------------------------------------------------------------------------------- + /// Withdraws liquidity from Astroport xyk pools and provides it to the concentrated liquidity ones. #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { - let mut resp: Response = Response::default(); - - NTRN_ATOM_CL_PAIR_ADDRESS.save(deps.storage, &msg.ntrn_atom_cl_pair_address)?; - NTRN_USDC_CL_PAIR_ADDRESS.save(deps.storage, &msg.ntrn_usdc_cl_pair_address)?; - ATOM_DENOM.save(deps.storage, &msg.atom_denom.clone())?; - USDC_DENOM.save(deps.storage, &msg.usdc_denom.clone())?; - - NTRN_BALANCE_BEFORE_WITHDRAWAL.save( - deps.storage, - &deps - .querier - .query_balance(env.contract.address.to_string(), "untrn")? - .amount, - )?; - ATOM_BALANCE_BEFORE_WITHDRAWAL.save( - deps.storage, - &deps - .querier - .query_balance(env.contract.address.to_string(), msg.atom_denom)? - .amount, - )?; - USDC_BALANCE_BEFORE_WITHDRAWAL.save( - deps.storage, - &deps - .querier - .query_balance(env.contract.address.to_string(), msg.usdc_denom)? - .amount, - )?; +pub fn migrate(_deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { + Ok(Response::default().add_messages(vec![ + CallbackMsg::MigrateLiquidityToClPair { + ntrn_denom: msg.ntrn_denom.clone(), + xyk_pair_address: msg.ntrn_atom_xyk_pair_address, + cl_pair_address: msg.ntrn_atom_cl_pair_address, + paired_asset_denom: msg.atom_denom, + } + .to_cosmos_msg(&env)?, + CallbackMsg::MigrateLiquidityToClPair { + ntrn_denom: msg.ntrn_denom, + xyk_pair_address: msg.ntrn_usdc_xyk_pair_address, + cl_pair_address: msg.ntrn_usdc_cl_pair_address, + paired_asset_denom: msg.usdc_denom, + } + .to_cosmos_msg(&env)?, + ])) +} - // get the NTRN/ATOM pair LP token address and contract's balance - let ntrn_atom_xyk_pair_info: PairInfo = deps.querier.query_wasm_smart( - msg.ntrn_atom_xyk_pair_address.clone(), - &to_binary(&PairQueryMsg::Pair {})?, - )?; - let ntrn_atom_xyk_pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( - ntrn_atom_xyk_pair_info.liquidity_token.clone(), - &Cw20QueryMsg::Balance { - address: env.contract.address.to_string(), - }, - )?; +fn migrate_liquidity_to_cl_pair_callback( + deps: DepsMut, + env: Env, + xyk_pair_address: String, + cl_pair_address: String, + ntrn_denom: String, + paired_asset_denom: String, +) -> Result { + let ntrn_init_balance = deps + .querier + .query_balance(env.contract.address.to_string(), ntrn_denom.clone())? + .amount; + let paired_asset_init_balance = deps + .querier + .query_balance(env.contract.address.to_string(), paired_asset_denom.clone())? + .amount; - // get the NTRN/USDC pair LP token address and contract's balance - let ntrn_usdc_xyk_pair_info: PairInfo = deps.querier.query_wasm_smart( - msg.ntrn_usdc_xyk_pair_address.clone(), + // get the pair LP token address and contract's balance + let pair_info: PairInfo = deps.querier.query_wasm_smart( + xyk_pair_address.clone(), &to_binary(&PairQueryMsg::Pair {})?, )?; - let ntrn_usdc_xyk_pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( - ntrn_usdc_xyk_pair_info.liquidity_token.clone(), + let pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( + pair_info.liquidity_token.clone(), &Cw20QueryMsg::Balance { address: env.contract.address.to_string(), }, )?; - // register submessages for liquidity withdrawal from both pools - resp = resp.add_submessages(vec![ - SubMsg { - id: WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID, - msg: CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: ntrn_atom_xyk_pair_info.liquidity_token.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Send { - contract: msg.ntrn_atom_xyk_pair_address, - amount: ntrn_atom_xyk_pair_lp_token_share, - msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, - })?, - funds: vec![], - }), - gas_limit: None, - reply_on: cosmwasm_std::ReplyOn::Success, - }, - SubMsg { - id: WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID, - msg: CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: ntrn_usdc_xyk_pair_info.liquidity_token.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Send { - contract: msg.ntrn_usdc_xyk_pair_address, - amount: ntrn_usdc_xyk_pair_lp_token_share, - msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, - })?, - funds: vec![], - }), - gas_limit: None, - reply_on: cosmwasm_std::ReplyOn::Success, - }, - ]); + let msgs: Vec = vec![ + // push message to withdraw liquidity from the xyk pool + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: pair_info.liquidity_token.to_string(), + msg: to_binary(&Cw20ExecuteMsg::Send { + contract: xyk_pair_address, + amount: pair_lp_token_share, + msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, + })?, + funds: vec![], + }), + // push the next migration step as a callback message + CallbackMsg::ProvideLiquidityToClPairAfterWithdrawal { + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, + cl_pair_address, + } + .to_cosmos_msg(&env)?, + ]; - Ok(resp) + Ok(Response::default().add_messages(msgs)) } -/// The entry point to the contract for processing replies from submessages. -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result { - let mut resp = Response::default(); - match msg.id { - WITHDRAW_NTRN_ATOM_LIQUIDITY_REPLY_ID => { - let atom_denom = ATOM_DENOM.load(deps.storage)?; - let ntrn_balance_after_withdrawal = deps - .querier - .query_balance(env.contract.address.to_string(), "untrn")? - .amount; - let atom_balance_after_withdrawal = deps - .querier - .query_balance(env.contract.address.to_string(), atom_denom.clone())? - .amount; - - // calc amount of assets that's been withdrawn - let withdrawn_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL - .load(deps.storage)? - .checked_sub(ntrn_balance_after_withdrawal)?; - let withdrawn_atom_amount = ATOM_BALANCE_BEFORE_WITHDRAWAL - .load(deps.storage)? - .checked_sub(atom_balance_after_withdrawal)?; - - // provide the withdrawn assets to the CL pair - resp = resp.add_submessage(SubMsg { - id: POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID, - msg: CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: NTRN_ATOM_CL_PAIR_ADDRESS.load(deps.storage)?, - msg: to_binary(&PairExecuteMsg::ProvideLiquidity { - assets: vec![ - native_asset(String::from("untrn"), withdrawn_ntrn_amount), - native_asset(atom_denom.clone(), withdrawn_atom_amount), - ], - slippage_tolerance: None, - auto_stake: None, - receiver: None, - })?, - funds: vec![ - Coin::new(withdrawn_ntrn_amount.into(), String::from("untrn")), - Coin::new(withdrawn_atom_amount.into(), atom_denom), - ], - }), - gas_limit: None, - reply_on: cosmwasm_std::ReplyOn::Never, - }); - } +fn provide_liquidity_to_cl_pair_after_withdrawal_callback( + deps: DepsMut, + env: Env, + ntrn_denom: String, + ntrn_init_balance: Uint128, + paired_asset_denom: String, + paired_asset_init_balance: Uint128, + cl_pair_address: String, +) -> Result { + let ntrn_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), ntrn_denom.clone())? + .amount; + let paired_asset_balance_after_withdrawal = deps + .querier + .query_balance(env.contract.address.to_string(), paired_asset_denom.clone())? + .amount; - WITHDRAW_NTRN_USDC_LIQUIDITY_REPLY_ID => { - let usdc_denom = USDC_DENOM.load(deps.storage)?; - let ntrn_balance_after_withdrawal = deps - .querier - .query_balance(env.contract.address.to_string(), "untrn")? - .amount; - let usdc_balance_after_withdrawal = deps - .querier - .query_balance(env.contract.address.to_string(), usdc_denom.clone())? - .amount; - - // calc amount of assets that's been withdrawn - let withdrawn_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL - .load(deps.storage)? - .checked_sub(ntrn_balance_after_withdrawal)?; - let withdrawn_usdc_amount = USDC_BALANCE_BEFORE_WITHDRAWAL - .load(deps.storage)? - .checked_sub(usdc_balance_after_withdrawal)?; - - // provide the withdrawn assets to the CL pair - resp = resp.add_submessage(SubMsg { - id: POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID, - msg: CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: NTRN_USDC_CL_PAIR_ADDRESS.load(deps.storage)?, - msg: to_binary(&PairExecuteMsg::ProvideLiquidity { - assets: vec![ - native_asset(String::from("untrn"), withdrawn_ntrn_amount), - native_asset(usdc_denom.clone(), withdrawn_usdc_amount), - ], - slippage_tolerance: None, - auto_stake: None, - receiver: None, - })?, - funds: vec![ - Coin::new(withdrawn_ntrn_amount.into(), String::from("untrn")), - Coin::new(withdrawn_usdc_amount.into(), usdc_denom), - ], - }), - gas_limit: None, - reply_on: cosmwasm_std::ReplyOn::Never, - }); + // calc amount of assets that's been withdrawn + let withdrawn_ntrn_amount = ntrn_balance_after_withdrawal.checked_sub(ntrn_init_balance)?; + let withdrawn_paired_asset_amount = + paired_asset_balance_after_withdrawal.checked_sub(paired_asset_init_balance)?; + + let msgs: Vec = vec![ + // push message to provide liquidity to the CL pool + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: cl_pair_address, + msg: to_binary(&PairExecuteMsg::ProvideLiquidity { + assets: vec![ + native_asset(ntrn_denom.clone(), withdrawn_ntrn_amount), + native_asset(paired_asset_denom.clone(), withdrawn_paired_asset_amount), + ], + slippage_tolerance: Some(Decimal::percent(50)), + auto_stake: None, + receiver: None, + })?, + funds: vec![ + Coin::new(withdrawn_ntrn_amount.into(), ntrn_denom.clone()), + Coin::new( + withdrawn_paired_asset_amount.into(), + paired_asset_denom.clone(), + ), + ], + }), + // push the next migration step as a callback message + CallbackMsg::PostMigrationBalancesCheck { + ntrn_denom, + ntrn_init_balance, + paired_asset_denom, + paired_asset_init_balance, } + .to_cosmos_msg(&env)?, + ]; - POST_PROVIDE_LIQUIDITY_BALANCE_CHECK_REPLY_ID => { - let atom_denom = ATOM_DENOM.load(deps.storage)?; - let usdc_denom = USDC_DENOM.load(deps.storage)?; - - let ntrn_balance = deps - .querier - .query_balance(env.contract.address.to_string(), "untrn")? - .amount; - let atom_balance = deps - .querier - .query_balance(env.contract.address.to_string(), atom_denom.clone())? - .amount; - let usdc_balance = deps - .querier - .query_balance(env.contract.address.to_string(), usdc_denom.clone())? - .amount; - - let initial_ntrn_amount = NTRN_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; - let initial_atom_amount = ATOM_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; - let initial_usdc_amount = USDC_BALANCE_BEFORE_WITHDRAWAL.load(deps.storage)?; - - if !ntrn_balance.eq(&initial_ntrn_amount) { - return Err(ContractError::MigrationBalancesMismtach { - denom: String::from("untrn"), - initial_balance: initial_ntrn_amount, - intermediate_balance: ntrn_balance, - }); - } - if !atom_balance.eq(&initial_atom_amount) { - return Err(ContractError::MigrationBalancesMismtach { - denom: atom_denom, - initial_balance: initial_atom_amount, - intermediate_balance: atom_balance, - }); - } - if !usdc_balance.eq(&initial_usdc_amount) { - return Err(ContractError::MigrationBalancesMismtach { - denom: usdc_denom, - initial_balance: initial_usdc_amount, - intermediate_balance: usdc_balance, - }); - } - } - _ => return Err(ContractError::UnkownReplyID { reply_id: msg.id }), + Ok(Response::default().add_messages(msgs)) +} + +fn post_migration_balances_check_callback( + deps: DepsMut, + env: Env, + ntrn_denom: String, + ntrn_init_balance: Uint128, + paired_asset_denom: String, + paired_asset_init_balance: Uint128, +) -> Result { + let ntrn_balance = deps + .querier + .query_balance(env.contract.address.to_string(), ntrn_denom.clone())? + .amount; + let paired_asset_balance = deps + .querier + .query_balance(env.contract.address.to_string(), paired_asset_denom.clone())? + .amount; + + if !ntrn_balance.eq(&ntrn_init_balance) { + return Err(ContractError::MigrationBalancesMismtach { + denom: ntrn_denom, + initial_balance: ntrn_init_balance, + final_balance: ntrn_balance, + }); } - Ok(resp) + if !paired_asset_balance.eq(&paired_asset_init_balance) { + return Err(ContractError::MigrationBalancesMismtach { + denom: paired_asset_denom, + initial_balance: paired_asset_init_balance, + final_balance: paired_asset_balance, + }); + } + + Ok(Response::default()) } diff --git a/contracts/tokenomics/reserve/src/error.rs b/contracts/tokenomics/reserve/src/error.rs index 0166ba6b..32987c07 100644 --- a/contracts/tokenomics/reserve/src/error.rs +++ b/contracts/tokenomics/reserve/src/error.rs @@ -34,11 +34,11 @@ pub enum ContractError { #[error("Unknown reply ID {reply_id}")] UnkownReplyID { reply_id: u64 }, - #[error("{denom} balance {intermediate_balance} after liquidity withdrawal and providing doesn't match the initial one {initial_balance}")] + #[error("{denom} balance {final_balance} after liquidity withdrawal and providing doesn't match the initial one {initial_balance}")] MigrationBalancesMismtach { denom: String, initial_balance: Uint128, - intermediate_balance: Uint128, + final_balance: Uint128, }, #[error("Overflow")] diff --git a/contracts/tokenomics/reserve/src/msg.rs b/contracts/tokenomics/reserve/src/msg.rs index ec108b5a..786463c7 100644 --- a/contracts/tokenomics/reserve/src/msg.rs +++ b/contracts/tokenomics/reserve/src/msg.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Decimal, Uint128}; +use cosmwasm_std::{to_binary, CosmosMsg, Decimal, Env, StdResult, Uint128, WasmMsg}; use cwd_macros::{pausable, pausable_query}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -31,7 +31,7 @@ pub enum ExecuteMsg { /// Distribute pending funds between Bank and Distribution accounts Distribute {}, - // //Update config + /// Update config UpdateConfig { distribution_rate: Option, min_period: Option, @@ -40,6 +40,45 @@ pub enum ExecuteMsg { security_dao_address: Option, vesting_denominator: Option, }, + + /// Callbacks; only callable by the contract itself. + Callback(CallbackMsg), +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum CallbackMsg { + MigrateLiquidityToClPair { + xyk_pair_address: String, + cl_pair_address: String, + ntrn_denom: String, + paired_asset_denom: String, + }, + ProvideLiquidityToClPairAfterWithdrawal { + ntrn_denom: String, + ntrn_init_balance: Uint128, + paired_asset_denom: String, + paired_asset_init_balance: Uint128, + cl_pair_address: String, + }, + PostMigrationBalancesCheck { + ntrn_denom: String, + ntrn_init_balance: Uint128, + paired_asset_denom: String, + paired_asset_init_balance: Uint128, + }, +} + +// Modified from +// https://github.com/CosmWasm/cosmwasm-plus/blob/v0.2.3/packages/cw20/src/receiver.rs#L15 +impl CallbackMsg { + pub fn to_cosmos_msg(self, env: &Env) -> StdResult { + Ok(CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: env.contract.address.to_string(), + msg: to_binary(&ExecuteMsg::Callback(self))?, + funds: vec![], + })) + } } #[pausable_query] @@ -68,6 +107,7 @@ pub enum DistributeMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct MigrateMsg { + pub ntrn_denom: String, pub atom_denom: String, pub ntrn_atom_xyk_pair_address: String, pub ntrn_atom_cl_pair_address: String, diff --git a/contracts/tokenomics/reserve/src/state.rs b/contracts/tokenomics/reserve/src/state.rs index f72e6ac0..689ff150 100644 --- a/contracts/tokenomics/reserve/src/state.rs +++ b/contracts/tokenomics/reserve/src/state.rs @@ -55,29 +55,6 @@ pub const CONFIG: Item = Item::new("config"); /// The height the contract is paused until. If it's None, the contract is not paused. pub const PAUSED_UNTIL: Item> = Item::new("paused_until"); -/// Denom of the IBC transferred ATOM. Used in migrate from xyk to concentrated liquidity pool. -pub const ATOM_DENOM: Item = Item::new("atom_denom"); -/// Denom of the IBC transferred USDC. Used in migrate from xyk to concentrated liquidity pool. -pub const USDC_DENOM: Item = Item::new("usdc_denom"); - -/// Contract's ntrn balance before withdraw liquidity call. Used in migrate from xyk to concentrated -/// liquidity pool. -pub const NTRN_BALANCE_BEFORE_WITHDRAWAL: Item = - Item::new("ntrn_balance_before_withdrawal"); -/// Contract's atom balance before withdraw liquidity call. Used in migrate from xyk to concentrated -/// liquidity pool. -pub const ATOM_BALANCE_BEFORE_WITHDRAWAL: Item = - Item::new("atom_balance_before_withdrawal"); -/// Contract's usdc balance before withdraw liquidity call. Used in migrate from xyk to concentrated -/// liquidity pool. -pub const USDC_BALANCE_BEFORE_WITHDRAWAL: Item = - Item::new("usdc_balance_before_withdrawal"); - -/// Address of the NTRN/ATOM pair of CL type. Used in migrate from xyk to concentrated liquidity pool. -pub const NTRN_ATOM_CL_PAIR_ADDRESS: Item = Item::new("ntrn_atom_cl_pair_address"); -/// Address of the NTRN/USDC pair of CL type. Used in migrate from xyk to concentrated liquidity pool. -pub const NTRN_USDC_CL_PAIR_ADDRESS: Item = Item::new("ntrn_usdc_cl_pair_address"); - #[cfg(test)] mod tests { use super::Config; From c2bbba833abe180863e62ff7925672057cccbe09 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Tue, 13 Jun 2023 18:05:31 +0300 Subject: [PATCH 03/23] tmp rm all but reserve contract --- Cargo.lock | 501 +++-------------------------------------------------- Cargo.toml | 20 +-- 2 files changed, 33 insertions(+), 488 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index caeb31c9..82de6ab7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,19 +32,6 @@ dependencies = [ "uint", ] -[[package]] -name = "astroport" -version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw20 0.15.1", - "itertools", - "uint", -] - [[package]] name = "astroport" version = "2.7.1" @@ -265,29 +252,6 @@ dependencies = [ "libc", ] -[[package]] -name = "credits-vault" -version = "0.2.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", - "cw-paginate 0.2.0", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "cw2 0.13.4", - "cw20 1.0.1", - "cwd-interface", - "cwd-macros", - "cwd-voting", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "crunchy" version = "0.2.2" @@ -343,21 +307,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cw-controllers" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91440ce8ec4f0642798bc8c8cb6b9b53c1926c6dadaf0eed267a5145cd529071" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cw-core" version = "0.1.0" @@ -405,7 +354,7 @@ name = "cw-denom" version = "0.2.0" dependencies = [ "cosmwasm-std", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw20 0.13.4", "cw20-base", "schemars", @@ -432,25 +381,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cw-multi-test" -version = "0.16.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a18afd2e201221c6d72a57f0886ef2a22151bbc9e6db7af276fde8a91081042" -dependencies = [ - "anyhow", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "derivative", - "itertools", - "k256", - "prost 0.9.0", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cw-paginate" version = "0.1.0" @@ -468,7 +398,7 @@ version = "0.2.0" dependencies = [ "cosmwasm-std", "cosmwasm-storage", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-storage-plus 0.13.4", "serde", ] @@ -557,21 +487,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cw-utils" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2 1.0.1", - "schemars", - "semver", - "serde", - "thiserror", -] - [[package]] name = "cw2" version = "0.13.4" @@ -597,19 +512,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cw2" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "schemars", - "serde", -] - [[package]] name = "cw20" version = "0.13.4" @@ -635,19 +537,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cw20" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91666da6c7b40c8dd5ff94df655a28114efc10c79b70b4d06f13c31e37d60609" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-utils 1.0.1", - "schemars", - "serde", -] - [[package]] name = "cw20-base" version = "0.13.4" @@ -695,7 +584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6c95c89153e7831c8306c8eba40a3daa76f9c7b8f5179dd0b8628aca168ec7a" dependencies = [ "cosmwasm-std", - "cw-controllers 0.13.4", + "cw-controllers", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", @@ -761,7 +650,7 @@ dependencies = [ "cw721", "cwd-interface", "cwd-macros", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -810,7 +699,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", @@ -829,7 +718,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", @@ -841,34 +730,9 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk 0.5.0", - "schemars", - "serde", -] - -[[package]] -name = "cwd-pre-propose-overrule" -version = "0.2.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-denom", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cwd-core", - "cwd-interface", - "cwd-pre-propose-base", - "cwd-proposal-hooks", - "cwd-proposal-single", - "cwd-voting", - "neutron-dao-pre-propose-overrule", - "neutron-sdk 0.5.0", - "neutron-subdao-core", - "neutron-subdao-timelock-single", + "neutron-sdk", "schemars", "serde", - "thiserror", ] [[package]] @@ -878,7 +742,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", @@ -890,7 +754,7 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -906,45 +770,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cwd-proposal-multiple" -version = "0.2.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-denom", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cw20 0.13.4", - "cw20-base", - "cw3", - "cw4", - "cw4-group", - "cw721-base", - "cwd-core", - "cwd-hooks", - "cwd-interface", - "cwd-macros", - "cwd-pre-propose-base", - "cwd-pre-propose-multiple", - "cwd-pre-propose-single", - "cwd-proposal-hooks", - "cwd-testing", - "cwd-vote-hooks", - "cwd-voting", - "neutron-sdk 0.5.0", - "neutron-vault", - "neutron-voting-registry", - "rand", - "schemars", - "serde", - "thiserror", - "voting", -] - [[package]] name = "cwd-proposal-single" version = "0.2.0" @@ -953,7 +778,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-denom", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-proposal-single", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -974,7 +799,7 @@ dependencies = [ "cwd-testing", "cwd-vote-hooks", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-vault", "neutron-voting-registry", "schemars", @@ -983,128 +808,13 @@ dependencies = [ "voting", ] -[[package]] -name = "cwd-subdao-core" -version = "0.2.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-core", - "cw-paginate 0.2.0", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cw20 0.13.4", - "cw721", - "cwd-interface", - "cwd-macros", - "cwd-voting", - "exec-control", - "neutron-sdk 0.5.0", - "neutron-subdao-core", - "neutron-subdao-pre-propose-single", - "neutron-subdao-proposal-single", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "cwd-subdao-pre-propose-single" -version = "0.2.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-denom", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cw20 0.13.4", - "cwd-interface", - "cwd-pre-propose-base", - "cwd-voting", - "neutron-sdk 0.5.0", - "neutron-subdao-core", - "neutron-subdao-pre-propose-single", - "neutron-subdao-proposal-single", - "neutron-subdao-timelock-single", - "schemars", - "serde", -] - -[[package]] -name = "cwd-subdao-proposal-single" -version = "0.2.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-denom", - "cw-multi-test 0.13.4", - "cw-proposal-single", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cw20 0.13.4", - "cw20-base", - "cw3", - "cw4", - "cw4-group", - "cw721-base", - "cwd-hooks", - "cwd-interface", - "cwd-macros", - "cwd-pre-propose-base", - "cwd-proposal-hooks", - "cwd-subdao-pre-propose-single", - "cwd-vote-hooks", - "cwd-voting", - "neutron-sdk 0.5.0", - "neutron-subdao-core", - "neutron-subdao-pre-propose-single", - "neutron-subdao-proposal-single", - "schemars", - "serde", - "thiserror", - "voting", -] - -[[package]] -name = "cwd-subdao-timelock-single" -version = "0.2.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-controllers 0.13.4", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.13.4", - "cw-utils 0.13.4", - "cw2 0.13.4", - "cwd-interface", - "cwd-macros", - "cwd-pre-propose-base", - "cwd-proposal-single", - "cwd-voting", - "neutron-dao-pre-propose-overrule", - "neutron-sdk 0.5.0", - "neutron-subdao-core", - "neutron-subdao-pre-propose-single", - "neutron-subdao-timelock-single", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cwd-testing" version = "0.2.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test 0.13.4", + "cw-multi-test", "cw-proposal-single", "cw-utils 0.13.4", "cw2 0.13.4", @@ -1149,7 +859,7 @@ dependencies = [ "cwd-core", "cwd-interface", "cwd-macros", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -1358,30 +1068,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "investors-vesting-vault" -version = "0.2.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", - "cw-paginate 0.2.0", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "cw2 0.13.4", - "cw20 1.0.1", - "cwd-interface", - "cwd-macros", - "cwd-voting", - "schemars", - "serde", - "thiserror", - "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", -] - [[package]] name = "itertools" version = "0.10.5" @@ -1415,28 +1101,6 @@ version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" -[[package]] -name = "lockdrop-vault" -version = "0.1.0" -dependencies = [ - "anyhow", - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", - "astroport-periphery", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.13.4", - "cw2 0.13.4", - "cw20 0.13.4", - "cwd-interface", - "cwd-macros", - "cwd-voting", - "neutron-lockdrop-vault", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "neutron-dao-pre-propose-overrule" version = "0.1.0" @@ -1446,20 +1110,6 @@ dependencies = [ "serde", ] -[[package]] -name = "neutron-distribution" -version = "0.1.0" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "cwd-macros", - "exec-control", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "neutron-lockdrop-vault" version = "0.1.0" @@ -1477,7 +1127,7 @@ dependencies = [ name = "neutron-oracle" version = "0.1.0" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0", "cosmwasm-std", ] @@ -1492,33 +1142,12 @@ dependencies = [ "cw20 0.13.4", "cwd-macros", "exec-control", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", ] -[[package]] -name = "neutron-sdk" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a57cb451a16a676ecbbb1bb1e0e2e9bc9989834d82c6b16eebc24d9ed97cf" -dependencies = [ - "base64 0.20.0", - "bech32", - "cosmos-sdk-proto", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "prost 0.11.9", - "protobuf 3.2.0", - "schemars", - "serde", - "serde-json-wasm 0.4.1", - "serde_json", - "thiserror", -] - [[package]] name = "neutron-sdk" version = "0.5.0" @@ -1551,7 +1180,7 @@ dependencies = [ "cwd-macros", "cwd-voting", "exec-control", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -1565,7 +1194,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1578,7 +1207,7 @@ dependencies = [ "cw-utils 0.13.4", "cwd-macros", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1588,7 +1217,7 @@ name = "neutron-subdao-timelock-single" version = "0.1.0" dependencies = [ "cosmwasm-std", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1601,8 +1230,8 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers 0.13.4", - "cw-multi-test 0.13.4", + "cw-controllers", + "cw-multi-test", "cw-paginate 0.2.0", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -1634,8 +1263,8 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers 0.13.4", - "cw-multi-test 0.13.4", + "cw-controllers", + "cw-multi-test", "cw-paginate 0.2.0", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -1852,24 +1481,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rescueeer" -version = "0.2.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "neutron-sdk 0.4.0", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "rfc6979" version = "0.3.1" @@ -2194,72 +1805,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "vesting-base" -version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" -dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw-utils 0.15.1", - "cw2 0.15.1", - "cw20 0.15.1", - "serde", - "thiserror", -] - -[[package]] -name = "vesting-base" -version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" -dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw-utils 0.15.1", - "cw2 0.15.1", - "cw20 0.15.1", - "serde", - "thiserror", -] - -[[package]] -name = "vesting-lp" -version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" -dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw2 0.15.1", - "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", -] - -[[package]] -name = "vesting-lp-vault" -version = "0.1.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test 0.13.4", - "cw-storage-plus 0.13.4", - "cw2 0.13.4", - "cwd-interface", - "cwd-macros", - "neutron-oracle", - "neutron-vesting-lp-vault", - "schemars", - "serde", - "thiserror", - "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", - "vesting-lp", -] - [[package]] name = "vote-hooks" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b3874be4..c7b27343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,16 @@ [workspace] members = [ - "contracts/dao/cwd-core", - "contracts/dao/proposal/*", - "contracts/dao/pre-propose/*", - "contracts/dao/voting/*", - "contracts/subdaos/cwd-subdao-core", - "contracts/subdaos/proposal/*", - "contracts/subdaos/pre-propose/*", - "contracts/subdaos/cwd-subdao-timelock-single", + # "contracts/dao/cwd-core", + # "contracts/dao/proposal/*", + # "contracts/dao/pre-propose/*", + # "contracts/dao/voting/*", + # "contracts/subdaos/cwd-subdao-core", + # "contracts/subdaos/proposal/*", + # "contracts/subdaos/pre-propose/*", + # "contracts/subdaos/cwd-subdao-timelock-single", "contracts/tokenomics/reserve", - "contracts/tokenomics/distribution", - "contracts/misc/rescueeer", + # "contracts/tokenomics/distribution", + # "contracts/misc/rescueeer", "packages/*", ] From 4039ef326e55b82b013f5273f4a5b4691724e0df Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Wed, 14 Jun 2023 12:56:51 +0300 Subject: [PATCH 04/23] fix typo in error name --- contracts/tokenomics/reserve/src/contract.rs | 4 ++-- contracts/tokenomics/reserve/src/error.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index 414b9f07..cabb90dd 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -577,14 +577,14 @@ fn post_migration_balances_check_callback( .amount; if !ntrn_balance.eq(&ntrn_init_balance) { - return Err(ContractError::MigrationBalancesMismtach { + return Err(ContractError::MigrationBalancesMismatch { denom: ntrn_denom, initial_balance: ntrn_init_balance, final_balance: ntrn_balance, }); } if !paired_asset_balance.eq(&paired_asset_init_balance) { - return Err(ContractError::MigrationBalancesMismtach { + return Err(ContractError::MigrationBalancesMismatch { denom: paired_asset_denom, initial_balance: paired_asset_init_balance, final_balance: paired_asset_balance, diff --git a/contracts/tokenomics/reserve/src/error.rs b/contracts/tokenomics/reserve/src/error.rs index 32987c07..1a0958d7 100644 --- a/contracts/tokenomics/reserve/src/error.rs +++ b/contracts/tokenomics/reserve/src/error.rs @@ -35,7 +35,7 @@ pub enum ContractError { UnkownReplyID { reply_id: u64 }, #[error("{denom} balance {final_balance} after liquidity withdrawal and providing doesn't match the initial one {initial_balance}")] - MigrationBalancesMismtach { + MigrationBalancesMismatch { denom: String, initial_balance: Uint128, final_balance: Uint128, From 4eaf301b1f9dda14fca2a471a8790a0c33a6cdab Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Wed, 14 Jun 2023 12:59:09 +0300 Subject: [PATCH 05/23] fix pair info and balances query in reserve migration --- contracts/tokenomics/reserve/src/contract.rs | 34 +++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index cabb90dd..aaad2e27 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -1,16 +1,5 @@ use crate::distribution_params::DistributionParams; use crate::error::ContractError; -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; -use cosmwasm_std::{ - coins, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, - MessageInfo, Response, StdResult, Uint128, WasmMsg, -}; -use exec_control::pause::{ - can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, -}; -use neutron_sdk::bindings::query::NeutronQuery; - use crate::msg::{ CallbackMsg, DistributeMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, StatsResponse, }; @@ -25,7 +14,17 @@ use astroport::asset::{native_asset, PairInfo}; use astroport::pair::{ Cw20HookMsg as PairCw20HookMsg, ExecuteMsg as PairExecuteMsg, QueryMsg as PairQueryMsg, }; -use cw20::{Cw20ExecuteMsg, Cw20QueryMsg}; +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{ + coins, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, + MessageInfo, Response, StdResult, Uint128, WasmMsg, +}; +use cw20::{BalanceResponse, Cw20ExecuteMsg, Cw20QueryMsg}; +use exec_control::pause::{ + can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, +}; +use neutron_sdk::bindings::query::NeutronQuery; //-------------------------------------------------------------------------------------------------- // Instantiation @@ -466,11 +465,10 @@ fn migrate_liquidity_to_cl_pair_callback( .amount; // get the pair LP token address and contract's balance - let pair_info: PairInfo = deps.querier.query_wasm_smart( - xyk_pair_address.clone(), - &to_binary(&PairQueryMsg::Pair {})?, - )?; - let pair_lp_token_share: Uint128 = deps.querier.query_wasm_smart( + let pair_info: PairInfo = deps + .querier + .query_wasm_smart(xyk_pair_address.clone(), &PairQueryMsg::Pair {})?; + let pair_lp_token_balance: BalanceResponse = deps.querier.query_wasm_smart( pair_info.liquidity_token.clone(), &Cw20QueryMsg::Balance { address: env.contract.address.to_string(), @@ -483,7 +481,7 @@ fn migrate_liquidity_to_cl_pair_callback( contract_addr: pair_info.liquidity_token.to_string(), msg: to_binary(&Cw20ExecuteMsg::Send { contract: xyk_pair_address, - amount: pair_lp_token_share, + amount: pair_lp_token_balance.balance, msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, })?, funds: vec![], From 8ff3856df029b2aabc828e7dc05301f146d9af32 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Wed, 14 Jun 2023 13:02:58 +0300 Subject: [PATCH 06/23] enable all contracts --- Cargo.lock | 511 ++++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 20 +-- 2 files changed, 493 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82de6ab7..d4fa7386 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -34,8 +34,21 @@ dependencies = [ [[package]] name = "astroport" -version = "2.7.1" -source = "git+https://github.com/astroport-fi/astroport-core.git?branch=main#c73a2db3c0b4f069e906d90970e1b72a5cf71bbf" +version = "2.0.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#20790b78175b41c3ccbabce2c296c4c605d07946" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw20 0.15.1", + "itertools", + "uint", +] + +[[package]] +name = "astroport" +version = "2.5.0" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.5.0#65ce7d1879cc5d95b09fa14202f0423bba52ae0e" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -63,9 +76,9 @@ dependencies = [ [[package]] name = "astroport-periphery" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" dependencies = [ - "astroport 2.7.1", + "astroport 2.5.0", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", @@ -252,6 +265,29 @@ dependencies = [ "libc", ] +[[package]] +name = "credits-vault" +version = "0.2.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-controllers 1.0.1", + "cw-multi-test 0.16.5", + "cw-paginate 0.2.0", + "cw-storage-plus 1.0.1", + "cw-utils 1.0.1", + "cw2 0.13.4", + "cw20 1.0.1", + "cwd-interface", + "cwd-macros", + "cwd-voting", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "crunchy" version = "0.2.2" @@ -307,6 +343,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-controllers" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91440ce8ec4f0642798bc8c8cb6b9b53c1926c6dadaf0eed267a5145cd529071" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.0.1", + "cw-utils 1.0.1", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw-core" version = "0.1.0" @@ -354,7 +405,7 @@ name = "cw-denom" version = "0.2.0" dependencies = [ "cosmwasm-std", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw20 0.13.4", "cw20-base", "schemars", @@ -381,6 +432,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-multi-test" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cw-storage-plus 1.0.1", + "cw-utils 1.0.1", + "derivative", + "itertools", + "k256", + "prost 0.9.0", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw-paginate" version = "0.1.0" @@ -398,7 +468,7 @@ version = "0.2.0" dependencies = [ "cosmwasm-std", "cosmwasm-storage", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-storage-plus 0.13.4", "serde", ] @@ -487,6 +557,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-utils" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw2 1.0.1", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw2" version = "0.13.4" @@ -512,6 +597,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cw2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.0.1", + "schemars", + "serde", +] + [[package]] name = "cw20" version = "0.13.4" @@ -537,6 +635,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cw20" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91666da6c7b40c8dd5ff94df655a28114efc10c79b70b4d06f13c31e37d60609" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-utils 1.0.1", + "schemars", + "serde", +] + [[package]] name = "cw20-base" version = "0.13.4" @@ -584,7 +695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6c95c89153e7831c8306c8eba40a3daa76f9c7b8f5179dd0b8628aca168ec7a" dependencies = [ "cosmwasm-std", - "cw-controllers", + "cw-controllers 0.13.4", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", @@ -650,7 +761,7 @@ dependencies = [ "cw721", "cwd-interface", "cwd-macros", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", "thiserror", @@ -699,7 +810,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", @@ -718,7 +829,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", @@ -730,9 +841,34 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk", + "neutron-sdk 0.5.0", + "schemars", + "serde", +] + +[[package]] +name = "cwd-pre-propose-overrule" +version = "0.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-denom", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cwd-core", + "cwd-interface", + "cwd-pre-propose-base", + "cwd-proposal-hooks", + "cwd-proposal-single", + "cwd-voting", + "neutron-dao-pre-propose-overrule", + "neutron-sdk 0.5.0", + "neutron-subdao-core", + "neutron-subdao-timelock-single", "schemars", "serde", + "thiserror", ] [[package]] @@ -742,7 +878,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-denom", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", @@ -754,7 +890,7 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", ] @@ -770,6 +906,45 @@ dependencies = [ "serde", ] +[[package]] +name = "cwd-proposal-multiple" +version = "0.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-denom", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cw20 0.13.4", + "cw20-base", + "cw3", + "cw4", + "cw4-group", + "cw721-base", + "cwd-core", + "cwd-hooks", + "cwd-interface", + "cwd-macros", + "cwd-pre-propose-base", + "cwd-pre-propose-multiple", + "cwd-pre-propose-single", + "cwd-proposal-hooks", + "cwd-testing", + "cwd-vote-hooks", + "cwd-voting", + "neutron-sdk 0.5.0", + "neutron-vault", + "neutron-voting-registry", + "rand", + "schemars", + "serde", + "thiserror", + "voting", +] + [[package]] name = "cwd-proposal-single" version = "0.2.0" @@ -778,7 +953,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-denom", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-proposal-single", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -799,7 +974,7 @@ dependencies = [ "cwd-testing", "cwd-vote-hooks", "cwd-voting", - "neutron-sdk", + "neutron-sdk 0.5.0", "neutron-vault", "neutron-voting-registry", "schemars", @@ -808,13 +983,128 @@ dependencies = [ "voting", ] +[[package]] +name = "cwd-subdao-core" +version = "0.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-core", + "cw-paginate 0.2.0", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cw20 0.13.4", + "cw721", + "cwd-interface", + "cwd-macros", + "cwd-voting", + "exec-control", + "neutron-sdk 0.5.0", + "neutron-subdao-core", + "neutron-subdao-pre-propose-single", + "neutron-subdao-proposal-single", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cwd-subdao-pre-propose-single" +version = "0.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-denom", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cw20 0.13.4", + "cwd-interface", + "cwd-pre-propose-base", + "cwd-voting", + "neutron-sdk 0.5.0", + "neutron-subdao-core", + "neutron-subdao-pre-propose-single", + "neutron-subdao-proposal-single", + "neutron-subdao-timelock-single", + "schemars", + "serde", +] + +[[package]] +name = "cwd-subdao-proposal-single" +version = "0.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-denom", + "cw-multi-test 0.13.4", + "cw-proposal-single", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cw20 0.13.4", + "cw20-base", + "cw3", + "cw4", + "cw4-group", + "cw721-base", + "cwd-hooks", + "cwd-interface", + "cwd-macros", + "cwd-pre-propose-base", + "cwd-proposal-hooks", + "cwd-subdao-pre-propose-single", + "cwd-vote-hooks", + "cwd-voting", + "neutron-sdk 0.5.0", + "neutron-subdao-core", + "neutron-subdao-pre-propose-single", + "neutron-subdao-proposal-single", + "schemars", + "serde", + "thiserror", + "voting", +] + +[[package]] +name = "cwd-subdao-timelock-single" +version = "0.2.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-controllers 0.13.4", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw-utils 0.13.4", + "cw2 0.13.4", + "cwd-interface", + "cwd-macros", + "cwd-pre-propose-base", + "cwd-proposal-single", + "cwd-voting", + "neutron-dao-pre-propose-overrule", + "neutron-sdk 0.5.0", + "neutron-subdao-core", + "neutron-subdao-pre-propose-single", + "neutron-subdao-timelock-single", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cwd-testing" version = "0.2.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test", + "cw-multi-test 0.13.4", "cw-proposal-single", "cw-utils 0.13.4", "cw2 0.13.4", @@ -859,7 +1149,7 @@ dependencies = [ "cwd-core", "cwd-interface", "cwd-macros", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", "thiserror", @@ -1068,6 +1358,30 @@ dependencies = [ "thiserror", ] +[[package]] +name = "investors-vesting-vault" +version = "0.2.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-controllers 1.0.1", + "cw-multi-test 0.16.5", + "cw-paginate 0.2.0", + "cw-storage-plus 1.0.1", + "cw-utils 1.0.1", + "cw2 0.13.4", + "cw20 1.0.1", + "cwd-interface", + "cwd-macros", + "cwd-voting", + "schemars", + "serde", + "thiserror", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1101,6 +1415,28 @@ version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +[[package]] +name = "lockdrop-vault" +version = "0.1.0" +dependencies = [ + "anyhow", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport-periphery", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "cw20 0.13.4", + "cwd-interface", + "cwd-macros", + "cwd-voting", + "neutron-lockdrop-vault", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "neutron-dao-pre-propose-overrule" version = "0.1.0" @@ -1110,6 +1446,20 @@ dependencies = [ "serde", ] +[[package]] +name = "neutron-distribution" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.0.1", + "cwd-macros", + "exec-control", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "neutron-lockdrop-vault" version = "0.1.0" @@ -1127,7 +1477,7 @@ dependencies = [ name = "neutron-oracle" version = "0.1.0" dependencies = [ - "astroport 2.0.0", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-std", ] @@ -1142,12 +1492,33 @@ dependencies = [ "cw20 0.13.4", "cwd-macros", "exec-control", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", "thiserror", ] +[[package]] +name = "neutron-sdk" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a57cb451a16a676ecbbb1bb1e0e2e9bc9989834d82c6b16eebc24d9ed97cf" +dependencies = [ + "base64 0.20.0", + "bech32", + "cosmos-sdk-proto", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.0.1", + "prost 0.11.9", + "protobuf 3.2.0", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "serde_json", + "thiserror", +] + [[package]] name = "neutron-sdk" version = "0.5.0" @@ -1180,7 +1551,7 @@ dependencies = [ "cwd-macros", "cwd-voting", "exec-control", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", "thiserror", @@ -1194,7 +1565,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", ] @@ -1207,7 +1578,7 @@ dependencies = [ "cw-utils 0.13.4", "cwd-macros", "cwd-voting", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", ] @@ -1217,7 +1588,7 @@ name = "neutron-subdao-timelock-single" version = "0.1.0" dependencies = [ "cosmwasm-std", - "neutron-sdk", + "neutron-sdk 0.5.0", "schemars", "serde", ] @@ -1230,8 +1601,8 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers", - "cw-multi-test", + "cw-controllers 0.13.4", + "cw-multi-test 0.13.4", "cw-paginate 0.2.0", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -1263,8 +1634,8 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers", - "cw-multi-test", + "cw-controllers 0.13.4", + "cw-multi-test 0.13.4", "cw-paginate 0.2.0", "cw-storage-plus 0.13.4", "cw-utils 0.13.4", @@ -1481,6 +1852,24 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rescueeer" +version = "0.2.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-controllers 1.0.1", + "cw-multi-test 0.16.5", + "cw-storage-plus 1.0.1", + "cw-utils 1.0.1", + "neutron-sdk 0.4.0", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "rfc6979" version = "0.3.1" @@ -1805,6 +2194,72 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vesting-base" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "serde", + "thiserror", +] + +[[package]] +name = "vesting-base" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#20790b78175b41c3ccbabce2c296c4c605d07946" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "serde", + "thiserror", +] + +[[package]] +name = "vesting-lp" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw2 0.15.1", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", +] + +[[package]] +name = "vesting-lp-vault" +version = "0.1.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test 0.13.4", + "cw-storage-plus 0.13.4", + "cw2 0.13.4", + "cwd-interface", + "cwd-macros", + "neutron-oracle", + "neutron-vesting-lp-vault", + "schemars", + "serde", + "thiserror", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "vesting-lp", +] + [[package]] name = "vote-hooks" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index c7b27343..b3874be4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,16 @@ [workspace] members = [ - # "contracts/dao/cwd-core", - # "contracts/dao/proposal/*", - # "contracts/dao/pre-propose/*", - # "contracts/dao/voting/*", - # "contracts/subdaos/cwd-subdao-core", - # "contracts/subdaos/proposal/*", - # "contracts/subdaos/pre-propose/*", - # "contracts/subdaos/cwd-subdao-timelock-single", + "contracts/dao/cwd-core", + "contracts/dao/proposal/*", + "contracts/dao/pre-propose/*", + "contracts/dao/voting/*", + "contracts/subdaos/cwd-subdao-core", + "contracts/subdaos/proposal/*", + "contracts/subdaos/pre-propose/*", + "contracts/subdaos/cwd-subdao-timelock-single", "contracts/tokenomics/reserve", - # "contracts/tokenomics/distribution", - # "contracts/misc/rescueeer", + "contracts/tokenomics/distribution", + "contracts/misc/rescueeer", "packages/*", ] From 7efb44a25302c15e4432e4f4fdad5ea2840fdeda Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Thu, 15 Jun 2023 14:07:49 +0300 Subject: [PATCH 07/23] move liquidity migration logic from migration handler to exec one --- contracts/tokenomics/reserve/src/contract.rs | 346 +++++++++++++------ contracts/tokenomics/reserve/src/error.rs | 21 +- contracts/tokenomics/reserve/src/msg.rs | 19 +- contracts/tokenomics/reserve/src/state.rs | 18 + 4 files changed, 293 insertions(+), 111 deletions(-) diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index aaad2e27..f54a08ea 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -5,7 +5,11 @@ use crate::msg::{ }; use crate::state::{ Config, CONFIG, LAST_BURNED_COINS_AMOUNT, LAST_DISTRIBUTION_TIME, PAUSED_UNTIL, - TOTAL_DISTRIBUTED, TOTAL_RESERVED, + TOTAL_DISTRIBUTED, TOTAL_RESERVED, XYK_TO_CL_MIGRATION_ATOM_DENOM, + XYK_TO_CL_MIGRATION_MAX_SLIPPAGE, XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR, + XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR, XYK_TO_CL_MIGRATION_NTRN_DENOM, + XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR, XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR, + XYK_TO_CL_MIGRATION_USDC_DENOM, }; use crate::vesting::{ get_burned_coins, safe_burned_coins_for_period, update_distribution_stats, vesting_function, @@ -174,6 +178,17 @@ pub fn execute( ), ExecuteMsg::Pause { duration } => execute_pause(deps, env, info.sender, duration), ExecuteMsg::Unpause {} => execute_unpause(deps, info.sender), + ExecuteMsg::MigrateFromXykToCl { + slippage_tolerance, + ntrn_atom_amount, + ntrn_usdc_amount, + } => execute_migrate_from_xyk_to_cl( + deps, + env, + slippage_tolerance, + ntrn_atom_amount, + ntrn_usdc_amount, + ), ExecuteMsg::Callback(msg) => _handle_callback(deps, env, info, msg), } } @@ -302,6 +317,106 @@ pub fn execute_distribute( .add_attribute("distributed", to_distribute)) } +fn execute_migrate_from_xyk_to_cl( + deps: DepsMut, + env: Env, + slippage_tolerance: Option, + ntrn_atom_amount: Option, + ntrn_usdc_amount: Option, +) -> Result { + // query max available amounts to be withdrawn from both pairs + let max_available_ntrn_atom_amount = { + let resp: BalanceResponse = deps.querier.query_wasm_smart( + XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.load(deps.storage)?, + &Cw20QueryMsg::Balance { + address: env.contract.address.to_string(), + }, + )?; + resp.balance + }; + let max_available_ntrn_usdc_amount = { + let resp: BalanceResponse = deps.querier.query_wasm_smart( + XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.load(deps.storage)?, + &Cw20QueryMsg::Balance { + address: env.contract.address.to_string(), + }, + )?; + resp.balance + }; + if max_available_ntrn_atom_amount.is_zero() && max_available_ntrn_usdc_amount.is_zero() { + return Err(ContractError::MigrationComplete {}); + } + + // validate parameters to the max available values + if let Some(ntrn_atom_amount) = ntrn_atom_amount { + if ntrn_atom_amount.gt(&max_available_ntrn_atom_amount) { + return Err(ContractError::MigrationAmountUnavailable { + amount: ntrn_atom_amount, + max_amount: max_available_ntrn_atom_amount, + }); + } + } + if let Some(ntrn_usdc_amount) = ntrn_usdc_amount { + if ntrn_usdc_amount.gt(&max_available_ntrn_usdc_amount) { + return Err(ContractError::MigrationAmountUnavailable { + amount: ntrn_usdc_amount, + max_amount: max_available_ntrn_usdc_amount, + }); + } + } + let max_slippage_tolerance = XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.load(deps.storage)?; + if let Some(slippage_tolerance) = slippage_tolerance { + if slippage_tolerance.gt(&max_slippage_tolerance) { + return Err(ContractError::MigrationSlippageToBig { + slippage_tolerance, + max_slippage_tolerance, + }); + } + } + + let ntrn_denom = XYK_TO_CL_MIGRATION_NTRN_DENOM.load(deps.storage)?; + let ntrn_atom_amount = ntrn_atom_amount.unwrap_or(max_available_ntrn_atom_amount); + let ntrn_usdc_amount = ntrn_usdc_amount.unwrap_or(max_available_ntrn_usdc_amount); + let ntrn_atom_xyk_pair_address = XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.load(deps.storage)?; + let ntrn_atom_cl_pair_address = XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR.load(deps.storage)?; + let atom_denom = XYK_TO_CL_MIGRATION_ATOM_DENOM.load(deps.storage)?; + let ntrn_usdc_xyk_pair_address = XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.load(deps.storage)?; + let ntrn_usdc_cl_pair_address = XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR.load(deps.storage)?; + let usdc_denom = XYK_TO_CL_MIGRATION_USDC_DENOM.load(deps.storage)?; + let slippage_tolerance = + slippage_tolerance.unwrap_or(XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.load(deps.storage)?); + + let mut resp = Response::default(); + if !ntrn_atom_amount.is_zero() { + resp = resp.add_message( + CallbackMsg::MigrateLiquidityToClPair { + ntrn_denom: ntrn_denom.clone(), + amount: ntrn_atom_amount, + slippage_tolerance, + xyk_pair_address: ntrn_atom_xyk_pair_address, + cl_pair_address: ntrn_atom_cl_pair_address, + paired_asset_denom: atom_denom, + } + .to_cosmos_msg(&env)?, + ); + } + if !ntrn_usdc_amount.is_zero() { + resp = resp.add_message( + CallbackMsg::MigrateLiquidityToClPair { + ntrn_denom, + amount: ntrn_usdc_amount, + slippage_tolerance, + xyk_pair_address: ntrn_usdc_xyk_pair_address, + cl_pair_address: ntrn_usdc_cl_pair_address, + paired_asset_denom: usdc_denom, + } + .to_cosmos_msg(&env)?, + ); + } + + Ok(resp) +} + fn _handle_callback( deps: DepsMut, env: Env, @@ -315,6 +430,8 @@ fn _handle_callback( match msg { CallbackMsg::MigrateLiquidityToClPair { xyk_pair_address, + amount, + slippage_tolerance, cl_pair_address, ntrn_denom, paired_asset_denom, @@ -322,6 +439,8 @@ fn _handle_callback( deps, env, xyk_pair_address, + amount, + slippage_tolerance, cl_pair_address, ntrn_denom, paired_asset_denom, @@ -332,6 +451,7 @@ fn _handle_callback( paired_asset_denom, paired_asset_init_balance, cl_pair_address, + slippage_tolerance, } => provide_liquidity_to_cl_pair_after_withdrawal_callback( deps, env, @@ -340,6 +460,7 @@ fn _handle_callback( paired_asset_denom, paired_asset_init_balance, cl_pair_address, + slippage_tolerance, ), CallbackMsg::PostMigrationBalancesCheck { ntrn_denom, @@ -357,101 +478,14 @@ fn _handle_callback( } } -//-------------------------------------------------------------------------------------------------- -// Queries -//-------------------------------------------------------------------------------------------------- - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::Config {} => to_binary(&query_config(deps)?), - QueryMsg::Stats {} => to_binary(&query_stats(deps)?), - QueryMsg::PauseInfo {} => query_paused(deps, env), - } -} - -pub fn query_paused(deps: Deps, env: Env) -> StdResult { - to_binary(&get_pause_info(deps, &env)?) -} - -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; - Ok(config) -} - -pub fn query_stats(deps: Deps) -> StdResult { - let total_distributed = TOTAL_DISTRIBUTED.load(deps.storage)?; - let total_reserved = TOTAL_RESERVED.load(deps.storage)?; - let total_processed_burned_coins = LAST_BURNED_COINS_AMOUNT.load(deps.storage)?; - - Ok(StatsResponse { - total_distributed, - total_reserved, - total_processed_burned_coins, - }) -} - -//-------------------------------------------------------------------------------------------------- -// Helpers -//-------------------------------------------------------------------------------------------------- - -pub fn create_distribution_response( - config: Config, - to_distribute: Uint128, - to_reserve: Uint128, - denom: String, -) -> StdResult { - let mut resp = Response::default(); - if !to_distribute.is_zero() { - let msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: config.distribution_contract.to_string(), - funds: coins(to_distribute.u128(), denom.clone()), - msg: to_binary(&DistributeMsg::Fund {})?, - }); - resp = resp.add_message(msg) - } - - if !to_reserve.is_zero() { - let msg = CosmosMsg::Bank(BankMsg::Send { - to_address: config.treasury_contract.to_string(), - amount: coins(to_reserve.u128(), denom), - }); - resp = resp.add_message(msg); - } - - Ok(resp) -} - -//-------------------------------------------------------------------------------------------------- -// Migration -//-------------------------------------------------------------------------------------------------- - -/// Withdraws liquidity from Astroport xyk pools and provides it to the concentrated liquidity ones. -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(_deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { - Ok(Response::default().add_messages(vec![ - CallbackMsg::MigrateLiquidityToClPair { - ntrn_denom: msg.ntrn_denom.clone(), - xyk_pair_address: msg.ntrn_atom_xyk_pair_address, - cl_pair_address: msg.ntrn_atom_cl_pair_address, - paired_asset_denom: msg.atom_denom, - } - .to_cosmos_msg(&env)?, - CallbackMsg::MigrateLiquidityToClPair { - ntrn_denom: msg.ntrn_denom, - xyk_pair_address: msg.ntrn_usdc_xyk_pair_address, - cl_pair_address: msg.ntrn_usdc_cl_pair_address, - paired_asset_denom: msg.usdc_denom, - } - .to_cosmos_msg(&env)?, - ])) -} - +#[allow(clippy::too_many_arguments)] fn migrate_liquidity_to_cl_pair_callback( deps: DepsMut, env: Env, - xyk_pair_address: String, - cl_pair_address: String, + xyk_pair_address: Addr, + amount: Uint128, + slippage_tolerance: Decimal, + cl_pair_address: Addr, ntrn_denom: String, paired_asset_denom: String, ) -> Result { @@ -468,20 +502,14 @@ fn migrate_liquidity_to_cl_pair_callback( let pair_info: PairInfo = deps .querier .query_wasm_smart(xyk_pair_address.clone(), &PairQueryMsg::Pair {})?; - let pair_lp_token_balance: BalanceResponse = deps.querier.query_wasm_smart( - pair_info.liquidity_token.clone(), - &Cw20QueryMsg::Balance { - address: env.contract.address.to_string(), - }, - )?; let msgs: Vec = vec![ - // push message to withdraw liquidity from the xyk pool + // push message to withdraw liquidity from the xyk pair CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: pair_info.liquidity_token.to_string(), msg: to_binary(&Cw20ExecuteMsg::Send { - contract: xyk_pair_address, - amount: pair_lp_token_balance.balance, + contract: xyk_pair_address.to_string(), + amount, msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, })?, funds: vec![], @@ -493,6 +521,7 @@ fn migrate_liquidity_to_cl_pair_callback( paired_asset_denom, paired_asset_init_balance, cl_pair_address, + slippage_tolerance, } .to_cosmos_msg(&env)?, ]; @@ -500,6 +529,7 @@ fn migrate_liquidity_to_cl_pair_callback( Ok(Response::default().add_messages(msgs)) } +#[allow(clippy::too_many_arguments)] fn provide_liquidity_to_cl_pair_after_withdrawal_callback( deps: DepsMut, env: Env, @@ -507,7 +537,8 @@ fn provide_liquidity_to_cl_pair_after_withdrawal_callback( ntrn_init_balance: Uint128, paired_asset_denom: String, paired_asset_init_balance: Uint128, - cl_pair_address: String, + cl_pair_address: Addr, + slippage_tolerance: Decimal, ) -> Result { let ntrn_balance_after_withdrawal = deps .querier @@ -524,15 +555,15 @@ fn provide_liquidity_to_cl_pair_after_withdrawal_callback( paired_asset_balance_after_withdrawal.checked_sub(paired_asset_init_balance)?; let msgs: Vec = vec![ - // push message to provide liquidity to the CL pool + // push message to provide liquidity to the CL pair CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: cl_pair_address, + contract_addr: cl_pair_address.to_string(), msg: to_binary(&PairExecuteMsg::ProvideLiquidity { assets: vec![ native_asset(ntrn_denom.clone(), withdrawn_ntrn_amount), native_asset(paired_asset_denom.clone(), withdrawn_paired_asset_amount), ], - slippage_tolerance: Some(Decimal::percent(50)), + slippage_tolerance: Some(slippage_tolerance), auto_stake: None, receiver: None, })?, @@ -591,3 +622,106 @@ fn post_migration_balances_check_callback( Ok(Response::default()) } + +//-------------------------------------------------------------------------------------------------- +// Queries +//-------------------------------------------------------------------------------------------------- + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Config {} => to_binary(&query_config(deps)?), + QueryMsg::Stats {} => to_binary(&query_stats(deps)?), + QueryMsg::PauseInfo {} => query_paused(deps, env), + } +} + +pub fn query_paused(deps: Deps, env: Env) -> StdResult { + to_binary(&get_pause_info(deps, &env)?) +} + +pub fn query_config(deps: Deps) -> StdResult { + let config = CONFIG.load(deps.storage)?; + Ok(config) +} + +pub fn query_stats(deps: Deps) -> StdResult { + let total_distributed = TOTAL_DISTRIBUTED.load(deps.storage)?; + let total_reserved = TOTAL_RESERVED.load(deps.storage)?; + let total_processed_burned_coins = LAST_BURNED_COINS_AMOUNT.load(deps.storage)?; + + Ok(StatsResponse { + total_distributed, + total_reserved, + total_processed_burned_coins, + }) +} + +//-------------------------------------------------------------------------------------------------- +// Helpers +//-------------------------------------------------------------------------------------------------- + +pub fn create_distribution_response( + config: Config, + to_distribute: Uint128, + to_reserve: Uint128, + denom: String, +) -> StdResult { + let mut resp = Response::default(); + if !to_distribute.is_zero() { + let msg = CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: config.distribution_contract.to_string(), + funds: coins(to_distribute.u128(), denom.clone()), + msg: to_binary(&DistributeMsg::Fund {})?, + }); + resp = resp.add_message(msg) + } + + if !to_reserve.is_zero() { + let msg = CosmosMsg::Bank(BankMsg::Send { + to_address: config.treasury_contract.to_string(), + amount: coins(to_reserve.u128(), denom), + }); + resp = resp.add_message(msg); + } + + Ok(resp) +} + +//-------------------------------------------------------------------------------------------------- +// Migration +//-------------------------------------------------------------------------------------------------- + +/// Withdraws liquidity from Astroport xyk pairs and provides it to the concentrated liquidity ones. +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { + XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.save(deps.storage, &msg.max_slippage)?; + XYK_TO_CL_MIGRATION_NTRN_DENOM.save(deps.storage, &msg.ntrn_denom)?; + XYK_TO_CL_MIGRATION_ATOM_DENOM.save(deps.storage, &msg.atom_denom)?; + XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.save( + deps.storage, + &deps + .api + .addr_validate(msg.ntrn_atom_xyk_pair_address.as_str())?, + )?; + XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR.save( + deps.storage, + &deps + .api + .addr_validate(msg.ntrn_atom_cl_pair_address.as_str())?, + )?; + XYK_TO_CL_MIGRATION_USDC_DENOM.save(deps.storage, &msg.usdc_denom)?; + XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.save( + deps.storage, + &deps + .api + .addr_validate(msg.ntrn_usdc_xyk_pair_address.as_str())?, + )?; + XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR.save( + deps.storage, + &deps + .api + .addr_validate(msg.ntrn_usdc_cl_pair_address.as_str())?, + )?; + Ok(Response::default()) +} diff --git a/contracts/tokenomics/reserve/src/error.rs b/contracts/tokenomics/reserve/src/error.rs index 1a0958d7..bf7451c4 100644 --- a/contracts/tokenomics/reserve/src/error.rs +++ b/contracts/tokenomics/reserve/src/error.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{OverflowError, StdError, Uint128}; +use cosmwasm_std::{Decimal, OverflowError, StdError, Uint128}; use exec_control::pause::PauseError; use thiserror::Error; @@ -41,6 +41,25 @@ pub enum ContractError { final_balance: Uint128, }, + #[error( + "Amount {amount} to be withdrawn is greater that the max available amount {max_amount}" + )] + MigrationAmountUnavailable { + amount: Uint128, + max_amount: Uint128, + }, + + #[error( + "Provided slippage tolerance {slippage_tolerance} is more than the max allowed {max_slippage_tolerance}" + )] + MigrationSlippageToBig { + slippage_tolerance: Decimal, + max_slippage_tolerance: Decimal, + }, + + #[error("Migration from xyk pairs to CL ones is complete: nothing to migrate")] + MigrationComplete {}, + #[error("Overflow")] OverflowError(#[from] OverflowError), } diff --git a/contracts/tokenomics/reserve/src/msg.rs b/contracts/tokenomics/reserve/src/msg.rs index 786463c7..e6abf64b 100644 --- a/contracts/tokenomics/reserve/src/msg.rs +++ b/contracts/tokenomics/reserve/src/msg.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, CosmosMsg, Decimal, Env, StdResult, Uint128, WasmMsg}; +use cosmwasm_std::{to_binary, Addr, CosmosMsg, Decimal, Env, StdResult, Uint128, WasmMsg}; use cwd_macros::{pausable, pausable_query}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -41,6 +41,13 @@ pub enum ExecuteMsg { vesting_denominator: Option, }, + /// Processes either partial or full xyk->CL migration of contract's liquidity. + MigrateFromXykToCl { + slippage_tolerance: Option, + ntrn_atom_amount: Option, + ntrn_usdc_amount: Option, + }, + /// Callbacks; only callable by the contract itself. Callback(CallbackMsg), } @@ -49,8 +56,10 @@ pub enum ExecuteMsg { #[serde(rename_all = "snake_case")] pub enum CallbackMsg { MigrateLiquidityToClPair { - xyk_pair_address: String, - cl_pair_address: String, + xyk_pair_address: Addr, + amount: Uint128, + slippage_tolerance: Decimal, + cl_pair_address: Addr, ntrn_denom: String, paired_asset_denom: String, }, @@ -59,7 +68,8 @@ pub enum CallbackMsg { ntrn_init_balance: Uint128, paired_asset_denom: String, paired_asset_init_balance: Uint128, - cl_pair_address: String, + cl_pair_address: Addr, + slippage_tolerance: Decimal, }, PostMigrationBalancesCheck { ntrn_denom: String, @@ -107,6 +117,7 @@ pub enum DistributeMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct MigrateMsg { + pub max_slippage: Decimal, pub ntrn_denom: String, pub atom_denom: String, pub ntrn_atom_xyk_pair_address: String, diff --git a/contracts/tokenomics/reserve/src/state.rs b/contracts/tokenomics/reserve/src/state.rs index 689ff150..b02e8424 100644 --- a/contracts/tokenomics/reserve/src/state.rs +++ b/contracts/tokenomics/reserve/src/state.rs @@ -55,6 +55,24 @@ pub const CONFIG: Item = Item::new("config"); /// The height the contract is paused until. If it's None, the contract is not paused. pub const PAUSED_UNTIL: Item> = Item::new("paused_until"); +/// The maximum allowed slippage tolerance for xyk to CL liquidity migration calls. +pub const XYK_TO_CL_MIGRATION_MAX_SLIPPAGE: Item = + Item::new("xyk_to_cl_migration_max_slippage"); +pub const XYK_TO_CL_MIGRATION_NTRN_DENOM: Item = + Item::new("xyk_to_cl_migration_ntrn_denom"); +pub const XYK_TO_CL_MIGRATION_ATOM_DENOM: Item = + Item::new("xyk_to_cl_migration_atom_denom"); +pub const XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR: Item = + Item::new("xyk_to_cl_migration_ntrn_atom_xyk_pair"); +pub const XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR: Item = + Item::new("xyk_to_cl_migration_ntrn_atom_cl_pair"); +pub const XYK_TO_CL_MIGRATION_USDC_DENOM: Item = + Item::new("xyk_to_cl_migration_usdc_denom"); +pub const XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR: Item = + Item::new("xyk_to_cl_migration_ntrn_usdc_xyk_pair"); +pub const XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR: Item = + Item::new("xyk_to_cl_migration_ntrn_usdc_cl_pair"); + #[cfg(test)] mod tests { use super::Config; From 0c74e0fe4ad92cbb8842ce924a82b584d83652e1 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Thu, 15 Jun 2023 14:29:10 +0300 Subject: [PATCH 08/23] prettify migration config and reuse lp token addr --- contracts/tokenomics/reserve/src/contract.rs | 122 ++++++++----------- contracts/tokenomics/reserve/src/msg.rs | 15 +-- contracts/tokenomics/reserve/src/state.rs | 33 +++-- 3 files changed, 77 insertions(+), 93 deletions(-) diff --git a/contracts/tokenomics/reserve/src/contract.rs b/contracts/tokenomics/reserve/src/contract.rs index f54a08ea..7cb89fbe 100644 --- a/contracts/tokenomics/reserve/src/contract.rs +++ b/contracts/tokenomics/reserve/src/contract.rs @@ -4,12 +4,8 @@ use crate::msg::{ CallbackMsg, DistributeMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, StatsResponse, }; use crate::state::{ - Config, CONFIG, LAST_BURNED_COINS_AMOUNT, LAST_DISTRIBUTION_TIME, PAUSED_UNTIL, - TOTAL_DISTRIBUTED, TOTAL_RESERVED, XYK_TO_CL_MIGRATION_ATOM_DENOM, - XYK_TO_CL_MIGRATION_MAX_SLIPPAGE, XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR, - XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR, XYK_TO_CL_MIGRATION_NTRN_DENOM, - XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR, XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR, - XYK_TO_CL_MIGRATION_USDC_DENOM, + Config, XykToClMigrationConfig, CONFIG, LAST_BURNED_COINS_AMOUNT, LAST_DISTRIBUTION_TIME, + PAUSED_UNTIL, TOTAL_DISTRIBUTED, TOTAL_RESERVED, XYK_TO_CL_MIGRATION_CONFIG, }; use crate::vesting::{ get_burned_coins, safe_burned_coins_for_period, update_distribution_stats, vesting_function, @@ -324,10 +320,22 @@ fn execute_migrate_from_xyk_to_cl( ntrn_atom_amount: Option, ntrn_usdc_amount: Option, ) -> Result { + let migration_config: XykToClMigrationConfig = XYK_TO_CL_MIGRATION_CONFIG.load(deps.storage)?; + + // get pairs LP token addresses + let ntrn_atom_pair_info: PairInfo = deps.querier.query_wasm_smart( + migration_config.ntrn_atom_xyk_pair.clone(), + &PairQueryMsg::Pair {}, + )?; + let ntrn_usdc_pair_info: PairInfo = deps.querier.query_wasm_smart( + migration_config.ntrn_usdc_xyk_pair.clone(), + &PairQueryMsg::Pair {}, + )?; + // query max available amounts to be withdrawn from both pairs let max_available_ntrn_atom_amount = { let resp: BalanceResponse = deps.querier.query_wasm_smart( - XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.load(deps.storage)?, + ntrn_atom_pair_info.liquidity_token.clone(), &Cw20QueryMsg::Balance { address: env.contract.address.to_string(), }, @@ -336,7 +344,7 @@ fn execute_migrate_from_xyk_to_cl( }; let max_available_ntrn_usdc_amount = { let resp: BalanceResponse = deps.querier.query_wasm_smart( - XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.load(deps.storage)?, + ntrn_usdc_pair_info.liquidity_token.clone(), &Cw20QueryMsg::Balance { address: env.contract.address.to_string(), }, @@ -364,38 +372,30 @@ fn execute_migrate_from_xyk_to_cl( }); } } - let max_slippage_tolerance = XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.load(deps.storage)?; if let Some(slippage_tolerance) = slippage_tolerance { - if slippage_tolerance.gt(&max_slippage_tolerance) { + if slippage_tolerance.gt(&migration_config.max_slippage) { return Err(ContractError::MigrationSlippageToBig { slippage_tolerance, - max_slippage_tolerance, + max_slippage_tolerance: migration_config.max_slippage, }); } } - let ntrn_denom = XYK_TO_CL_MIGRATION_NTRN_DENOM.load(deps.storage)?; let ntrn_atom_amount = ntrn_atom_amount.unwrap_or(max_available_ntrn_atom_amount); let ntrn_usdc_amount = ntrn_usdc_amount.unwrap_or(max_available_ntrn_usdc_amount); - let ntrn_atom_xyk_pair_address = XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.load(deps.storage)?; - let ntrn_atom_cl_pair_address = XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR.load(deps.storage)?; - let atom_denom = XYK_TO_CL_MIGRATION_ATOM_DENOM.load(deps.storage)?; - let ntrn_usdc_xyk_pair_address = XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.load(deps.storage)?; - let ntrn_usdc_cl_pair_address = XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR.load(deps.storage)?; - let usdc_denom = XYK_TO_CL_MIGRATION_USDC_DENOM.load(deps.storage)?; - let slippage_tolerance = - slippage_tolerance.unwrap_or(XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.load(deps.storage)?); + let slippage_tolerance = slippage_tolerance.unwrap_or(migration_config.max_slippage); let mut resp = Response::default(); if !ntrn_atom_amount.is_zero() { resp = resp.add_message( CallbackMsg::MigrateLiquidityToClPair { - ntrn_denom: ntrn_denom.clone(), + ntrn_denom: migration_config.ntrn_denom.clone(), amount: ntrn_atom_amount, slippage_tolerance, - xyk_pair_address: ntrn_atom_xyk_pair_address, - cl_pair_address: ntrn_atom_cl_pair_address, - paired_asset_denom: atom_denom, + xyk_pair: migration_config.ntrn_atom_xyk_pair, + xyk_lp_token: ntrn_atom_pair_info.liquidity_token, + cl_pair: migration_config.ntrn_atom_cl_pair, + paired_asset_denom: migration_config.atom_denom, } .to_cosmos_msg(&env)?, ); @@ -403,12 +403,13 @@ fn execute_migrate_from_xyk_to_cl( if !ntrn_usdc_amount.is_zero() { resp = resp.add_message( CallbackMsg::MigrateLiquidityToClPair { - ntrn_denom, + ntrn_denom: migration_config.ntrn_denom, amount: ntrn_usdc_amount, slippage_tolerance, - xyk_pair_address: ntrn_usdc_xyk_pair_address, - cl_pair_address: ntrn_usdc_cl_pair_address, - paired_asset_denom: usdc_denom, + xyk_pair: migration_config.ntrn_usdc_xyk_pair, + xyk_lp_token: ntrn_usdc_pair_info.liquidity_token, + cl_pair: migration_config.ntrn_usdc_cl_pair, + paired_asset_denom: migration_config.usdc_denom, } .to_cosmos_msg(&env)?, ); @@ -429,19 +430,21 @@ fn _handle_callback( } match msg { CallbackMsg::MigrateLiquidityToClPair { - xyk_pair_address, + xyk_pair, + xyk_lp_token, amount, slippage_tolerance, - cl_pair_address, + cl_pair, ntrn_denom, paired_asset_denom, } => migrate_liquidity_to_cl_pair_callback( deps, env, - xyk_pair_address, + xyk_pair, + xyk_lp_token, amount, slippage_tolerance, - cl_pair_address, + cl_pair, ntrn_denom, paired_asset_denom, ), @@ -450,7 +453,7 @@ fn _handle_callback( ntrn_init_balance, paired_asset_denom, paired_asset_init_balance, - cl_pair_address, + cl_pair: cl_pair_address, slippage_tolerance, } => provide_liquidity_to_cl_pair_after_withdrawal_callback( deps, @@ -482,10 +485,11 @@ fn _handle_callback( fn migrate_liquidity_to_cl_pair_callback( deps: DepsMut, env: Env, - xyk_pair_address: Addr, + xyk_pair: Addr, + xyk_lp_token: Addr, amount: Uint128, slippage_tolerance: Decimal, - cl_pair_address: Addr, + cl_pair: Addr, ntrn_denom: String, paired_asset_denom: String, ) -> Result { @@ -498,17 +502,12 @@ fn migrate_liquidity_to_cl_pair_callback( .query_balance(env.contract.address.to_string(), paired_asset_denom.clone())? .amount; - // get the pair LP token address and contract's balance - let pair_info: PairInfo = deps - .querier - .query_wasm_smart(xyk_pair_address.clone(), &PairQueryMsg::Pair {})?; - let msgs: Vec = vec![ // push message to withdraw liquidity from the xyk pair CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: pair_info.liquidity_token.to_string(), + contract_addr: xyk_lp_token.to_string(), msg: to_binary(&Cw20ExecuteMsg::Send { - contract: xyk_pair_address.to_string(), + contract: xyk_pair.to_string(), amount, msg: to_binary(&PairCw20HookMsg::WithdrawLiquidity { assets: vec![] })?, })?, @@ -520,7 +519,7 @@ fn migrate_liquidity_to_cl_pair_callback( ntrn_init_balance, paired_asset_denom, paired_asset_init_balance, - cl_pair_address, + cl_pair, slippage_tolerance, } .to_cosmos_msg(&env)?, @@ -695,33 +694,18 @@ pub fn create_distribution_response( /// Withdraws liquidity from Astroport xyk pairs and provides it to the concentrated liquidity ones. #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { - XYK_TO_CL_MIGRATION_MAX_SLIPPAGE.save(deps.storage, &msg.max_slippage)?; - XYK_TO_CL_MIGRATION_NTRN_DENOM.save(deps.storage, &msg.ntrn_denom)?; - XYK_TO_CL_MIGRATION_ATOM_DENOM.save(deps.storage, &msg.atom_denom)?; - XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR.save( - deps.storage, - &deps - .api - .addr_validate(msg.ntrn_atom_xyk_pair_address.as_str())?, - )?; - XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR.save( - deps.storage, - &deps - .api - .addr_validate(msg.ntrn_atom_cl_pair_address.as_str())?, - )?; - XYK_TO_CL_MIGRATION_USDC_DENOM.save(deps.storage, &msg.usdc_denom)?; - XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR.save( - deps.storage, - &deps - .api - .addr_validate(msg.ntrn_usdc_xyk_pair_address.as_str())?, - )?; - XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR.save( + XYK_TO_CL_MIGRATION_CONFIG.save( deps.storage, - &deps - .api - .addr_validate(msg.ntrn_usdc_cl_pair_address.as_str())?, + &XykToClMigrationConfig { + max_slippage: msg.max_slippage, + ntrn_denom: msg.ntrn_denom, + atom_denom: msg.atom_denom, + ntrn_atom_xyk_pair: deps.api.addr_validate(msg.ntrn_atom_xyk_pair.as_str())?, + ntrn_atom_cl_pair: deps.api.addr_validate(msg.ntrn_atom_cl_pair.as_str())?, + usdc_denom: msg.usdc_denom, + ntrn_usdc_xyk_pair: deps.api.addr_validate(msg.ntrn_usdc_xyk_pair.as_str())?, + ntrn_usdc_cl_pair: deps.api.addr_validate(msg.ntrn_usdc_cl_pair.as_str())?, + }, )?; Ok(Response::default()) } diff --git a/contracts/tokenomics/reserve/src/msg.rs b/contracts/tokenomics/reserve/src/msg.rs index e6abf64b..f33bd487 100644 --- a/contracts/tokenomics/reserve/src/msg.rs +++ b/contracts/tokenomics/reserve/src/msg.rs @@ -56,10 +56,11 @@ pub enum ExecuteMsg { #[serde(rename_all = "snake_case")] pub enum CallbackMsg { MigrateLiquidityToClPair { - xyk_pair_address: Addr, + xyk_pair: Addr, + xyk_lp_token: Addr, amount: Uint128, slippage_tolerance: Decimal, - cl_pair_address: Addr, + cl_pair: Addr, ntrn_denom: String, paired_asset_denom: String, }, @@ -68,7 +69,7 @@ pub enum CallbackMsg { ntrn_init_balance: Uint128, paired_asset_denom: String, paired_asset_init_balance: Uint128, - cl_pair_address: Addr, + cl_pair: Addr, slippage_tolerance: Decimal, }, PostMigrationBalancesCheck { @@ -120,9 +121,9 @@ pub struct MigrateMsg { pub max_slippage: Decimal, pub ntrn_denom: String, pub atom_denom: String, - pub ntrn_atom_xyk_pair_address: String, - pub ntrn_atom_cl_pair_address: String, + pub ntrn_atom_xyk_pair: String, + pub ntrn_atom_cl_pair: String, pub usdc_denom: String, - pub ntrn_usdc_xyk_pair_address: String, - pub ntrn_usdc_cl_pair_address: String, + pub ntrn_usdc_xyk_pair: String, + pub ntrn_usdc_cl_pair: String, } diff --git a/contracts/tokenomics/reserve/src/state.rs b/contracts/tokenomics/reserve/src/state.rs index b02e8424..b1394e15 100644 --- a/contracts/tokenomics/reserve/src/state.rs +++ b/contracts/tokenomics/reserve/src/state.rs @@ -44,6 +44,20 @@ impl Config { } } +/// Config for xyk->CL liquidity migration. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct XykToClMigrationConfig { + /// The maximum allowed slippage tolerance for xyk to CL liquidity migration calls. + pub max_slippage: Decimal, + pub ntrn_denom: String, + pub atom_denom: String, + pub ntrn_atom_xyk_pair: Addr, + pub ntrn_atom_cl_pair: Addr, + pub usdc_denom: String, + pub ntrn_usdc_xyk_pair: Addr, + pub ntrn_usdc_cl_pair: Addr, +} + pub const TOTAL_DISTRIBUTED: Item = Item::new("total_distributed"); pub const TOTAL_RESERVED: Item = Item::new("total_reserved"); @@ -55,23 +69,8 @@ pub const CONFIG: Item = Item::new("config"); /// The height the contract is paused until. If it's None, the contract is not paused. pub const PAUSED_UNTIL: Item> = Item::new("paused_until"); -/// The maximum allowed slippage tolerance for xyk to CL liquidity migration calls. -pub const XYK_TO_CL_MIGRATION_MAX_SLIPPAGE: Item = - Item::new("xyk_to_cl_migration_max_slippage"); -pub const XYK_TO_CL_MIGRATION_NTRN_DENOM: Item = - Item::new("xyk_to_cl_migration_ntrn_denom"); -pub const XYK_TO_CL_MIGRATION_ATOM_DENOM: Item = - Item::new("xyk_to_cl_migration_atom_denom"); -pub const XYK_TO_CL_MIGRATION_NTRN_ATOM_XYK_PAIR: Item = - Item::new("xyk_to_cl_migration_ntrn_atom_xyk_pair"); -pub const XYK_TO_CL_MIGRATION_NTRN_ATOM_CL_PAIR: Item = - Item::new("xyk_to_cl_migration_ntrn_atom_cl_pair"); -pub const XYK_TO_CL_MIGRATION_USDC_DENOM: Item = - Item::new("xyk_to_cl_migration_usdc_denom"); -pub const XYK_TO_CL_MIGRATION_NTRN_USDC_XYK_PAIR: Item = - Item::new("xyk_to_cl_migration_ntrn_usdc_xyk_pair"); -pub const XYK_TO_CL_MIGRATION_NTRN_USDC_CL_PAIR: Item = - Item::new("xyk_to_cl_migration_ntrn_usdc_cl_pair"); +pub const XYK_TO_CL_MIGRATION_CONFIG: Item = + Item::new("xyk_to_cl_migration_config"); #[cfg(test)] mod tests { From c3b200ec9a60c9bca1be6b834cc21851312c97ba Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 16 Jun 2023 11:48:33 +0300 Subject: [PATCH 09/23] improve MigrationAmountUnavailable error text --- contracts/tokenomics/reserve/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/tokenomics/reserve/src/error.rs b/contracts/tokenomics/reserve/src/error.rs index bf7451c4..366fedad 100644 --- a/contracts/tokenomics/reserve/src/error.rs +++ b/contracts/tokenomics/reserve/src/error.rs @@ -42,7 +42,7 @@ pub enum ContractError { }, #[error( - "Amount {amount} to be withdrawn is greater that the max available amount {max_amount}" + "Amount to be migrated is greater that the max available amount: {amount} > {max_amount}" )] MigrationAmountUnavailable { amount: Uint128, From 366110602e5b2a26c19b463cb5ff5f40a83280de Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Fri, 16 Jun 2023 17:44:18 +0300 Subject: [PATCH 10/23] wip --- Cargo.lock | 32 ++--- .../dao/voting/lockdrop-vault/src/contract.rs | 49 ++++--- .../dao/voting/lockdrop-vault/src/state.rs | 3 +- .../dao/voting/lockdrop-vault/src/tests.rs | 46 ++++++- .../dao/voting/vesting-lp-vault/Cargo.toml | 1 + .../voting/vesting-lp-vault/src/contract.rs | 66 ++++++--- .../dao/voting/vesting-lp-vault/src/state.rs | 3 +- .../dao/voting/vesting-lp-vault/src/tests.rs | 127 +++++++++++++----- packages/neutron-lockdrop-vault/Cargo.toml | 1 + packages/neutron-lockdrop-vault/src/msg.rs | 5 +- packages/neutron-lockdrop-vault/src/types.rs | 24 +++- .../src/voting_power.rs | 40 ++++-- packages/neutron-oracle/Cargo.toml | 2 +- packages/neutron-oracle/src/voting_power.rs | 49 ++++--- packages/neutron-vesting-lp-vault/src/msg.rs | 17 ++- .../neutron-vesting-lp-vault/src/types.rs | 25 +++- 16 files changed, 343 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4fa7386..44830cdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -47,8 +47,8 @@ dependencies = [ [[package]] name = "astroport" -version = "2.5.0" -source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.5.0#65ce7d1879cc5d95b09fa14202f0423bba52ae0e" +version = "2.7.1" +source = "git+https://github.com/astroport-fi/astroport-core.git?branch=main#c73a2db3c0b4f069e906d90970e1b72a5cf71bbf" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "astroport-periphery" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ - "astroport 2.5.0", + "astroport 2.7.1", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", @@ -274,7 +274,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-controllers 1.0.1", - "cw-multi-test 0.16.5", + "cw-multi-test 0.16.4", "cw-paginate 0.2.0", "cw-storage-plus 1.0.1", "cw-utils 1.0.1", @@ -434,9 +434,9 @@ dependencies = [ [[package]] name = "cw-multi-test" -version = "0.16.5" +version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" +checksum = "2a18afd2e201221c6d72a57f0886ef2a22151bbc9e6db7af276fde8a91081042" dependencies = [ "anyhow", "cosmwasm-std", @@ -1367,7 +1367,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-controllers 1.0.1", - "cw-multi-test 0.16.5", + "cw-multi-test 0.16.4", "cw-paginate 0.2.0", "cw-storage-plus 1.0.1", "cw-utils 1.0.1", @@ -1464,6 +1464,7 @@ dependencies = [ name = "neutron-lockdrop-vault" version = "0.1.0" dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "astroport-periphery", "cosmwasm-std", "cwd-macros", @@ -1477,7 +1478,7 @@ dependencies = [ name = "neutron-oracle" version = "0.1.0" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.8.0", "cosmwasm-std", ] @@ -1861,7 +1862,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-controllers 1.0.1", - "cw-multi-test 0.16.5", + "cw-multi-test 0.16.4", "cw-storage-plus 1.0.1", "cw-utils 1.0.1", "neutron-sdk 0.4.0", @@ -2197,7 +2198,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema", @@ -2213,7 +2214,7 @@ dependencies = [ [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", "cosmwasm-schema", @@ -2229,7 +2230,7 @@ dependencies = [ [[package]] name = "vesting-lp" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#20790b78175b41c3ccbabce2c296c4c605d07946" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema", @@ -2244,6 +2245,7 @@ name = "vesting-lp-vault" version = "0.1.0" dependencies = [ "anyhow", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test 0.13.4", diff --git a/contracts/dao/voting/lockdrop-vault/src/contract.rs b/contracts/dao/voting/lockdrop-vault/src/contract.rs index 028d3f1b..bd2328b0 100644 --- a/contracts/dao/voting/lockdrop-vault/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault/src/contract.rs @@ -9,7 +9,7 @@ use cwd_interface::voting::{ }; use neutron_lockdrop_vault::voting_power::{get_voting_power_for_address, get_voting_power_total}; -use crate::state::{CONFIG, DAO}; +use crate::state::{CONFIG, DAO, OLD_CONFIG}; use astroport_periphery::lockdrop::PoolType; use neutron_lockdrop_vault::error::{ContractError, ContractResult}; @@ -34,8 +34,8 @@ pub fn instantiate( name: msg.name, description: msg.description, lockdrop_contract: deps.api.addr_validate(&msg.lockdrop_contract)?, - oracle_usdc_contract: deps.api.addr_validate(&msg.oracle_usdc_contract)?, - oracle_atom_contract: deps.api.addr_validate(&msg.oracle_atom_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.oracle_usdc_contract)?, + atom_cl_pool_contract: deps.api.addr_validate(&msg.oracle_atom_contract)?, owner, }; config.validate()?; @@ -48,8 +48,8 @@ pub fn instantiate( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) - .add_attribute("oracle_usdc_contract", config.oracle_usdc_contract) - .add_attribute("oracle_atom_contract", config.oracle_atom_contract)) + .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) + .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -135,10 +135,10 @@ pub fn execute_update_config( config.lockdrop_contract = lockdrop_contract; } if let Some(oracle_contract) = new_oracle_usdc_contract { - config.oracle_usdc_contract = oracle_contract; + config.usdc_cl_pool_contract = oracle_contract; } if let Some(oracle_contract) = new_oracle_atom_contract { - config.oracle_atom_contract = oracle_contract; + config.atom_cl_pool_contract = oracle_contract; } if let Some(name) = new_name { config.name = name; @@ -155,8 +155,8 @@ pub fn execute_update_config( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) - .add_attribute("oracle_usdc_contract", config.oracle_usdc_contract) - .add_attribute("oracle_atom_contract", config.oracle_atom_contract)) + .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) + .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -195,8 +195,8 @@ pub fn query_voting_power_at_height( let atom_power = get_voting_power_for_address( deps, config.lockdrop_contract.as_ref(), - config.oracle_usdc_contract.as_ref(), - config.oracle_atom_contract.as_ref(), + config.usdc_cl_pool_contract.as_ref(), + config.atom_cl_pool_contract.as_ref(), PoolType::ATOM, address.clone(), height, @@ -204,8 +204,8 @@ pub fn query_voting_power_at_height( let usdc_power = get_voting_power_for_address( deps, config.lockdrop_contract, - config.oracle_usdc_contract, - config.oracle_atom_contract, + config.usdc_cl_pool_contract, + config.atom_cl_pool_contract, PoolType::USDC, address, height, @@ -231,16 +231,16 @@ pub fn query_total_power_at_height( let atom_power = get_voting_power_total( deps, config.lockdrop_contract.as_ref(), - config.oracle_usdc_contract.as_ref(), - config.oracle_atom_contract.as_ref(), + config.usdc_cl_pool_contract.as_ref(), + config.atom_cl_pool_contract.as_ref(), PoolType::ATOM, height, )?; let usdc_power = get_voting_power_total( deps, config.lockdrop_contract, - config.oracle_usdc_contract, - config.oracle_atom_contract, + config.usdc_cl_pool_contract, + config.atom_cl_pool_contract, PoolType::USDC, height, )?; @@ -296,7 +296,20 @@ pub fn query_bonding_status( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { +pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> ContractResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let old_config = OLD_CONFIG.load(deps.storage)?; + let new_config = Config { + name: old_config.name, + description: old_config.description, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, + owner: old_config.owner, + lockdrop_contract: old_config.lockdrop_contract, + }; + + CONFIG.save(deps.storage, &new_config)?; + Ok(Response::default()) } diff --git a/contracts/dao/voting/lockdrop-vault/src/state.rs b/contracts/dao/voting/lockdrop-vault/src/state.rs index c3b2cc19..9b3a5df7 100644 --- a/contracts/dao/voting/lockdrop-vault/src/state.rs +++ b/contracts/dao/voting/lockdrop-vault/src/state.rs @@ -1,6 +1,7 @@ use cosmwasm_std::Addr; use cw_storage_plus::Item; -use neutron_lockdrop_vault::types::Config; +use neutron_lockdrop_vault::types::{Config, OldConfig}; pub const CONFIG: Item = Item::new("config"); +pub const OLD_CONFIG: Item = Item::new("config"); pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/lockdrop-vault/src/tests.rs b/contracts/dao/voting/lockdrop-vault/src/tests.rs index 93430499..0dd4faa7 100644 --- a/contracts/dao/voting/lockdrop-vault/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault/src/tests.rs @@ -1,4 +1,5 @@ use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; +use crate::state::{CONFIG, OLD_CONFIG}; use astroport::asset::AssetInfo; use astroport::oracle::QueryMsg as OracleQueryMsg; use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; @@ -13,7 +14,7 @@ use cwd_interface::voting::{ }; use neutron_lockdrop_vault::error::ContractError; use neutron_lockdrop_vault::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use neutron_lockdrop_vault::types::Config; +use neutron_lockdrop_vault::types::{Config, OldConfig}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -28,6 +29,8 @@ const ORACLE_ATOM_ADDR: &str = "oracle_atom"; const NEW_LOCKDROP_ADDR: &str = "new_lockdrop"; const NEW_ORACLE_USDC_ADDR: &str = "new_oracle_usdc"; const NEW_ORACLE_ATOM_ADDR: &str = "new_oracle_atom"; +const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; +const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -425,8 +428,8 @@ fn test_update_config_as_owner() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), lockdrop_contract: Addr::unchecked(NEW_LOCKDROP_ADDR), - oracle_usdc_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), - oracle_atom_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), }, config ); @@ -567,8 +570,8 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), - oracle_usdc_contract: Addr::unchecked(ORACLE_USDC_ADDR), - oracle_atom_contract: Addr::unchecked(ORACLE_ATOM_ADDR), + usdc_cl_pool_contract: Addr::unchecked(ORACLE_USDC_ADDR), + atom_cl_pool_contract: Addr::unchecked(ORACLE_ATOM_ADDR), } ) } @@ -631,8 +634,39 @@ fn test_total_power_at_height() { pub fn test_migrate_update_version() { let mut deps = mock_dependencies(); cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); - migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); + + let old_config = OldConfig { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), + oracle_usdc_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), + oracle_atom_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), + owner: Addr::unchecked(DAO_ADDR.to_string()), + }; + OLD_CONFIG.save(&mut deps.storage, &old_config).unwrap(); + + let new_config = Config { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: Addr::unchecked(DAO_ADDR.to_string()), + atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR.to_string()), + usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR.to_string()), + lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), + }; + + migrate( + deps.as_mut(), + mock_env(), + MigrateMsg { + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + }, + ) + .unwrap(); let version = cw2::get_contract_version(&deps.storage).unwrap(); + let config = CONFIG.load(&deps.storage).unwrap(); + + assert_eq!(new_config, config); assert_eq!(version.version, CONTRACT_VERSION); assert_eq!(version.contract, CONTRACT_NAME); } diff --git a/contracts/dao/voting/vesting-lp-vault/Cargo.toml b/contracts/dao/voting/vesting-lp-vault/Cargo.toml index 25467711..ef723da0 100644 --- a/contracts/dao/voting/vesting-lp-vault/Cargo.toml +++ b/contracts/dao/voting/vesting-lp-vault/Cargo.toml @@ -28,6 +28,7 @@ neutron-vesting-lp-vault = { path = "../../../../packages/neutron-vesting-lp-vau neutron-oracle = { path = "../../../../packages/neutron-oracle" } vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } diff --git a/contracts/dao/voting/vesting-lp-vault/src/contract.rs b/contracts/dao/voting/vesting-lp-vault/src/contract.rs index a3d7eb22..47df86aa 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/contract.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/contract.rs @@ -1,3 +1,4 @@ +use astroport::asset::AssetInfo; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -10,7 +11,7 @@ use cwd_interface::voting::{ }; use serde::Serialize; -use crate::state::{CONFIG, DAO}; +use crate::state::{CONFIG, DAO, OLD_CONFIG}; use neutron_oracle::voting_power::voting_power_from_lp_tokens; use neutron_vesting_lp_vault::{ error::{ContractError, ContractResult}, @@ -18,6 +19,7 @@ use neutron_vesting_lp_vault::{ types::Config, }; use vesting_base::msg::{QueryMsg as VestingLpQueryMsg, QueryMsgHistorical}; +use vesting_base::types::Config as VestingBaseConfig; pub(crate) const CONTRACT_NAME: &str = "crates.io:neutron-vesting-lp-vault"; pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -37,9 +39,9 @@ pub fn instantiate( name: msg.name, description: msg.description, atom_vesting_lp_contract: deps.api.addr_validate(&msg.atom_vesting_lp_contract)?, - atom_oracle_contract: deps.api.addr_validate(&msg.atom_oracle_contract)?, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, usdc_vesting_lp_contract: deps.api.addr_validate(&msg.usdc_vesting_lp_contract)?, - usdc_oracle_contract: deps.api.addr_validate(&msg.usdc_oracle_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, owner, }; config.validate()?; @@ -52,9 +54,9 @@ pub fn instantiate( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) - .add_attribute("atom_oracle_contract", config.atom_oracle_contract) + .add_attribute("atom_cl_pool_contract", config.atom_cl_pool_contract) .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) - .add_attribute("usdc_oracle_contract", config.usdc_oracle_contract)) + .add_attribute("usdc_cl_pool_contract", config.usdc_cl_pool_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -70,9 +72,9 @@ pub fn execute( ExecuteMsg::UpdateConfig { owner, atom_vesting_lp_contract, - atom_oracle_contract, + atom_cl_pool_contract: atom_oracle_contract, usdc_vesting_lp_contract, - usdc_oracle_contract, + usdc_cl_pool_contract: usdc_oracle_contract, name, description, } => execute_update_config( @@ -127,9 +129,9 @@ pub fn execute_update_config( config.owner = new_owner; config.atom_vesting_lp_contract = new_atom_vesting_lp_contract; - config.atom_oracle_contract = new_atom_oracle_contract; + config.atom_cl_pool_contract = new_atom_oracle_contract; config.usdc_vesting_lp_contract = new_usdc_vesting_lp_contract; - config.usdc_oracle_contract = new_usdc_oracle_contract; + config.usdc_cl_pool_contract = new_usdc_oracle_contract; config.name = new_name; config.description = new_description; config.validate()?; @@ -140,9 +142,9 @@ pub fn execute_update_config( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) - .add_attribute("atom_oracle_contract", config.atom_oracle_contract) + .add_attribute("atom_oracle_contract", config.atom_cl_pool_contract) .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) - .add_attribute("usdc_oracle_contract", config.usdc_oracle_contract)) + .add_attribute("usdc_oracle_contract", config.usdc_cl_pool_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -175,22 +177,40 @@ fn get_voting_power( query_msg: &impl Serialize, ) -> ContractResult { let mut voting_power = Decimal256::zero(); - for (vesting_lp, oracle) in [ + for (vesting_lp, cl_pool) in [ ( &config.atom_vesting_lp_contract, - &config.atom_oracle_contract, + &config.atom_cl_pool_contract, ), ( &config.usdc_vesting_lp_contract, - &config.usdc_oracle_contract, + &config.usdc_cl_pool_contract, ), ] { + let vesting_base_config: VestingBaseConfig = deps + .querier + .query_wasm_smart(vesting_lp, &VestingLpQueryMsg::Config {})?; + let lp_token_address: AssetInfo = if vesting_base_config.vesting_token.is_some() { + vesting_base_config.vesting_token.unwrap() + } else { + return Err(ContractError::Std(StdError::generic_err(format!( + "vesting token is not set in {:?} contract", + vesting_lp + )))); + }; + + let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( + lp_token_address.to_string(), + &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, + )?; + voting_power += voting_power_from_lp_tokens( deps, deps.querier .query_wasm_smart::>(vesting_lp, &query_msg)? .unwrap_or_default(), - oracle, + lp_total_supply, + cl_pool, height, )?; } @@ -281,7 +301,21 @@ pub fn query_bonding_status( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { +pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> ContractResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let old_config = OLD_CONFIG.load(deps.storage)?; + let new_config = Config { + name: old_config.name, + description: old_config.description, + atom_vesting_lp_contract: old_config.atom_vesting_lp_contract, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool)?, + usdc_vesting_lp_contract: old_config.usdc_vesting_lp_contract, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool)?, + owner: old_config.owner, + }; + + CONFIG.save(deps.storage, &new_config)?; + Ok(Response::default()) } diff --git a/contracts/dao/voting/vesting-lp-vault/src/state.rs b/contracts/dao/voting/vesting-lp-vault/src/state.rs index 1638b96d..6ed3cba3 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/state.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/state.rs @@ -1,6 +1,7 @@ use cosmwasm_std::Addr; use cw_storage_plus::Item; -use neutron_vesting_lp_vault::types::Config; +use neutron_vesting_lp_vault::types::{Config, OldConfig}; +pub const OLD_CONFIG: Item = Item::new("config"); pub const CONFIG: Item = Item::new("config"); pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/vesting-lp-vault/src/tests.rs b/contracts/dao/voting/vesting-lp-vault/src/tests.rs index fc141c09..792a3b80 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/tests.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/tests.rs @@ -1,10 +1,13 @@ use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; +use crate::state::{CONFIG, OLD_CONFIG}; +use astroport::asset::AssetInfo; use cosmwasm_std::testing::{mock_dependencies, mock_env}; use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; use cwd_interface::voting::{ InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, }; +use neutron_vesting_lp_vault::types::OldConfig; use neutron_vesting_lp_vault::{ msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, types::Config, @@ -23,6 +26,8 @@ const NEW_ATOM_VESTING_LP_ADDR: &str = "new_atom_vesting_lp"; const NEW_USDC_VESTING_LP_ADDR: &str = "new_usdc_vesting_lp"; const NEW_ATOM_ORACLE_ADDR: &str = "new_atom_oracle"; const NEW_USDC_ORACLE_ADDR: &str = "new_usdc_oracle"; +const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; +const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -91,6 +96,21 @@ fn instantiate_vesting_lp(app: &mut App, id: u64, msg: vesting_lp::msg::Instanti .unwrap() } +fn set_vesting_token( + app: &mut App, + sender: Addr, + vesting_contract: Addr, + vesting_token: AssetInfo, +) { + app.execute_contract( + sender, + vesting_contract, + &vesting_base::msg::ExecuteMsg::SetVestingToken { vesting_token }, + &[], + ) + .unwrap(); +} + fn bond_tokens( app: &mut App, contract_addr: Addr, @@ -141,9 +161,9 @@ fn update_config( &ExecuteMsg::UpdateConfig { owner, atom_vesting_lp_contract, - atom_oracle_contract, + atom_cl_pool_contract: atom_oracle_contract, usdc_vesting_lp_contract, - usdc_oracle_contract, + usdc_cl_pool_contract: usdc_oracle_contract, name, description, }, @@ -200,9 +220,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -216,9 +236,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -237,9 +257,9 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -260,9 +280,9 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -282,9 +302,9 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -316,9 +336,9 @@ fn test_update_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -344,9 +364,9 @@ fn test_update_config() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), atom_vesting_lp_contract: Addr::unchecked(NEW_ATOM_VESTING_LP_ADDR), - atom_oracle_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), usdc_vesting_lp_contract: Addr::unchecked(NEW_USDC_VESTING_LP_ADDR), - usdc_oracle_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), }, config ); @@ -365,9 +385,9 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -400,9 +420,9 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -434,9 +454,9 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -457,9 +477,9 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -480,9 +500,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -494,9 +514,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR), - atom_oracle_contract: Addr::unchecked(ATOM_ORACLE_ADDR), + atom_cl_pool_contract: Addr::unchecked(ATOM_ORACLE_ADDR), usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR), - usdc_oracle_contract: Addr::unchecked(USDC_ORACLE_ADDR), + usdc_cl_pool_contract: Addr::unchecked(USDC_ORACLE_ADDR), } ) } @@ -534,9 +554,9 @@ fn test_voting_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -569,6 +589,15 @@ fn test_total_power_at_height() { }, ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + usdc_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: Addr::unchecked("usdc"), + }, + ); + let vault_id = app.store_code(vault_contract()); let addr = instantiate_vault( &mut app, @@ -578,9 +607,9 @@ fn test_total_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -593,8 +622,40 @@ fn test_total_power_at_height() { pub fn test_migrate_update_version() { let mut deps = mock_dependencies(); cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); - migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); + + let old_config = OldConfig { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: Addr::unchecked(DAO_ADDR.to_string()), + atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR.to_string()), + atom_oracle_contract: Addr::unchecked(ATOM_ORACLE_ADDR.to_string()), + usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR.to_string()), + usdc_oracle_contract: Addr::unchecked(USDC_ORACLE_ADDR.to_string()), + }; + OLD_CONFIG.save(&mut deps.storage, &old_config).unwrap(); + + let new_config = Config { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: Addr::unchecked(DAO_ADDR.to_string()), + atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR.to_string()), + atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR.to_string()), + usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR.to_string()), + usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR.to_string()), + }; + + migrate( + deps.as_mut(), + mock_env(), + MigrateMsg { + atom_cl_pool: ATOM_CL_POOL_ADDR.to_string(), + usdc_cl_pool: USDC_CL_POOL_ADDR.to_string(), + }, + ) + .unwrap(); let version = cw2::get_contract_version(&deps.storage).unwrap(); + let config = CONFIG.load(&deps.storage).unwrap(); assert_eq!(version.version, CONTRACT_VERSION); assert_eq!(version.contract, CONTRACT_NAME); + assert_eq!(config, new_config); } diff --git a/packages/neutron-lockdrop-vault/Cargo.toml b/packages/neutron-lockdrop-vault/Cargo.toml index 77d2d05a..3d576f90 100644 --- a/packages/neutron-lockdrop-vault/Cargo.toml +++ b/packages/neutron-lockdrop-vault/Cargo.toml @@ -14,3 +14,4 @@ serde = { version = "1.0.147", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } neutron-oracle = { path = "../neutron-oracle" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } diff --git a/packages/neutron-lockdrop-vault/src/msg.rs b/packages/neutron-lockdrop-vault/src/msg.rs index b429bea3..e00c210d 100644 --- a/packages/neutron-lockdrop-vault/src/msg.rs +++ b/packages/neutron-lockdrop-vault/src/msg.rs @@ -42,4 +42,7 @@ pub enum QueryMsg { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct MigrateMsg {} +pub struct MigrateMsg { + pub atom_cl_pool_contract: String, + pub usdc_cl_pool_contract: String, +} diff --git a/packages/neutron-lockdrop-vault/src/types.rs b/packages/neutron-lockdrop-vault/src/types.rs index 1df6066f..ee515c97 100644 --- a/packages/neutron-lockdrop-vault/src/types.rs +++ b/packages/neutron-lockdrop-vault/src/types.rs @@ -4,7 +4,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct Config { +pub struct OldConfig { pub name: String, pub description: String, pub lockdrop_contract: Addr, @@ -13,6 +13,16 @@ pub struct Config { pub owner: Addr, } +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] +pub struct Config { + pub name: String, + pub description: String, + pub lockdrop_contract: Addr, + pub usdc_cl_pool_contract: Addr, + pub atom_cl_pool_contract: Addr, + pub owner: Addr, +} + impl Config { /// checks whether the config fields are valid. pub fn validate(&self) -> Result<(), ContractError> { @@ -38,8 +48,8 @@ mod tests { name: String::from("name"), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), - oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg_ok.validate(), Ok(())); @@ -48,8 +58,8 @@ mod tests { name: String::from(""), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), - oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!( @@ -61,8 +71,8 @@ mod tests { name: String::from("name"), description: String::from(""), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), - oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!( diff --git a/packages/neutron-lockdrop-vault/src/voting_power.rs b/packages/neutron-lockdrop-vault/src/voting_power.rs index 8ebc8148..a37a877d 100644 --- a/packages/neutron-lockdrop-vault/src/voting_power.rs +++ b/packages/neutron-lockdrop-vault/src/voting_power.rs @@ -5,22 +5,22 @@ use serde::Serialize; pub fn get_voting_power_for_address( deps: Deps, - lp_contract: impl Into, - oracle_usdc_contract: impl Into, - oracle_atom_contract: impl Into, + lockdrop_contract: impl Into, + usdc_cl_pool_contract: impl Into, + atom_cl_pool_contract: impl Into, pool_type: PoolType, address: String, height: u64, ) -> StdResult { - let oracle_contract: String = match pool_type { - PoolType::ATOM => oracle_atom_contract.into(), - PoolType::USDC => oracle_usdc_contract.into(), + let pool_contract: String = match pool_type { + PoolType::ATOM => atom_cl_pool_contract.into(), + PoolType::USDC => usdc_cl_pool_contract.into(), }; get_voting_power( deps, - lp_contract, - oracle_contract, + lockdrop_contract, + pool_contract, &LockdropQueryMsg::QueryUserLockupTotalAtHeight { pool_type, user_address: address, @@ -54,12 +54,28 @@ pub fn get_voting_power_total( pub fn get_voting_power( deps: Deps, - lp_contract: impl Into, - oracle_contract: impl Into, + lockdrop_contract: impl Into, + pool_contract: String, msg: &impl Serialize, height: u64, ) -> StdResult { - let lp_tokens: Option = deps.querier.query_wasm_smart(lp_contract, msg)?; + let lp_tokens: Option = deps.querier.query_wasm_smart(lockdrop_contract, msg)?; + + let pair_info: astroport::asset::PairInfo = deps.querier.query_wasm_smart( + &pool_contract, + &astroport::pair_concentrated::QueryMsg::Pair {}, + )?; + + let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( + pair_info.liquidity_token, + &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, + )?; - voting_power_from_lp_tokens(deps, lp_tokens.unwrap_or_default(), oracle_contract, height) + voting_power_from_lp_tokens( + deps, + lp_tokens.unwrap_or_default(), + lp_total_supply, + pool_contract, + height, + ) } diff --git a/packages/neutron-oracle/Cargo.toml b/packages/neutron-oracle/Cargo.toml index 3782177c..6b225c19 100644 --- a/packages/neutron-oracle/Cargo.toml +++ b/packages/neutron-oracle/Cargo.toml @@ -8,4 +8,4 @@ repository = "https://github.com/neutron/neutron-dao" [dependencies] cosmwasm-std = { version = "1.0.0" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +astroport = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-oracle/src/voting_power.rs index ca3b37e4..0a01b26e 100644 --- a/packages/neutron-oracle/src/voting_power.rs +++ b/packages/neutron-oracle/src/voting_power.rs @@ -1,32 +1,37 @@ -use astroport::{asset::AssetInfo, oracle::QueryMsg as OracleQueryMsg}; -use cosmwasm_std::{Decimal256, Deps, StdError, StdResult, Uint128, Uint256, Uint64}; +use astroport::asset::Decimal256Ext; +use cosmwasm_std::{Decimal256, Deps, StdResult, Uint128, Uint64}; +use std::ops::Div; pub fn voting_power_from_lp_tokens( deps: Deps, lp_tokens: Uint128, - oracle_contract: impl Into, + total_lp_tokens: Uint128, + cl_pool: impl Into, height: u64, ) -> StdResult { - Ok(if lp_tokens.is_zero() { - Decimal256::zero() + if lp_tokens.is_zero() { + Ok(Decimal256::zero()) } else { - let twap: Decimal256 = deps - .querier - .query_wasm_smart::>( - oracle_contract, - &OracleQueryMsg::TWAPAtHeight { - token: AssetInfo::NativeToken { - denom: "untrn".to_string(), - }, - height: Uint64::new(height), + let balance_resp: Option = deps.querier.query_wasm_smart( + cl_pool, + &astroport::pair_concentrated::QueryMsg::AssetBalanceAt { + asset_info: astroport::asset::AssetInfo::NativeToken { + denom: "untrn".to_string(), }, - )? - .into_iter() - .map(|x| x.1) - .sum::(); + block_height: Uint64::from(height), + }, + )?; + let ntrn_balance_in_pool = if balance_resp.is_some() { + balance_resp.unwrap() + } else { + return Ok(Decimal256::zero()); + }; - Decimal256::new(Uint256::from(lp_tokens)) - .checked_div(twap.sqrt()) - .map_err(|err| StdError::generic_err(format!("{}", err)))? - }) + if ntrn_balance_in_pool.is_zero() { + return Ok(Decimal256::zero()); + } + + Ok(Decimal256::from_ratio(lp_tokens, total_lp_tokens) + .div(Decimal256::from_integer(ntrn_balance_in_pool))) + } } diff --git a/packages/neutron-vesting-lp-vault/src/msg.rs b/packages/neutron-vesting-lp-vault/src/msg.rs index 01b5a6ba..c3a27b1b 100644 --- a/packages/neutron-vesting-lp-vault/src/msg.rs +++ b/packages/neutron-vesting-lp-vault/src/msg.rs @@ -10,12 +10,12 @@ pub struct InstantiateMsg { pub description: String, /// The ATOM Vesting LP contract behind the vault. pub atom_vesting_lp_contract: String, - /// The ATOM oracle contract behind the vault. - pub atom_oracle_contract: String, + /// The ATOM/NTRN CL pool contract. + pub atom_cl_pool_contract: String, /// The USDC Vesting LP contract behind the vault. pub usdc_vesting_lp_contract: String, - /// The USDC oracle contract behind the vault. - pub usdc_oracle_contract: String, + /// The USDC/NTRN CL pool oracle contract. + pub usdc_cl_pool_contract: String, /// Owner can update all configs including changing the owner. This will generally be a DAO. pub owner: String, } @@ -27,9 +27,9 @@ pub enum ExecuteMsg { UpdateConfig { owner: String, atom_vesting_lp_contract: String, - atom_oracle_contract: String, + atom_cl_pool_contract: String, usdc_vesting_lp_contract: String, - usdc_oracle_contract: String, + usdc_cl_pool_contract: String, name: String, description: String, }, @@ -45,4 +45,7 @@ pub enum QueryMsg { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct MigrateMsg {} +pub struct MigrateMsg { + pub atom_cl_pool: String, + pub usdc_cl_pool: String, +} diff --git a/packages/neutron-vesting-lp-vault/src/types.rs b/packages/neutron-vesting-lp-vault/src/types.rs index bedee1b8..06174ec8 100644 --- a/packages/neutron-vesting-lp-vault/src/types.rs +++ b/packages/neutron-vesting-lp-vault/src/types.rs @@ -4,7 +4,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct Config { +pub struct OldConfig { pub name: String, pub description: String, pub atom_vesting_lp_contract: Addr, @@ -14,6 +14,17 @@ pub struct Config { pub owner: Addr, } +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] +pub struct Config { + pub name: String, + pub description: String, + pub atom_vesting_lp_contract: Addr, + pub atom_cl_pool_contract: Addr, + pub usdc_vesting_lp_contract: Addr, + pub usdc_cl_pool_contract: Addr, + pub owner: Addr, +} + impl Config { /// checks whether the config fields are valid. pub fn validate(&self) -> ContractResult<()> { @@ -38,9 +49,9 @@ mod tests { name: String::from("name"), description: String::from("description"), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), owner: Addr::unchecked("owner"), }; assert!(cfg.validate().is_ok()); @@ -52,9 +63,9 @@ mod tests { name: String::from(""), description: String::from("description"), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg.validate(), Err(ContractError::NameIsEmpty {})); @@ -66,9 +77,9 @@ mod tests { name: String::from("name"), description: String::from(""), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg.validate(), Err(ContractError::DescriptionIsEmpty {})); From 68f4b373a1db066b6fdd26bebe6d1a1d4f691439 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 19 Jun 2023 16:06:34 +0400 Subject: [PATCH 11/23] wip --- Cargo.lock | 109 ++++++++++++++++-- .../dao/voting/vesting-lp-vault/Cargo.toml | 3 + .../dao/voting/vesting-lp-vault/src/tests.rs | 55 ++++++++- 3 files changed, 159 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44830cdd..066196e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,38 @@ dependencies = [ "uint", ] +[[package]] +name = "astroport-factory" +version = "1.5.1" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.8.0#3b44a4044b823a145730f66ffaf7ae4205b2cd35" +dependencies = [ + "astroport 2.8.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw2 0.15.1", + "itertools", + "protobuf 2.28.0", + "thiserror", +] + +[[package]] +name = "astroport-pair-concentrated" +version = "1.2.0" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.8.0#3b44a4044b823a145730f66ffaf7ae4205b2cd35" +dependencies = [ + "astroport 2.8.0", + "astroport-factory", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "itertools", + "thiserror", +] + [[package]] name = "astroport-periphery" version = "1.1.0" @@ -88,6 +120,21 @@ dependencies = [ "terraswap", ] +[[package]] +name = "astroport-xastro-token" +version = "1.0.2" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.8.0#3b44a4044b823a145730f66ffaf7ae4205b2cd35" +dependencies = [ + "astroport 2.8.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "cw20-base 0.15.1", + "snafu", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -407,7 +454,7 @@ dependencies = [ "cosmwasm-std", "cw-multi-test 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "schemars", "serde", "thiserror", @@ -664,6 +711,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw20-base" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0909c56d0c14601fbdc69382189799482799dcad87587926aec1f3aa321abc41" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw3" version = "0.13.4" @@ -833,7 +898,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw4-group", "cwd-core", "cwd-interface", @@ -882,7 +947,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw4-group", "cwd-core", "cwd-interface", @@ -919,7 +984,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw3", "cw4", "cw4-group", @@ -959,7 +1024,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw3", "cw4", "cw4-group", @@ -1047,7 +1112,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw3", "cw4", "cw4-group", @@ -1109,7 +1174,7 @@ dependencies = [ "cw-utils 0.13.4", "cw2 0.13.4", "cw20 0.13.4", - "cw20-base", + "cw20-base 0.13.4", "cw4", "cw4-group", "cw721-base", @@ -1196,6 +1261,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dyn-clone" version = "1.0.11" @@ -2035,6 +2106,27 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "snafu" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab12d3c261b2308b0d80c26fffb58d17eba81a4be97890101f416b478c79ca7" +dependencies = [ + "doc-comment", + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1508efa03c362e23817f96cde18abed596a25219a8b2c66e8db33c03543d315b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "spki" version = "0.6.0" @@ -2246,6 +2338,9 @@ version = "0.1.0" dependencies = [ "anyhow", "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.8.0", + "astroport-pair-concentrated", + "astroport-xastro-token", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test 0.13.4", diff --git a/contracts/dao/voting/vesting-lp-vault/Cargo.toml b/contracts/dao/voting/vesting-lp-vault/Cargo.toml index ef723da0..57783096 100644 --- a/contracts/dao/voting/vesting-lp-vault/Cargo.toml +++ b/contracts/dao/voting/vesting-lp-vault/Cargo.toml @@ -34,3 +34,6 @@ astroport = { package="astroport", git = "https://github.com/neutron-org/neutron cosmwasm-schema = { version = "1.0.0" } cw-multi-test = "0.13" anyhow = "1.0.57" +astroport-xastro-token = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } +astroport-pair-concentrated = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } +astroport-original = { package = "astroport", git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } \ No newline at end of file diff --git a/contracts/dao/voting/vesting-lp-vault/src/tests.rs b/contracts/dao/voting/vesting-lp-vault/src/tests.rs index 792a3b80..1953116e 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/tests.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/tests.rs @@ -42,6 +42,15 @@ fn vault_contract() -> Box> { Box::new(contract) } +fn lp_token_contract() -> Box> { + let contract = ContractWrapper::new( + astroport_xastro_token::contract::execute, + astroport_xastro_token::contract::instantiate, + astroport_xastro_token::contract::query, + ); + Box::new(contract) +} + fn vesting_lp_contract() -> Box> { let contract = ContractWrapper::new( vesting_lp::contract::execute, @@ -91,6 +100,15 @@ fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { .unwrap() } +fn instantiate_lp_token( + app: &mut App, + id: u64, + msg: astroport_original::xastro_token::InstantiateMsg, +) -> Addr { + app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "lp-token", None) + .unwrap() +} + fn instantiate_vesting_lp(app: &mut App, id: u64, msg: vesting_lp::msg::InstantiateMsg) -> Addr { app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vesting_lp", None) .unwrap() @@ -570,6 +588,33 @@ fn test_total_power_at_height() { let mut app = mock_app(); let vesting_lp_id = app.store_code(vesting_lp_contract()); + let lp_token_id = app.store_code(lp_token_contract()); + + let atom_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "atom".to_string(), + symbol: "atom-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let usdc_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "usdc".to_string(), + symbol: "usdc-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let atom_vesting_lp_addr = instantiate_vesting_lp( &mut app, vesting_lp_id, @@ -594,7 +639,15 @@ fn test_total_power_at_height() { Addr::unchecked("manager".to_string()), usdc_vesting_lp_addr.clone(), AssetInfo::Token { - contract_addr: Addr::unchecked("usdc"), + contract_addr: usdc_lp_token_address, + }, + ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + atom_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: atom_lp_token_address, }, ); From c37b759a8f19778e768128db51823a92383060d5 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 19 Jun 2023 17:21:55 +0400 Subject: [PATCH 12/23] wip --- .../vesting-lp-vault/schema/execute_msg.json | 8 +- .../schema/get_config_response.json | 8 +- .../schema/instantiate_msg.json | 12 +-- .../vesting-lp-vault/schema/migrate_msg.json | 14 ++- .../reserve/schema/execute_msg.json | 85 ++++++++++++++++--- packages/neutron-oracle/src/voting_power.rs | 4 +- 6 files changed, 104 insertions(+), 27 deletions(-) diff --git a/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json index 5920d68b..ad012325 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json @@ -11,16 +11,16 @@ "update_config": { "type": "object", "required": [ - "atom_oracle_contract", + "atom_cl_pool_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_oracle_contract", + "usdc_cl_pool_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_oracle_contract": { + "atom_cl_pool_contract": { "type": "string" }, "atom_vesting_lp_contract": { @@ -35,7 +35,7 @@ "owner": { "type": "string" }, - "usdc_oracle_contract": { + "usdc_cl_pool_contract": { "type": "string" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json b/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json index adda59d3..9d7c2f88 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json @@ -3,16 +3,16 @@ "title": "GetConfigResponse", "type": "object", "required": [ - "atom_oracle_contract", + "atom_cl_pool_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_oracle_contract", + "usdc_cl_pool_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_oracle_contract": { + "atom_cl_pool_contract": { "$ref": "#/definitions/Addr" }, "atom_vesting_lp_contract": { @@ -27,7 +27,7 @@ "owner": { "$ref": "#/definitions/Addr" }, - "usdc_oracle_contract": { + "usdc_cl_pool_contract": { "$ref": "#/definitions/Addr" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json index 9dbb4e25..ea001c18 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json @@ -3,17 +3,17 @@ "title": "InstantiateMsg", "type": "object", "required": [ - "atom_oracle_contract", + "atom_cl_pool_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_oracle_contract", + "usdc_cl_pool_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_oracle_contract": { - "description": "The ATOM oracle contract behind the vault.", + "atom_cl_pool_contract": { + "description": "The ATOM/NTRN CL pool contract.", "type": "string" }, "atom_vesting_lp_contract": { @@ -32,8 +32,8 @@ "description": "Owner can update all configs including changing the owner. This will generally be a DAO.", "type": "string" }, - "usdc_oracle_contract": { - "description": "The USDC oracle contract behind the vault.", + "usdc_cl_pool_contract": { + "description": "The USDC/NTRN CL pool oracle contract.", "type": "string" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json index 87b18ea7..688bcc83 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json @@ -1,5 +1,17 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "MigrateMsg", - "type": "object" + "type": "object", + "required": [ + "atom_cl_pool", + "usdc_cl_pool" + ], + "properties": { + "atom_cl_pool": { + "type": "string" + }, + "usdc_cl_pool": { + "type": "string" + } + } } diff --git a/contracts/tokenomics/reserve/schema/execute_msg.json b/contracts/tokenomics/reserve/schema/execute_msg.json index 53c0cc31..abc72a7b 100644 --- a/contracts/tokenomics/reserve/schema/execute_msg.json +++ b/contracts/tokenomics/reserve/schema/execute_msg.json @@ -87,6 +87,51 @@ }, "additionalProperties": false }, + { + "description": "Processes either partial or full xyk->CL migration of contract's liquidity.", + "type": "object", + "required": [ + "migrate_from_xyk_to_cl" + ], + "properties": { + "migrate_from_xyk_to_cl": { + "type": "object", + "properties": { + "ntrn_atom_amount": { + "anyOf": [ + { + "$ref": "#/definitions/Uint128" + }, + { + "type": "null" + } + ] + }, + "ntrn_usdc_amount": { + "anyOf": [ + { + "$ref": "#/definitions/Uint128" + }, + { + "type": "null" + } + ] + }, + "slippage_tolerance": { + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + } + } + } + }, + "additionalProperties": false + }, { "description": "Callbacks; only callable by the contract itself.", "type": "object", @@ -136,6 +181,10 @@ } ], "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + }, "CallbackMsg": { "oneOf": [ { @@ -147,14 +196,20 @@ "migrate_liquidity_to_cl_pair": { "type": "object", "required": [ - "cl_pair_address", + "amount", + "cl_pair", "ntrn_denom", "paired_asset_denom", - "xyk_pair_address" + "slippage_tolerance", + "xyk_lp_token", + "xyk_pair" ], "properties": { - "cl_pair_address": { - "type": "string" + "amount": { + "$ref": "#/definitions/Uint128" + }, + "cl_pair": { + "$ref": "#/definitions/Addr" }, "ntrn_denom": { "type": "string" @@ -162,8 +217,14 @@ "paired_asset_denom": { "type": "string" }, - "xyk_pair_address": { - "type": "string" + "slippage_tolerance": { + "$ref": "#/definitions/Decimal" + }, + "xyk_lp_token": { + "$ref": "#/definitions/Addr" + }, + "xyk_pair": { + "$ref": "#/definitions/Addr" } } } @@ -179,15 +240,16 @@ "provide_liquidity_to_cl_pair_after_withdrawal": { "type": "object", "required": [ - "cl_pair_address", + "cl_pair", "ntrn_denom", "ntrn_init_balance", "paired_asset_denom", - "paired_asset_init_balance" + "paired_asset_init_balance", + "slippage_tolerance" ], "properties": { - "cl_pair_address": { - "type": "string" + "cl_pair": { + "$ref": "#/definitions/Addr" }, "ntrn_denom": { "type": "string" @@ -200,6 +262,9 @@ }, "paired_asset_init_balance": { "$ref": "#/definitions/Uint128" + }, + "slippage_tolerance": { + "$ref": "#/definitions/Decimal" } } } diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-oracle/src/voting_power.rs index 0a01b26e..993e77ff 100644 --- a/packages/neutron-oracle/src/voting_power.rs +++ b/packages/neutron-oracle/src/voting_power.rs @@ -21,8 +21,8 @@ pub fn voting_power_from_lp_tokens( block_height: Uint64::from(height), }, )?; - let ntrn_balance_in_pool = if balance_resp.is_some() { - balance_resp.unwrap() + let ntrn_balance_in_pool = if let Some(ntrn_balance) = balance_resp { + ntrn_balance } else { return Ok(Decimal256::zero()); }; From 0aa2cb8034b1d81abd6d45f31395468d3c3fdbf6 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Fri, 23 Jun 2023 17:14:01 +0400 Subject: [PATCH 13/23] wip --- .../dao/voting/lockdrop-vault/src/contract.rs | 4 +- .../dao/voting/lockdrop-vault/src/tests.rs | 48 +++++++++---------- packages/neutron-lockdrop-vault/src/msg.rs | 8 ++-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault/src/contract.rs b/contracts/dao/voting/lockdrop-vault/src/contract.rs index bd2328b0..8b682b8c 100644 --- a/contracts/dao/voting/lockdrop-vault/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault/src/contract.rs @@ -34,8 +34,8 @@ pub fn instantiate( name: msg.name, description: msg.description, lockdrop_contract: deps.api.addr_validate(&msg.lockdrop_contract)?, - usdc_cl_pool_contract: deps.api.addr_validate(&msg.oracle_usdc_contract)?, - atom_cl_pool_contract: deps.api.addr_validate(&msg.oracle_atom_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, owner, }; config.validate()?; diff --git a/contracts/dao/voting/lockdrop-vault/src/tests.rs b/contracts/dao/voting/lockdrop-vault/src/tests.rs index 0dd4faa7..f7b1738e 100644 --- a/contracts/dao/voting/lockdrop-vault/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault/src/tests.rs @@ -307,8 +307,8 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -327,8 +327,8 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -349,8 +349,8 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -370,8 +370,8 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -402,8 +402,8 @@ fn test_update_config_as_owner() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -448,8 +448,8 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -481,8 +481,8 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -513,8 +513,8 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -535,8 +535,8 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -557,8 +557,8 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), - oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -593,8 +593,8 @@ fn test_voting_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: lockdrop_contract.to_string(), - oracle_usdc_contract: oracle_usdc_contract.to_string(), - oracle_atom_contract: oracle_atom_contract.to_string(), + usdc_cl_pool_contract: oracle_usdc_contract.to_string(), + atom_cl_pool_contract: oracle_atom_contract.to_string(), }, ); @@ -620,8 +620,8 @@ fn test_total_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: lockdrop_contract.to_string(), - oracle_usdc_contract: oracle_usdc_contract.to_string(), - oracle_atom_contract: oracle_atom_contract.to_string(), + usdc_cl_pool_contract: oracle_usdc_contract.to_string(), + atom_cl_pool_contract: oracle_atom_contract.to_string(), }, ); diff --git a/packages/neutron-lockdrop-vault/src/msg.rs b/packages/neutron-lockdrop-vault/src/msg.rs index e00c210d..3f72628f 100644 --- a/packages/neutron-lockdrop-vault/src/msg.rs +++ b/packages/neutron-lockdrop-vault/src/msg.rs @@ -10,10 +10,10 @@ pub struct InstantiateMsg { pub description: String, /// The lockdrop contract behind the vault. pub lockdrop_contract: String, - /// The oracle USDC/NTRN contract behind the vault. - pub oracle_usdc_contract: String, - /// The oracle ATOM/NTRN contract behind the vault. - pub oracle_atom_contract: String, + /// The USDC/NTRN CL pool contract. + pub usdc_cl_pool_contract: String, + /// The ATOM/NTRN CL pool oracle contract. + pub atom_cl_pool_contract: String, /// Owner can update all configs including changing the owner. This will generally be a DAO. pub owner: String, } From adbe3e1de075f1752a750b558d55af55d03ae97f Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 26 Jun 2023 15:33:08 +0400 Subject: [PATCH 14/23] wip --- .../dao/voting/lockdrop-vault/src/tests.rs | 203 +----------------- .../dao/voting/vesting-lp-vault/src/tests.rs | 44 ++++ 2 files changed, 46 insertions(+), 201 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault/src/tests.rs b/contracts/dao/voting/lockdrop-vault/src/tests.rs index f7b1738e..cf41125a 100644 --- a/contracts/dao/voting/lockdrop-vault/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault/src/tests.rs @@ -1,18 +1,9 @@ use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; use crate::state::{CONFIG, OLD_CONFIG}; -use astroport::asset::AssetInfo; -use astroport::oracle::QueryMsg as OracleQueryMsg; -use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; use cosmwasm_std::testing::{mock_dependencies, mock_env}; -use cosmwasm_std::{ - coins, to_binary, Addr, Binary, Coin, Decimal256, Deps, Empty, Env, Response, StdResult, - Uint128, -}; +use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; -use cwd_interface::voting::{ - InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, -}; -use neutron_lockdrop_vault::error::ContractError; +use cwd_interface::voting::InfoResponse; use neutron_lockdrop_vault::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use neutron_lockdrop_vault::types::{Config, OldConfig}; use schemars::JsonSchema; @@ -84,118 +75,6 @@ fn mock_app() -> App { #[serde(rename_all = "snake_case")] pub struct EmptyMsg {} -const USER_ATOM_LOCKUP_AT_HEIGHT: u64 = 1_000_000u64; -const USER_USDC_LOCKUP_AT_HEIGHT: u64 = 2_000_000u64; -const TOTAL_ATOM_LOCKUP_AT_HEIGHT: u64 = 3_000_000u64; -const TOTAL_USDC_LOCKUP_AT_HEIGHT: u64 = 4_000_000u64; - -fn lockdrop_query(_deps: Deps, _env: Env, msg: LockdropQueryMsg) -> StdResult { - match msg { - LockdropQueryMsg::QueryUserLockupTotalAtHeight { - pool_type, - user_address: _, - height: _, - } => { - let response = match pool_type { - PoolType::ATOM => Uint128::from(USER_ATOM_LOCKUP_AT_HEIGHT), - PoolType::USDC => Uint128::from(USER_USDC_LOCKUP_AT_HEIGHT), - }; - - to_binary(&response) - } - LockdropQueryMsg::QueryLockupTotalAtHeight { - pool_type, - height: _, - } => { - let response = match pool_type { - PoolType::ATOM => Uint128::from(TOTAL_ATOM_LOCKUP_AT_HEIGHT), - PoolType::USDC => Uint128::from(TOTAL_USDC_LOCKUP_AT_HEIGHT), - }; - - to_binary(&response) - } - _ => unreachable!(), - } -} - -fn lockdrop_contract() -> Box> { - let contract: ContractWrapper< - EmptyMsg, - EmptyMsg, - LockdropQueryMsg, - ContractError, - ContractError, - cosmwasm_std::StdError, - > = ContractWrapper::new( - |_, _, _, _: EmptyMsg| Ok(Response::new()), - |_, _, _, _: EmptyMsg| Ok(Response::new()), - lockdrop_query, - ); - Box::new(contract) -} - -fn instantiate_lockdrop_contract(app: &mut App) -> Addr { - let contract_id = app.store_code(lockdrop_contract()); - app.instantiate_contract( - contract_id, - Addr::unchecked(DAO_ADDR), - &EmptyMsg {}, - &[], - "lockdrop contract", - None, - ) - .unwrap() -} - -const NTRN_TWAP: u64 = 4; - -fn oracle_query(_deps: Deps, _env: Env, msg: OracleQueryMsg) -> StdResult { - match msg { - OracleQueryMsg::TWAPAtHeight { token, height: _ } => { - let twap = match token.clone() { - AssetInfo::NativeToken { denom } => match denom.as_str() { - "untrn" => Decimal256::from_ratio(NTRN_TWAP, 1u64), - _ => Decimal256::from_ratio(1u64, NTRN_TWAP), - }, - AssetInfo::Token { contract_addr: _ } => Decimal256::from_ratio(1u64, NTRN_TWAP), - }; - - let response = vec![(token, twap)]; - to_binary(&response) - } - _ => unreachable!(), - } -} - -fn oracle_contract() -> Box> { - let contract: ContractWrapper< - EmptyMsg, - EmptyMsg, - OracleQueryMsg, - ContractError, - ContractError, - cosmwasm_std::StdError, - > = ContractWrapper::new( - |_, _, _, _: EmptyMsg| Ok(Response::new()), - |_, _, _, _: EmptyMsg| Ok(Response::new()), - oracle_query, - ); - Box::new(contract) -} - -fn instantiate_oracle_contract(app: &mut App) -> Addr { - let contract_id = app.store_code(oracle_contract()); - app.instantiate_contract( - contract_id, - Addr::unchecked(DAO_ADDR), - &EmptyMsg {}, - &[], - "oracle contract", - None, - ) - .unwrap() -} - fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vault", None) .unwrap() @@ -259,30 +138,6 @@ fn update_config( ) } -fn get_voting_power_at_height( - app: &mut App, - contract_addr: Addr, - address: String, - height: Option, -) -> VotingPowerAtHeightResponse { - app.wrap() - .query_wasm_smart( - contract_addr, - &QueryMsg::VotingPowerAtHeight { address, height }, - ) - .unwrap() -} - -fn get_total_power_at_height( - app: &mut App, - contract_addr: Addr, - height: Option, -) -> TotalPowerAtHeightResponse { - app.wrap() - .query_wasm_smart(contract_addr, &QueryMsg::TotalPowerAtHeight { height }) - .unwrap() -} - fn get_config(app: &mut App, contract_addr: Addr) -> Config { app.wrap() .query_wasm_smart(contract_addr, &QueryMsg::Config {}) @@ -576,60 +431,6 @@ fn test_query_get_config() { ) } -#[test] -fn test_voting_power_at_height() { - let mut app = mock_app(); - - let lockdrop_contract = instantiate_lockdrop_contract(&mut app); - let oracle_usdc_contract = instantiate_oracle_contract(&mut app); - let oracle_atom_contract = instantiate_oracle_contract(&mut app); - - let vault_id = app.store_code(vault_contract()); - let addr = instantiate_vault( - &mut app, - vault_id, - InstantiateMsg { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - owner: DAO_ADDR.to_string(), - lockdrop_contract: lockdrop_contract.to_string(), - usdc_cl_pool_contract: oracle_usdc_contract.to_string(), - atom_cl_pool_contract: oracle_atom_contract.to_string(), - }, - ); - - let resp = get_voting_power_at_height(&mut app, addr, ADDR1.to_string(), None); - // (USER_ATOM_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + (USER_USDC_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) - assert_eq!(resp.power, Uint128::from(500_000u128 + 1_000_000u128)); -} - -#[test] -fn test_total_power_at_height() { - let mut app = mock_app(); - - let lockdrop_contract = instantiate_lockdrop_contract(&mut app); - let oracle_usdc_contract = instantiate_oracle_contract(&mut app); - let oracle_atom_contract = instantiate_oracle_contract(&mut app); - - let vault_id = app.store_code(vault_contract()); - let addr = instantiate_vault( - &mut app, - vault_id, - InstantiateMsg { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - owner: DAO_ADDR.to_string(), - lockdrop_contract: lockdrop_contract.to_string(), - usdc_cl_pool_contract: oracle_usdc_contract.to_string(), - atom_cl_pool_contract: oracle_atom_contract.to_string(), - }, - ); - - let resp = get_total_power_at_height(&mut app, addr, None); - // (TOTAL_ATOM_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + (TOTAL_USDC_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) - assert_eq!(resp.power, Uint128::from(1_500_000u128 + 2_000_000u128)); -} - #[test] pub fn test_migrate_update_version() { let mut deps = mock_dependencies(); diff --git a/contracts/dao/voting/vesting-lp-vault/src/tests.rs b/contracts/dao/voting/vesting-lp-vault/src/tests.rs index 1953116e..2a163d10 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/tests.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/tests.rs @@ -544,6 +544,33 @@ fn test_voting_power_at_height() { let mut app = mock_app(); let vesting_lp_id = app.store_code(vesting_lp_contract()); + let lp_token_id = app.store_code(lp_token_contract()); + + let atom_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "atom".to_string(), + symbol: "atom-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let usdc_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "usdc".to_string(), + symbol: "usdc-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let atom_vesting_lp_addr = instantiate_vesting_lp( &mut app, vesting_lp_id, @@ -563,6 +590,23 @@ fn test_voting_power_at_height() { }, ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + usdc_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: usdc_lp_token_address, + }, + ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + atom_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: atom_lp_token_address, + }, + ); + let vault_id = app.store_code(vault_contract()); let addr = instantiate_vault( &mut app, From 8bdec0452c51f65ff678899ca8681a4cfe19444f Mon Sep 17 00:00:00 2001 From: quasisamurai Date: Fri, 7 Jul 2023 19:18:48 +0400 Subject: [PATCH 15/23] fix voting power calc --- packages/neutron-oracle/src/voting_power.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-oracle/src/voting_power.rs index 993e77ff..53b413ce 100644 --- a/packages/neutron-oracle/src/voting_power.rs +++ b/packages/neutron-oracle/src/voting_power.rs @@ -1,6 +1,6 @@ use astroport::asset::Decimal256Ext; use cosmwasm_std::{Decimal256, Deps, StdResult, Uint128, Uint64}; -use std::ops::Div; +use std::ops::Mul; pub fn voting_power_from_lp_tokens( deps: Deps, @@ -32,6 +32,6 @@ pub fn voting_power_from_lp_tokens( } Ok(Decimal256::from_ratio(lp_tokens, total_lp_tokens) - .div(Decimal256::from_integer(ntrn_balance_in_pool))) + .mul(Decimal256::from_integer(ntrn_balance_in_pool))) } } From 3efb538abaf1673f0ac5f921bbffaedf5dc17258 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 10 Jul 2023 13:26:28 +0300 Subject: [PATCH 16/23] fix vp calculation --- .../dao/voting/lockdrop-vault/src/contract.rs | 14 +++----------- .../dao/voting/vesting-lp-vault/src/contract.rs | 17 +++++------------ .../neutron-lockdrop-vault/src/voting_power.rs | 8 ++++---- packages/neutron-oracle/src/voting_power.rs | 15 ++++++--------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault/src/contract.rs b/contracts/dao/voting/lockdrop-vault/src/contract.rs index 8b682b8c..0271be9e 100644 --- a/contracts/dao/voting/lockdrop-vault/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault/src/contract.rs @@ -1,8 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, Fraction, MessageInfo, Response, StdError, Uint128, -}; +use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, Uint128}; use cw2::set_contract_version; use cwd_interface::voting::{ BondingStatusResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, @@ -213,10 +211,7 @@ pub fn query_voting_power_at_height( let power = atom_power + usdc_power; - Ok(VotingPowerAtHeightResponse { - power: power.numerator().try_into().map_err(StdError::from)?, - height, - }) + Ok(VotingPowerAtHeightResponse { power, height }) } pub fn query_total_power_at_height( @@ -247,10 +242,7 @@ pub fn query_total_power_at_height( let power = atom_power + usdc_power; - Ok(TotalPowerAtHeightResponse { - power: power.numerator().try_into().map_err(StdError::from)?, - height, - }) + Ok(TotalPowerAtHeightResponse { power, height }) } pub fn query_info(deps: Deps) -> ContractResult { diff --git a/contracts/dao/voting/vesting-lp-vault/src/contract.rs b/contracts/dao/voting/vesting-lp-vault/src/contract.rs index 47df86aa..dd1baee3 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/contract.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/contract.rs @@ -2,8 +2,7 @@ use astroport::asset::AssetInfo; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Decimal256, Deps, DepsMut, Env, Fraction, MessageInfo, Response, StdError, - Uint128, + to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, Uint128, }; use cw2::set_contract_version; use cwd_interface::voting::{ @@ -175,8 +174,8 @@ fn get_voting_power( config: &Config, height: u64, query_msg: &impl Serialize, -) -> ContractResult { - let mut voting_power = Decimal256::zero(); +) -> ContractResult { + let mut voting_power = Uint128::zero(); for (vesting_lp, cl_pool) in [ ( &config.atom_vesting_lp_contract, @@ -230,10 +229,7 @@ pub fn query_voting_power_at_height( }; Ok(VotingPowerAtHeightResponse { - power: get_voting_power(deps, &config, height, &query_msg)? - .numerator() - .try_into() - .map_err(StdError::from)?, + power: get_voting_power(deps, &config, height, &query_msg)?, height, }) } @@ -250,10 +246,7 @@ pub fn query_total_power_at_height( }; Ok(TotalPowerAtHeightResponse { - power: get_voting_power(deps, &config, height, &query_msg)? - .numerator() - .try_into() - .map_err(StdError::from)?, + power: get_voting_power(deps, &config, height, &query_msg)?, height, }) } diff --git a/packages/neutron-lockdrop-vault/src/voting_power.rs b/packages/neutron-lockdrop-vault/src/voting_power.rs index a37a877d..f8b9496b 100644 --- a/packages/neutron-lockdrop-vault/src/voting_power.rs +++ b/packages/neutron-lockdrop-vault/src/voting_power.rs @@ -1,5 +1,5 @@ use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; -use cosmwasm_std::{Decimal256, Deps, StdResult, Uint128}; +use cosmwasm_std::{Deps, StdResult, Uint128}; use neutron_oracle::voting_power::voting_power_from_lp_tokens; use serde::Serialize; @@ -11,7 +11,7 @@ pub fn get_voting_power_for_address( pool_type: PoolType, address: String, height: u64, -) -> StdResult { +) -> StdResult { let pool_contract: String = match pool_type { PoolType::ATOM => atom_cl_pool_contract.into(), PoolType::USDC => usdc_cl_pool_contract.into(), @@ -37,7 +37,7 @@ pub fn get_voting_power_total( oracle_atom_contract: impl Into, pool_type: PoolType, height: u64, -) -> StdResult { +) -> StdResult { let oracle_contract: String = match pool_type { PoolType::ATOM => oracle_atom_contract.into(), PoolType::USDC => oracle_usdc_contract.into(), @@ -58,7 +58,7 @@ pub fn get_voting_power( pool_contract: String, msg: &impl Serialize, height: u64, -) -> StdResult { +) -> StdResult { let lp_tokens: Option = deps.querier.query_wasm_smart(lockdrop_contract, msg)?; let pair_info: astroport::asset::PairInfo = deps.querier.query_wasm_smart( diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-oracle/src/voting_power.rs index 53b413ce..12cefc30 100644 --- a/packages/neutron-oracle/src/voting_power.rs +++ b/packages/neutron-oracle/src/voting_power.rs @@ -1,6 +1,4 @@ -use astroport::asset::Decimal256Ext; -use cosmwasm_std::{Decimal256, Deps, StdResult, Uint128, Uint64}; -use std::ops::Mul; +use cosmwasm_std::{Deps, StdResult, Uint128, Uint64}; pub fn voting_power_from_lp_tokens( deps: Deps, @@ -8,9 +6,9 @@ pub fn voting_power_from_lp_tokens( total_lp_tokens: Uint128, cl_pool: impl Into, height: u64, -) -> StdResult { +) -> StdResult { if lp_tokens.is_zero() { - Ok(Decimal256::zero()) + Ok(Uint128::zero()) } else { let balance_resp: Option = deps.querier.query_wasm_smart( cl_pool, @@ -24,14 +22,13 @@ pub fn voting_power_from_lp_tokens( let ntrn_balance_in_pool = if let Some(ntrn_balance) = balance_resp { ntrn_balance } else { - return Ok(Decimal256::zero()); + return Ok(Uint128::zero()); }; if ntrn_balance_in_pool.is_zero() { - return Ok(Decimal256::zero()); + return Ok(Uint128::zero()); } - Ok(Decimal256::from_ratio(lp_tokens, total_lp_tokens) - .mul(Decimal256::from_integer(ntrn_balance_in_pool))) + Ok(lp_tokens.multiply_ratio(ntrn_balance_in_pool, total_lp_tokens)) } } From d5bc5320198eef1c435f8514e0f93655a1cca5e3 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 7 Aug 2023 14:40:31 +0300 Subject: [PATCH 17/23] review fixes --- Cargo.lock | 347 +++++++++--------- .../dao/voting/lockdrop-vault/Cargo.toml | 4 +- .../dao/voting/vesting-lp-vault/Cargo.toml | 8 +- .../voting/vesting-lp-vault/src/contract.rs | 4 +- packages/cwd-hooks/src/lib.rs | 4 +- packages/neutron-lockdrop-vault/Cargo.toml | 4 +- .../neutron-vesting-lp-vault/src/error.rs | 5 +- .../Cargo.toml | 0 .../src/lib.rs | 0 .../src/voting_power.rs | 0 10 files changed, 184 insertions(+), 192 deletions(-) rename packages/{neutron-oracle => neutron-voting-power}/Cargo.toml (100%) rename packages/{neutron-oracle => neutron-voting-power}/src/lib.rs (100%) rename packages/{neutron-oracle => neutron-voting-power}/src/voting_power.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index c51b1f41..3d562bc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,14 +15,14 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -47,8 +47,21 @@ dependencies = [ [[package]] name = "astroport" -version = "2.7.1" -source = "git+https://github.com/astroport-fi/astroport-core.git?branch=main#c73a2db3c0b4f069e906d90970e1b72a5cf71bbf" +version = "2.0.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#e306308dd23d567399c15d899f295a910ede945b" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw20 0.15.1", + "itertools", + "uint", +] + +[[package]] +name = "astroport" +version = "2.5.0" +source = "git+https://github.com/astroport-fi/astroport-core.git?tag=v2.5.0#65ce7d1879cc5d95b09fa14202f0423bba52ae0e" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -108,9 +121,9 @@ dependencies = [ [[package]] name = "astroport-periphery" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ - "astroport 2.7.1", + "astroport 2.5.0", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", @@ -189,6 +202,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bnum" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "845141a4fade3f790628b7daaaa298a25b204fb28907eb54febe5142db6ce653" + [[package]] name = "byteorder" version = "1.4.3" @@ -212,9 +231,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const-oid" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" [[package]] name = "cosmos-sdk-proto" @@ -229,11 +248,11 @@ dependencies = [ [[package]] name = "cosmwasm-crypto" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b76d2207945b8aa3ce0735da53ab9a74f75fe3e7794754c216a9edfa04e1e627" +checksum = "7e272708a9745dad8b591ef8a718571512130f2b39b33e3d7a27c558e3069394" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "ed25519-zebra", "k256", "rand_core 0.6.4", @@ -242,18 +261,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd07af7736164d2d8126dc67fdb33b1b5c54fb5a3190395c47f46d24fc6d592" +checksum = "296db6a3caca5283425ae0cf347f4e46999ba3f6620dbea8939a0e00347831ce" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9e92cdce475a91659d0dc4d17836a484fc534e80e787281aa4adde4cb1798b" +checksum = "63c337e097a089e5b52b5d914a7ff6613332777f38ea6d9d36e1887cd0baa72e" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -264,9 +283,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69681bac3dbeb0b00990279e3ed39e3d4406b29f538b16b712f6771322a45048" +checksum = "766cc9e7c1762d8fc9c0265808910fcad755200cd0e624195a491dd885a61169" dependencies = [ "proc-macro2", "quote", @@ -275,11 +294,12 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d39f20967baeb94709123f7bba13a25ae2fa166bc5e7813f734914df3f8f6a1" +checksum = "eb5e05a95fd2a420cca50f4e94eb7e70648dac64db45e90403997ebefeb143bd" dependencies = [ "base64 0.13.1", + "bnum", "cosmwasm-crypto", "cosmwasm-derive", "derivative", @@ -288,16 +308,15 @@ dependencies = [ "schemars", "serde", "serde-json-wasm 0.5.1", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", - "uint", ] [[package]] name = "cosmwasm-storage" -version = "1.2.4" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88f7944b5204c3a998f73248925a097ace887bdf01c2f70de00d8b92cd69e807" +checksum = "800aaddd70ba915e19bf3d2d992aa3689d8767857727fdd3b414df4fd52d2aa1" dependencies = [ "cosmwasm-std", "serde", @@ -305,9 +324,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -320,13 +339,13 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", + "cw-controllers 1.1.0", + "cw-multi-test 0.16.5", "cw-paginate 0.2.0", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cw-utils 1.0.1", "cw2 0.13.4", - "cw20 1.0.1", + "cw20 1.1.0", "cwd-interface", "cwd-macros", "cwd-voting", @@ -392,13 +411,13 @@ dependencies = [ [[package]] name = "cw-controllers" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91440ce8ec4f0642798bc8c8cb6b9b53c1926c6dadaf0eed267a5145cd529071" +checksum = "d5d8edce4b78785f36413f67387e4be7d0cb7d032b5d4164bcc024f9c3f3f2ea" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cw-utils 1.0.1", "schemars", "serde", @@ -481,13 +500,13 @@ dependencies = [ [[package]] name = "cw-multi-test" -version = "0.16.4" +version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a18afd2e201221c6d72a57f0886ef2a22151bbc9e6db7af276fde8a91081042" +checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" dependencies = [ "anyhow", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cw-utils 1.0.1", "derivative", "itertools", @@ -568,9 +587,9 @@ dependencies = [ [[package]] name = "cw-storage-plus" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a5083c258acd68386734f428a5a171b29f7d733151ae83090c6fcc9417ffa" +checksum = "3f0e92a069d62067f3472c62e30adedb4cab1754725c0f2a682b3128d2bf3c79" dependencies = [ "cosmwasm-std", "schemars", @@ -612,7 +631,7 @@ checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw2 1.0.1", + "cw2 1.1.0", "schemars", "semver", "serde", @@ -646,15 +665,16 @@ dependencies = [ [[package]] name = "cw2" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" +checksum = "29ac2dc7a55ad64173ca1e0a46697c31b7a5c51342f55a1e84a724da4eb99908" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "schemars", "serde", + "thiserror", ] [[package]] @@ -684,9 +704,9 @@ dependencies = [ [[package]] name = "cw20" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91666da6c7b40c8dd5ff94df655a28114efc10c79b70b4d06f13c31e37d60609" +checksum = "011c45920f8200bd5d32d4fe52502506f64f2f75651ab408054d4cfc75ca3a9b" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -826,7 +846,7 @@ dependencies = [ "cw721", "cwd-interface", "cwd-macros", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -906,7 +926,7 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -928,7 +948,7 @@ dependencies = [ "cwd-proposal-single", "cwd-voting", "neutron-dao-pre-propose-overrule", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-subdao-core", "neutron-subdao-timelock-single", "schemars", @@ -955,7 +975,7 @@ dependencies = [ "cwd-proposal-hooks", "cwd-proposal-single", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1000,7 +1020,7 @@ dependencies = [ "cwd-testing", "cwd-vote-hooks", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-vault", "neutron-voting-registry", "rand", @@ -1039,7 +1059,7 @@ dependencies = [ "cwd-testing", "cwd-vote-hooks", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-vault", "neutron-voting-registry", "schemars", @@ -1066,7 +1086,7 @@ dependencies = [ "cwd-macros", "cwd-voting", "exec-control", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-subdao-core", "neutron-subdao-pre-propose-single", "neutron-subdao-proposal-single", @@ -1089,7 +1109,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-subdao-core", "neutron-subdao-pre-propose-single", "neutron-subdao-proposal-single", @@ -1112,7 +1132,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-security-subdao-pre-propose", "neutron-subdao-core", "neutron-subdao-proposal-single", @@ -1148,7 +1168,7 @@ dependencies = [ "cwd-subdao-pre-propose-single", "cwd-vote-hooks", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-subdao-core", "neutron-subdao-pre-propose-single", "neutron-subdao-proposal-single", @@ -1177,7 +1197,7 @@ dependencies = [ "cwd-proposal-single", "cwd-voting", "neutron-dao-pre-propose-overrule", - "neutron-sdk 0.5.0", + "neutron-sdk", "neutron-subdao-core", "neutron-subdao-pre-propose-single", "neutron-subdao-timelock-single", @@ -1237,7 +1257,7 @@ dependencies = [ "cwd-core", "cwd-interface", "cwd-macros", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -1253,6 +1273,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + [[package]] name = "derivative" version = "2.2.0" @@ -1275,9 +1301,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common", @@ -1292,9 +1318,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dyn-clone" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" +checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" [[package]] name = "ecdsa" @@ -1325,9 +1351,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" @@ -1338,7 +1364,7 @@ dependencies = [ "base16ct", "crypto-bigint", "der", - "digest 0.10.6", + "digest 0.10.7", "ff", "generic-array", "group", @@ -1396,9 +1422,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", @@ -1437,7 +1463,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -1460,13 +1486,13 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", + "cw-controllers 1.1.0", + "cw-multi-test 0.16.5", "cw-paginate 0.2.0", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cw-utils 1.0.1", "cw2 0.13.4", - "cw20 1.0.1", + "cw20 1.1.0", "cwd-interface", "cwd-macros", "cwd-voting", @@ -1487,9 +1513,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "k256" @@ -1500,21 +1526,21 @@ dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] name = "libc" -version = "0.2.141" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "lockdrop-vault" version = "0.1.0" dependencies = [ "anyhow", - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "astroport-periphery", "cosmwasm-schema", "cosmwasm-std", @@ -1546,7 +1572,7 @@ version = "0.1.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cwd-macros", "exec-control", "schemars", @@ -1583,37 +1609,16 @@ dependencies = [ "astroport 2.8.0", "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "cw20 0.13.4", "cwd-macros", "exec-control", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", ] -[[package]] -name = "neutron-sdk" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a57cb451a16a676ecbbb1bb1e0e2e9bc9989834d82c6b16eebc24d9ed97cf" -dependencies = [ - "base64 0.20.0", - "bech32", - "cosmos-sdk-proto", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.0.1", - "prost 0.11.9", - "protobuf 3.2.0", - "schemars", - "serde", - "serde-json-wasm 0.4.1", - "serde_json", - "thiserror", -] - [[package]] name = "neutron-sdk" version = "0.5.0" @@ -1625,7 +1630,7 @@ dependencies = [ "cosmos-sdk-proto", "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.1.0", "prost 0.11.9", "protobuf 3.2.0", "schemars", @@ -1644,7 +1649,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1660,7 +1665,7 @@ dependencies = [ "cwd-macros", "cwd-voting", "exec-control", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", "thiserror", @@ -1674,7 +1679,7 @@ dependencies = [ "cwd-interface", "cwd-pre-propose-base", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1687,7 +1692,7 @@ dependencies = [ "cw-utils 0.13.4", "cwd-macros", "cwd-voting", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1697,7 +1702,7 @@ name = "neutron-subdao-timelock-single" version = "0.1.0" dependencies = [ "cosmwasm-std", - "neutron-sdk 0.5.0", + "neutron-sdk", "schemars", "serde", ] @@ -1770,18 +1775,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -1791,9 +1796,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "paste" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pkcs8" @@ -1813,9 +1818,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1918,9 +1923,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -1961,24 +1966,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rescueeer" -version = "0.2.0" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-controllers 1.0.1", - "cw-multi-test 0.16.4", - "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", - "neutron-sdk 0.4.0", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "rfc6979" version = "0.3.1" @@ -1992,9 +1979,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "schemars" @@ -2036,15 +2023,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.160" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] @@ -2069,22 +2056,22 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.28", ] [[package]] @@ -2100,9 +2087,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "itoa", "ryu", @@ -2124,13 +2111,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -2139,7 +2126,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "rand_core 0.6.4", ] @@ -2182,9 +2169,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "subtle-encoding" @@ -2208,9 +2195,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -2237,12 +2224,13 @@ dependencies = [ [[package]] name = "terraswap" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9540f8489ec6e098de380c9fa8fa81fa95e502f87d63705aa6fba56817ad1a7" +checksum = "73bbfb46c586aeaaa91da9532bff8b12fd909dcc80ff2817d58b87eab2f3a2b5" dependencies = [ "cosmwasm-std", "cosmwasm-storage", + "cw2 0.13.4", "cw20 0.13.4", "protobuf 2.28.0", "schemars", @@ -2251,45 +2239,46 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.28", ] [[package]] name = "time" -version = "0.3.20" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ + "deranged", "time-core", "time-macros", ] [[package]] name = "time-core" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" dependencies = [ "time-core", ] @@ -2314,9 +2303,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "version_check" @@ -2327,9 +2316,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", @@ -2343,7 +2332,7 @@ dependencies = [ [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", "cosmwasm-schema", @@ -2359,14 +2348,14 @@ dependencies = [ [[package]] name = "vesting-lp" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#0c7175d125e0208ad94868f5cd0b634c1fc76ad1" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b#e306308dd23d567399c15d899f295a910ede945b" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 0.15.1", "cw2 0.15.1", - "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", ] [[package]] @@ -2374,7 +2363,7 @@ name = "vesting-lp-vault" version = "0.1.0" dependencies = [ "anyhow", - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "astroport 2.8.0", "astroport-pair-concentrated", "astroport-xastro-token", @@ -2390,7 +2379,7 @@ dependencies = [ "schemars", "serde", "thiserror", - "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "vesting-lp", ] diff --git a/contracts/dao/voting/lockdrop-vault/Cargo.toml b/contracts/dao/voting/lockdrop-vault/Cargo.toml index ecf4c720..098ba5fe 100644 --- a/contracts/dao/voting/lockdrop-vault/Cargo.toml +++ b/contracts/dao/voting/lockdrop-vault/Cargo.toml @@ -27,8 +27,8 @@ cwd-macros = { path = "../../../../packages/cwd-macros" } cwd-interface = { path = "../../../../packages/cwd-interface" } cwd-voting = { path = "../../../../packages/cwd-voting" } neutron-lockdrop-vault = { path = "../../../../packages/neutron-lockdrop-vault" } -astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } [dev-dependencies] cosmwasm-schema = { version = "^1.2.1" } diff --git a/contracts/dao/voting/vesting-lp-vault/Cargo.toml b/contracts/dao/voting/vesting-lp-vault/Cargo.toml index 57783096..a1fb8a85 100644 --- a/contracts/dao/voting/vesting-lp-vault/Cargo.toml +++ b/contracts/dao/voting/vesting-lp-vault/Cargo.toml @@ -25,10 +25,10 @@ thiserror = { version = "1.0" } cwd-macros = { path = "../../../../packages/cwd-macros" } cwd-interface = { path = "../../../../packages/cwd-interface" } neutron-vesting-lp-vault = { path = "../../../../packages/neutron-vesting-lp-vault" } -neutron-oracle = { path = "../../../../packages/neutron-oracle" } -vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } -vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +neutron-oracle = { path = "../../../../packages/neutron-voting-power" } +vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } +vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } [dev-dependencies] cosmwasm-schema = { version = "1.0.0" } diff --git a/contracts/dao/voting/vesting-lp-vault/src/contract.rs b/contracts/dao/voting/vesting-lp-vault/src/contract.rs index dd1baee3..741fb5f8 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/contract.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/contract.rs @@ -203,7 +203,7 @@ fn get_voting_power( &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, )?; - voting_power += voting_power_from_lp_tokens( + voting_power = voting_power.checked_add(voting_power_from_lp_tokens( deps, deps.querier .query_wasm_smart::>(vesting_lp, &query_msg)? @@ -211,7 +211,7 @@ fn get_voting_power( lp_total_supply, cl_pool, height, - )?; + )?)?; } Ok(voting_power) } diff --git a/packages/cwd-hooks/src/lib.rs b/packages/cwd-hooks/src/lib.rs index 5048a8eb..7a009d7e 100644 --- a/packages/cwd-hooks/src/lib.rs +++ b/packages/cwd-hooks/src/lib.rs @@ -32,7 +32,7 @@ impl<'a> Hooks<'a> { pub fn add_hook(&self, storage: &mut dyn Storage, addr: Addr) -> Result<(), HookError> { let mut hooks = self.0.may_load(storage)?.unwrap_or_default(); - if !hooks.iter().any(|h| h == &addr) { + if !hooks.iter().any(|h| h == addr) { hooks.push(addr); } else { return Err(HookError::HookAlreadyRegistered {}); @@ -42,7 +42,7 @@ impl<'a> Hooks<'a> { pub fn remove_hook(&self, storage: &mut dyn Storage, addr: Addr) -> Result<(), HookError> { let mut hooks = self.0.load(storage)?; - if let Some(p) = hooks.iter().position(|x| x == &addr) { + if let Some(p) = hooks.iter().position(|x| x == addr) { hooks.remove(p); } else { return Err(HookError::HookNotRegistered {}); diff --git a/packages/neutron-lockdrop-vault/Cargo.toml b/packages/neutron-lockdrop-vault/Cargo.toml index 3d576f90..ddc65b49 100644 --- a/packages/neutron-lockdrop-vault/Cargo.toml +++ b/packages/neutron-lockdrop-vault/Cargo.toml @@ -12,6 +12,6 @@ cwd-macros = { path = "../cwd-macros" } schemars = "0.8" serde = { version = "1.0.147", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } -astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } -neutron-oracle = { path = "../neutron-oracle" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +neutron-oracle = { path = "../neutron-voting-power" } astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } diff --git a/packages/neutron-vesting-lp-vault/src/error.rs b/packages/neutron-vesting-lp-vault/src/error.rs index 2f42b205..3d0bd284 100644 --- a/packages/neutron-vesting-lp-vault/src/error.rs +++ b/packages/neutron-vesting-lp-vault/src/error.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::StdError; +use cosmwasm_std::{OverflowError, StdError}; use thiserror::Error; #[derive(Error, Debug, PartialEq)] @@ -20,6 +20,9 @@ pub enum ContractError { #[error("config description cannot be empty.")] DescriptionIsEmpty {}, + + #[error("{0}")] + OverflowError(#[from] OverflowError), } pub type ContractResult = Result; diff --git a/packages/neutron-oracle/Cargo.toml b/packages/neutron-voting-power/Cargo.toml similarity index 100% rename from packages/neutron-oracle/Cargo.toml rename to packages/neutron-voting-power/Cargo.toml diff --git a/packages/neutron-oracle/src/lib.rs b/packages/neutron-voting-power/src/lib.rs similarity index 100% rename from packages/neutron-oracle/src/lib.rs rename to packages/neutron-voting-power/src/lib.rs diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-voting-power/src/voting_power.rs similarity index 100% rename from packages/neutron-oracle/src/voting_power.rs rename to packages/neutron-voting-power/src/voting_power.rs From 686f2670ab24a7569c1ca048c549743edf15b558 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 7 Aug 2023 16:38:57 +0300 Subject: [PATCH 18/23] review fixes --- Cargo.lock | 15 +-------------- packages/neutron-lockdrop-vault/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d562bc1..ed264463 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,19 +19,6 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" -[[package]] -name = "astroport" -version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "cw20 0.15.1", - "itertools", - "uint", -] - [[package]] name = "astroport" version = "2.0.0" @@ -1584,7 +1571,7 @@ dependencies = [ name = "neutron-lockdrop-vault" version = "0.1.0" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", "astroport-periphery", "cosmwasm-std", "cwd-macros", diff --git a/packages/neutron-lockdrop-vault/Cargo.toml b/packages/neutron-lockdrop-vault/Cargo.toml index ddc65b49..32af1b43 100644 --- a/packages/neutron-lockdrop-vault/Cargo.toml +++ b/packages/neutron-lockdrop-vault/Cargo.toml @@ -14,4 +14,4 @@ serde = { version = "1.0.147", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } neutron-oracle = { path = "../neutron-voting-power" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } From 0edde36c67f4c9c96b68b4fa915003071070300a Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Wed, 9 Aug 2023 19:56:04 +0300 Subject: [PATCH 19/23] separate contracts for migrated lockdrop and vesting lp vaults to cl pools --- Cargo.lock | 148 +++- .../lockdrop-vault-for-cl-pools/.cargo/config | 4 + .../lockdrop-vault-for-cl-pools/Cargo.toml | 36 + .../lockdrop-vault-for-cl-pools/README.md | 3 + .../examples/schema.rs | 31 + .../schema/execute_msg.json | 94 +++ .../schema/instantiate_msg.json | 39 + .../schema/query_msg.json | 172 +++++ .../src/contract.rs | 297 +++++++ .../lockdrop-vault-for-cl-pools/src/lib.rs | 5 + .../lockdrop-vault-for-cl-pools/src/state.rs | 6 + .../lockdrop-vault-for-cl-pools/src/tests.rs | 444 +++++++++++ .../dao/voting/lockdrop-vault/Cargo.toml | 4 +- .../dao/voting/lockdrop-vault/src/contract.rs | 63 +- .../dao/voting/lockdrop-vault/src/state.rs | 3 +- .../dao/voting/lockdrop-vault/src/tests.rs | 289 +++++-- .../.cargo/config | 4 + .../vesting-lp-vault-for-cl-pools/Cargo.toml | 39 + .../vesting-lp-vault-for-cl-pools/README.md | 3 + .../examples/schema.rs | 34 + .../schema/bonding_status_response.json | 29 + .../schema/dao_response.json | 6 + .../schema/execute_msg.json | 88 +++ .../schema/get_config_response.json | 43 ++ .../schema/info_response.json | 33 + .../schema/instantiate_msg.json | 44 ++ .../schema/migrate_msg.json | 5 + .../schema/query_msg.json | 172 +++++ .../total_power_at_height_response.json | 25 + .../voting_power_at_height_response.json | 25 + .../src/contract.rs | 302 ++++++++ .../vesting-lp-vault-for-cl-pools/src/lib.rs | 5 + .../src/state.rs | 6 + .../src/tests.rs | 727 ++++++++++++++++++ .../dao/voting/vesting-lp-vault/Cargo.toml | 10 +- .../vesting-lp-vault/schema/execute_msg.json | 8 +- .../schema/get_config_response.json | 8 +- .../schema/instantiate_msg.json | 12 +- .../vesting-lp-vault/schema/migrate_msg.json | 14 +- .../voting/vesting-lp-vault/src/contract.rs | 87 +-- .../dao/voting/vesting-lp-vault/src/state.rs | 3 +- .../dao/voting/vesting-lp-vault/src/tests.rs | 224 +----- .../Cargo.toml | 17 + .../src/error.rs | 25 + .../src/lib.rs | 4 + .../src/msg.rs | 45 ++ .../src/types.rs | 73 ++ .../src/voting_power.rs | 81 ++ packages/neutron-lockdrop-vault/Cargo.toml | 5 +- packages/neutron-lockdrop-vault/src/msg.rs | 13 +- packages/neutron-lockdrop-vault/src/types.rs | 24 +- .../src/voting_power.rs | 48 +- packages/neutron-oracle/Cargo.toml | 11 + packages/neutron-oracle/src/lib.rs | 1 + packages/neutron-oracle/src/voting_power.rs | 32 + .../Cargo.toml | 14 + .../src/error.rs | 28 + .../src/lib.rs | 3 + .../src/msg.rs | 48 ++ .../src/types.rs | 76 ++ .../neutron-vesting-lp-vault/src/error.rs | 5 +- packages/neutron-vesting-lp-vault/src/msg.rs | 17 +- .../neutron-vesting-lp-vault/src/types.rs | 25 +- packages/neutron-voting-power/Cargo.toml | 2 +- 64 files changed, 3706 insertions(+), 485 deletions(-) create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/.cargo/config create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/Cargo.toml create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/README.md create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/examples/schema.rs create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/instantiate_msg.json create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/src/lib.rs create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/src/state.rs create mode 100644 contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/.cargo/config create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/Cargo.toml create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/README.md create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/examples/schema.rs create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/bonding_status_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/dao_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/execute_msg.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/get_config_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/info_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/instantiate_msg.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/migrate_msg.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/total_power_at_height_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/voting_power_at_height_response.json create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/contract.rs create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/lib.rs create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/state.rs create mode 100644 contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/Cargo.toml create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/src/error.rs create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/src/lib.rs create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/src/types.rs create mode 100644 packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs create mode 100644 packages/neutron-oracle/Cargo.toml create mode 100644 packages/neutron-oracle/src/lib.rs create mode 100644 packages/neutron-oracle/src/voting_power.rs create mode 100644 packages/neutron-vesting-lp-vault-for-cl-pools/Cargo.toml create mode 100644 packages/neutron-vesting-lp-vault-for-cl-pools/src/error.rs create mode 100644 packages/neutron-vesting-lp-vault-for-cl-pools/src/lib.rs create mode 100644 packages/neutron-vesting-lp-vault-for-cl-pools/src/msg.rs create mode 100644 packages/neutron-vesting-lp-vault-for-cl-pools/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index ab14377b..8ef34f9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,19 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +[[package]] +name = "astroport" +version = "2.0.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw20 0.15.1", + "itertools", + "uint", +] + [[package]] name = "astroport" version = "2.0.0" @@ -105,6 +118,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "astroport-periphery" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" +dependencies = [ + "astroport 2.5.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw20 0.13.4", + "schemars", + "serde", + "terraswap", +] + [[package]] name = "astroport-periphery" version = "1.1.0" @@ -1633,8 +1661,8 @@ name = "lockdrop-vault" version = "0.1.0" dependencies = [ "anyhow", - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", - "astroport-periphery", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "astroport-periphery 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", @@ -1650,6 +1678,28 @@ dependencies = [ "thiserror", ] +[[package]] +name = "lockdrop-vault-for-cl-pools" +version = "0.1.0" +dependencies = [ + "anyhow", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", + "astroport-periphery 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus 1.1.0", + "cw2 1.1.0", + "cw20 1.1.0", + "cwd-interface", + "cwd-macros", + "cwd-voting", + "neutron-lockdrop-vault-for-cl-pools", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "neutron-dao-pre-propose-overrule" version = "0.1.0" @@ -1677,8 +1727,7 @@ dependencies = [ name = "neutron-lockdrop-vault" version = "0.1.0" dependencies = [ - "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", - "astroport-periphery", + "astroport-periphery 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-std", "cwd-macros", "neutron-oracle", @@ -1687,11 +1736,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "neutron-lockdrop-vault-for-cl-pools" +version = "0.1.0" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", + "astroport-periphery 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", + "cosmwasm-std", + "cwd-macros", + "neutron-voting-power", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "neutron-oracle" version = "0.1.0" dependencies = [ - "astroport 2.8.0", + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-std", ] @@ -1833,6 +1896,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "neutron-vesting-lp-vault-for-cl-pools" +version = "0.1.0" +dependencies = [ + "cosmwasm-std", + "cwd-macros", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "neutron-voting-power" +version = "0.1.0" +dependencies = [ + "astroport 2.8.0", + "cosmwasm-std", +] + [[package]] name = "neutron-voting-registry" version = "0.2.0" @@ -2397,6 +2479,22 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vesting-base" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw2 0.15.1", + "cw20 0.15.1", + "serde", + "thiserror", +] + [[package]] name = "vesting-base" version = "1.1.0" @@ -2429,6 +2527,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "vesting-lp" +version = "1.1.0" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#e306308dd23d567399c15d899f295a910ede945b" +dependencies = [ + "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw2 0.15.1", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", +] + [[package]] name = "vesting-lp" version = "1.1.0" @@ -2445,6 +2556,27 @@ dependencies = [ [[package]] name = "vesting-lp-vault" version = "0.1.0" +dependencies = [ + "anyhow", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus 1.1.0", + "cw2 1.1.0", + "cwd-interface", + "cwd-macros", + "neutron-oracle", + "neutron-vesting-lp-vault", + "schemars", + "serde", + "thiserror", + "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", + "vesting-lp 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", +] + +[[package]] +name = "vesting-lp-vault-for-cl-pools" +version = "0.1.0" dependencies = [ "anyhow", "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", @@ -2458,13 +2590,13 @@ dependencies = [ "cw2 1.1.0", "cwd-interface", "cwd-macros", - "neutron-oracle", - "neutron-vesting-lp-vault", + "neutron-vesting-lp-vault-for-cl-pools", + "neutron-voting-power", "schemars", "serde", "thiserror", "vesting-base 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", - "vesting-lp", + "vesting-lp 1.1.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?rev=e306308dd23d567399c15d899f295a910ede945b)", ] [[package]] diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/.cargo/config b/contracts/dao/voting/lockdrop-vault-for-cl-pools/.cargo/config new file mode 100644 index 00000000..336b618a --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/Cargo.toml b/contracts/dao/voting/lockdrop-vault-for-cl-pools/Cargo.toml new file mode 100644 index 00000000..579a5177 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "lockdrop-vault-for-cl-pools" +version = "0.1.0" +authors = ["Sergei Sotnikov "] +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/neutron/neutron-dao" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-std = { version = "1.3.0" } +cw-storage-plus = "1.1.0" +cw2 = "1.1.0" +cw20 = "1.1.0" +schemars = "0.8.8" +serde = { version = "1.0.175", default-features = false, features = ["derive"] } +thiserror = { version = "1.0" } +cwd-macros = { path = "../../../../packages/cwd-macros" } +cwd-interface = { path = "../../../../packages/cwd-interface" } +cwd-voting = { path = "../../../../packages/cwd-voting" } +neutron-lockdrop-vault-for-cl-pools = { path = "../../../../packages/neutron-lockdrop-vault-for-cl-pools" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } + +[dev-dependencies] +cosmwasm-schema = { version = "^1.2.1" } +cw-multi-test = "0.16.5" +anyhow = "1.0.57" diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/README.md b/contracts/dao/voting/lockdrop-vault-for-cl-pools/README.md new file mode 100644 index 00000000..d9277633 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/README.md @@ -0,0 +1,3 @@ +### Neutron Lockdrop Voting Vault + +This contract is not really a voting vault. It's rather an interface to get voting power from a Lockdrop contract. It's not possible to Bond or Unbond funds to this vault cause these ExecuteMsg handlers are introduced just to make the contract comply with the voting vault interface. diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/examples/schema.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/examples/schema.rs new file mode 100644 index 00000000..9293d06d --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/examples/schema.rs @@ -0,0 +1,31 @@ +// Copyright 2022 Neutron +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::env::current_dir; +use std::fs::create_dir_all; + +use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; + +use neutron_lockdrop_vault_for_cl_pools::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); +} diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json new file mode 100644 index 00000000..a654b145 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json @@ -0,0 +1,94 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "update_config" + ], + "properties": { + "update_config": { + "type": "object", + "properties": { + "description": { + "type": [ + "string", + "null" + ] + }, + "lockdrop_contract": { + "type": [ + "string", + "null" + ] + }, + "name": { + "type": [ + "string", + "null" + ] + }, + "oracle_atom_contract": { + "type": [ + "string", + "null" + ] + }, + "oracle_usdc_contract": { + "type": [ + "string", + "null" + ] + }, + "owner": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bond" + ], + "properties": { + "bond": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "unbond" + ], + "properties": { + "unbond": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/instantiate_msg.json b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/instantiate_msg.json new file mode 100644 index 00000000..b8baf0bb --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/instantiate_msg.json @@ -0,0 +1,39 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "atom_cl_pool_contract", + "description", + "lockdrop_contract", + "name", + "owner", + "usdc_cl_pool_contract" + ], + "properties": { + "atom_cl_pool_contract": { + "description": "The ATOM/NTRN CL pool oracle contract.", + "type": "string" + }, + "description": { + "description": "Description contains information that characterizes the vault.", + "type": "string" + }, + "lockdrop_contract": { + "description": "The lockdrop contract behind the vault.", + "type": "string" + }, + "name": { + "description": "Name contains the vault name which is used to ease the vault's recognition.", + "type": "string" + }, + "owner": { + "description": "Owner can update all configs including changing the owner. This will generally be a DAO.", + "type": "string" + }, + "usdc_cl_pool_contract": { + "description": "The USDC/NTRN CL pool contract.", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json new file mode 100644 index 00000000..a7567a73 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json @@ -0,0 +1,172 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "voting_power_at_height" + ], + "properties": { + "voting_power_at_height": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + }, + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "total_power_at_height" + ], + "properties": { + "total_power_at_height": { + "type": "object", + "properties": { + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bonding_status" + ], + "properties": { + "bonding_status": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + }, + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "dao" + ], + "properties": { + "dao": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "list_bonders" + ], + "properties": { + "list_bonders": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs new file mode 100644 index 00000000..1bc07c8f --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs @@ -0,0 +1,297 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, Uint128}; +use cw2::set_contract_version; +use cwd_interface::voting::{ + BondingStatusResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, +}; +use neutron_lockdrop_vault_for_cl_pools::voting_power::{ + get_voting_power_for_address, get_voting_power_total, +}; + +use crate::state::{CONFIG, DAO}; + +use astroport_periphery::lockdrop::PoolType; +use neutron_lockdrop_vault_for_cl_pools::error::{ContractError, ContractResult}; +use neutron_lockdrop_vault_for_cl_pools::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use neutron_lockdrop_vault_for_cl_pools::types::Config; + +pub(crate) const CONTRACT_NAME: &str = "crates.io:neutron-lockdrop-vault-for-cl-pools-for-cl-pools"; +pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: InstantiateMsg, +) -> ContractResult { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let owner = deps.api.addr_validate(&msg.owner)?; + + let config = Config { + name: msg.name, + description: msg.description, + lockdrop_contract: deps.api.addr_validate(&msg.lockdrop_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, + owner, + }; + config.validate()?; + CONFIG.save(deps.storage, &config)?; + DAO.save(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_attribute("action", "instantiate") + .add_attribute("name", config.name) + .add_attribute("description", config.description) + .add_attribute("owner", config.owner) + .add_attribute("lockdrop_contract", config.lockdrop_contract) + .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) + .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> ContractResult { + match msg { + ExecuteMsg::Bond {} => execute_bond(deps, env, info), + ExecuteMsg::Unbond { amount } => execute_unbond(deps, env, info, amount), + ExecuteMsg::UpdateConfig { + owner, + lockdrop_contract, + oracle_usdc_contract, + oracle_atom_contract, + name, + description, + } => execute_update_config( + deps, + info, + owner, + lockdrop_contract, + oracle_usdc_contract, + oracle_atom_contract, + name, + description, + ), + } +} + +pub fn execute_bond(_deps: DepsMut, _env: Env, _info: MessageInfo) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +pub fn execute_unbond( + _deps: DepsMut, + _env: Env, + _info: MessageInfo, + _amount: Uint128, +) -> ContractResult { + Err(ContractError::DirectUnbondingDisabled {}) +} + +#[allow(clippy::too_many_arguments)] +pub fn execute_update_config( + deps: DepsMut, + info: MessageInfo, + new_owner: Option, + new_lockdrop_contract: Option, + new_oracle_usdc_contract: Option, + new_oracle_atom_contract: Option, + new_name: Option, + new_description: Option, +) -> ContractResult { + let mut config: Config = CONFIG.load(deps.storage)?; + if info.sender != config.owner { + return Err(ContractError::Unauthorized {}); + } + + let new_owner = new_owner + .map(|new_owner| deps.api.addr_validate(&new_owner)) + .transpose()?; + + let new_lockdrop_contract = new_lockdrop_contract + .map(|new_lockdrop_contract| deps.api.addr_validate(&new_lockdrop_contract)) + .transpose()?; + + let new_oracle_usdc_contract = new_oracle_usdc_contract + .map(|new_oracle_usdc_contract| deps.api.addr_validate(&new_oracle_usdc_contract)) + .transpose()?; + + let new_oracle_atom_contract = new_oracle_atom_contract + .map(|new_oracle_atom_contract| deps.api.addr_validate(&new_oracle_atom_contract)) + .transpose()?; + + if let Some(owner) = new_owner { + config.owner = owner; + } + + if let Some(lockdrop_contract) = new_lockdrop_contract { + config.lockdrop_contract = lockdrop_contract; + } + if let Some(oracle_contract) = new_oracle_usdc_contract { + config.usdc_cl_pool_contract = oracle_contract; + } + if let Some(oracle_contract) = new_oracle_atom_contract { + config.atom_cl_pool_contract = oracle_contract; + } + if let Some(name) = new_name { + config.name = name; + } + if let Some(description) = new_description { + config.description = description; + } + + config.validate()?; + CONFIG.save(deps.storage, &config)?; + + Ok(Response::new() + .add_attribute("action", "update_config") + .add_attribute("description", config.description) + .add_attribute("owner", config.owner) + .add_attribute("lockdrop_contract", config.lockdrop_contract) + .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) + .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> ContractResult { + match msg { + QueryMsg::VotingPowerAtHeight { address, height } => Ok(to_binary( + &query_voting_power_at_height(deps, env, address, height)?, + )?), + QueryMsg::TotalPowerAtHeight { height } => { + Ok(to_binary(&query_total_power_at_height(deps, env, height)?)?) + } + QueryMsg::Info {} => query_info(deps), + QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Name {} => query_name(deps), + QueryMsg::Description {} => query_description(deps), + QueryMsg::Config {} => query_config(deps), + QueryMsg::ListBonders { start_after, limit } => { + query_list_bonders(deps, start_after, limit) + } + QueryMsg::BondingStatus { height, address } => Ok(to_binary(&query_bonding_status( + deps, env, height, address, + )?)?), + } +} + +pub fn query_voting_power_at_height( + deps: Deps, + env: Env, + address: String, + height: Option, +) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + + let height = height.unwrap_or(env.block.height); + + let atom_power = get_voting_power_for_address( + deps, + config.lockdrop_contract.as_ref(), + config.usdc_cl_pool_contract.as_ref(), + config.atom_cl_pool_contract.as_ref(), + PoolType::ATOM, + address.clone(), + height, + )?; + let usdc_power = get_voting_power_for_address( + deps, + config.lockdrop_contract, + config.usdc_cl_pool_contract, + config.atom_cl_pool_contract, + PoolType::USDC, + address, + height, + )?; + + let power = atom_power + usdc_power; + + Ok(VotingPowerAtHeightResponse { power, height }) +} + +pub fn query_total_power_at_height( + deps: Deps, + env: Env, + height: Option, +) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + + let height = height.unwrap_or(env.block.height); + + let atom_power = get_voting_power_total( + deps, + config.lockdrop_contract.as_ref(), + config.usdc_cl_pool_contract.as_ref(), + config.atom_cl_pool_contract.as_ref(), + PoolType::ATOM, + height, + )?; + let usdc_power = get_voting_power_total( + deps, + config.lockdrop_contract, + config.usdc_cl_pool_contract, + config.atom_cl_pool_contract, + PoolType::USDC, + height, + )?; + + let power = atom_power + usdc_power; + + Ok(TotalPowerAtHeightResponse { power, height }) +} + +pub fn query_info(deps: Deps) -> ContractResult { + let info = cw2::get_contract_version(deps.storage)?; + Ok(to_binary(&cwd_interface::voting::InfoResponse { info })?) +} + +pub fn query_dao(deps: Deps) -> ContractResult { + let dao = DAO.load(deps.storage)?; + Ok(to_binary(&dao)?) +} + +pub fn query_name(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config.name)?) +} + +pub fn query_description(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config.description)?) +} + +pub fn query_config(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config)?) +} + +pub fn query_list_bonders( + _deps: Deps, + _start_after: Option, + _limit: Option, +) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +pub fn query_bonding_status( + _deps: Deps, + _env: Env, + _height: Option, + _address: String, +) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _: MigrateMsg) -> ContractResult { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + Ok(Response::default()) +} diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/lib.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/lib.rs new file mode 100644 index 00000000..da3bbc25 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/lib.rs @@ -0,0 +1,5 @@ +pub mod contract; +pub mod state; + +#[cfg(test)] +mod tests; diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/state.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/state.rs new file mode 100644 index 00000000..fd89a2d1 --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/state.rs @@ -0,0 +1,6 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; +use neutron_lockdrop_vault_for_cl_pools::types::Config; + +pub const CONFIG: Item = Item::new("config"); +pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs new file mode 100644 index 00000000..db446ccd --- /dev/null +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs @@ -0,0 +1,444 @@ +use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; +use cosmwasm_std::testing::{mock_dependencies, mock_env}; +use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; +use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; +use cwd_interface::voting::InfoResponse; +use neutron_lockdrop_vault_for_cl_pools::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; +use neutron_lockdrop_vault_for_cl_pools::types::Config; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +const DAO_ADDR: &str = "dao"; +const NAME: &str = "name"; +const NEW_NAME: &str = "new_name"; +const DESCRIPTION: &str = "description"; +const NEW_DESCRIPTION: &str = "new description"; +const LOCKDROP_ADDR: &str = "lockdrop"; +const ORACLE_USDC_ADDR: &str = "oracle_usdc"; +const ORACLE_ATOM_ADDR: &str = "oracle_atom"; +const NEW_LOCKDROP_ADDR: &str = "new_lockdrop"; +const NEW_ORACLE_USDC_ADDR: &str = "new_oracle_usdc"; +const NEW_ORACLE_ATOM_ADDR: &str = "new_oracle_atom"; +const ADDR1: &str = "addr1"; +const ADDR2: &str = "addr2"; +const DENOM: &str = "ujuno"; +const INIT_BALANCE: Uint128 = Uint128::new(10000); + +fn vault_contract() -> Box> { + let contract = ContractWrapper::new( + crate::contract::execute, + crate::contract::instantiate, + crate::contract::query, + ); + Box::new(contract) +} + +fn mock_app() -> App { + custom_app(|r, _a, s| { + r.bank + .init_balance( + s, + &Addr::unchecked(DAO_ADDR), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + r.bank + .init_balance( + s, + &Addr::unchecked(ADDR1), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + r.bank + .init_balance( + s, + &Addr::unchecked(ADDR2), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + }) +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[serde(rename_all = "snake_case")] +pub struct EmptyMsg {} + +fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { + app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vault", None) + .unwrap() +} + +fn bond_tokens( + app: &mut App, + contract_addr: Addr, + sender: &str, + amount: u128, + denom: &str, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::Bond {}, + &coins(amount, denom), + ) +} + +fn unbond_tokens( + app: &mut App, + contract_addr: Addr, + sender: &str, + amount: u128, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::Unbond { + amount: Uint128::new(amount), + }, + &[], + ) +} + +#[allow(clippy::too_many_arguments)] +fn update_config( + app: &mut App, + contract_addr: Addr, + sender: &str, + owner: Option, + lockdrop_contract: Option, + oracle_usdc_contract: Option, + oracle_atom_contract: Option, + name: Option, + description: Option, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::UpdateConfig { + owner, + lockdrop_contract, + oracle_usdc_contract, + oracle_atom_contract, + name, + description, + }, + &[], + ) +} + +fn get_config(app: &mut App, contract_addr: Addr) -> Config { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::Config {}) + .unwrap() +} + +fn get_dao(app: &App, contract_addr: &Addr) -> String { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::Dao {}) + .unwrap() +} + +#[test] +fn test_instantiate() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); +} + +#[test] +#[should_panic(expected = "Bonding is not available for this contract")] +fn test_bond() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + // Try and bond an invalid denom + bond_tokens(&mut app, addr, ADDR1, 100, DENOM).unwrap(); +} + +#[test] +#[should_panic(expected = "Direct unbonding is not available for this contract")] +fn test_unbond() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + unbond_tokens(&mut app, addr, ADDR1, 100).unwrap(); +} + +#[test] +#[should_panic(expected = "Unauthorized")] +fn test_update_config_unauthorized() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + // From ADDR2, so not owner + update_config( + &mut app, + addr, + ADDR2, + Some(ADDR1.to_string()), + Some(NEW_LOCKDROP_ADDR.to_string()), + Some(NEW_ORACLE_USDC_ADDR.to_string()), + Some(NEW_ORACLE_ATOM_ADDR.to_string()), + Some(NEW_NAME.to_string()), + Some(NEW_DESCRIPTION.to_string()), + ) + .unwrap(); +} + +#[test] +fn test_update_config_as_owner() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + // Change owner, description, name and lockdrop contract + update_config( + &mut app, + addr.clone(), + DAO_ADDR, + Some(ADDR1.to_string()), + Some(NEW_LOCKDROP_ADDR.to_string()), + Some(NEW_ORACLE_USDC_ADDR.to_string()), + Some(NEW_ORACLE_ATOM_ADDR.to_string()), + Some(NEW_NAME.to_string()), + Some(NEW_DESCRIPTION.to_string()), + ) + .unwrap(); + + let config = get_config(&mut app, addr); + assert_eq!( + Config { + name: NEW_NAME.to_string(), + description: NEW_DESCRIPTION.to_string(), + owner: Addr::unchecked(ADDR1), + lockdrop_contract: Addr::unchecked(NEW_LOCKDROP_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), + }, + config + ); +} + +#[test] +#[should_panic(expected = "config description cannot be empty.")] +fn test_update_config_invalid_description() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + // Change name + update_config( + &mut app, + addr, + DAO_ADDR, + Some(DAO_ADDR.to_string()), + Some(LOCKDROP_ADDR.to_string()), + Some(ORACLE_USDC_ADDR.to_string()), + Some(ORACLE_ATOM_ADDR.to_string()), + Some(NEW_NAME.to_string()), + Some(String::from("")), + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "config name cannot be empty.")] +fn test_update_config_invalid_name() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + // Change description + update_config( + &mut app, + addr, + DAO_ADDR, + Some(DAO_ADDR.to_string()), + Some(LOCKDROP_ADDR.to_string()), + Some(ORACLE_USDC_ADDR.to_string()), + Some(ORACLE_ATOM_ADDR.to_string()), + Some(String::from("")), + Some(NEW_DESCRIPTION.to_string()), + ) + .unwrap(); +} + +#[test] +fn test_query_dao() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + let msg = QueryMsg::Dao {}; + let dao: Addr = app.wrap().query_wasm_smart(addr, &msg).unwrap(); + assert_eq!(dao, Addr::unchecked(DAO_ADDR)); +} + +#[test] +fn test_query_info() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + let msg = QueryMsg::Info {}; + let resp: InfoResponse = app.wrap().query_wasm_smart(addr, &msg).unwrap(); + assert_eq!( + resp.info.contract, + "crates.io:neutron-lockdrop-vault-for-cl-pools-for-cl-pools" + ); +} + +#[test] +fn test_query_get_config() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: LOCKDROP_ADDR.to_string(), + usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), + atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + }, + ); + + let config = get_config(&mut app, addr); + assert_eq!( + config, + Config { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: Addr::unchecked(DAO_ADDR), + lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), + usdc_cl_pool_contract: Addr::unchecked(ORACLE_USDC_ADDR), + atom_cl_pool_contract: Addr::unchecked(ORACLE_ATOM_ADDR), + } + ) +} + +#[test] +pub fn test_migrate_update_version() { + let mut deps = mock_dependencies(); + cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); + + migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); + let version = cw2::get_contract_version(&deps.storage).unwrap(); + + assert_eq!(version.version, CONTRACT_VERSION); + assert_eq!(version.contract, CONTRACT_NAME); +} diff --git a/contracts/dao/voting/lockdrop-vault/Cargo.toml b/contracts/dao/voting/lockdrop-vault/Cargo.toml index 7b42ab73..963a6bee 100644 --- a/contracts/dao/voting/lockdrop-vault/Cargo.toml +++ b/contracts/dao/voting/lockdrop-vault/Cargo.toml @@ -27,8 +27,8 @@ cwd-macros = { path = "../../../../packages/cwd-macros" } cwd-interface = { path = "../../../../packages/cwd-interface" } cwd-voting = { path = "../../../../packages/cwd-voting" } neutron-lockdrop-vault = { path = "../../../../packages/neutron-lockdrop-vault" } -astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } [dev-dependencies] cosmwasm-schema = { version = "^1.2.1" } diff --git a/contracts/dao/voting/lockdrop-vault/src/contract.rs b/contracts/dao/voting/lockdrop-vault/src/contract.rs index 0271be9e..028d3f1b 100644 --- a/contracts/dao/voting/lockdrop-vault/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault/src/contract.rs @@ -1,13 +1,15 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, Uint128}; +use cosmwasm_std::{ + to_binary, Binary, Deps, DepsMut, Env, Fraction, MessageInfo, Response, StdError, Uint128, +}; use cw2::set_contract_version; use cwd_interface::voting::{ BondingStatusResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, }; use neutron_lockdrop_vault::voting_power::{get_voting_power_for_address, get_voting_power_total}; -use crate::state::{CONFIG, DAO, OLD_CONFIG}; +use crate::state::{CONFIG, DAO}; use astroport_periphery::lockdrop::PoolType; use neutron_lockdrop_vault::error::{ContractError, ContractResult}; @@ -32,8 +34,8 @@ pub fn instantiate( name: msg.name, description: msg.description, lockdrop_contract: deps.api.addr_validate(&msg.lockdrop_contract)?, - usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, - atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, + oracle_usdc_contract: deps.api.addr_validate(&msg.oracle_usdc_contract)?, + oracle_atom_contract: deps.api.addr_validate(&msg.oracle_atom_contract)?, owner, }; config.validate()?; @@ -46,8 +48,8 @@ pub fn instantiate( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) - .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) - .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) + .add_attribute("oracle_usdc_contract", config.oracle_usdc_contract) + .add_attribute("oracle_atom_contract", config.oracle_atom_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -133,10 +135,10 @@ pub fn execute_update_config( config.lockdrop_contract = lockdrop_contract; } if let Some(oracle_contract) = new_oracle_usdc_contract { - config.usdc_cl_pool_contract = oracle_contract; + config.oracle_usdc_contract = oracle_contract; } if let Some(oracle_contract) = new_oracle_atom_contract { - config.atom_cl_pool_contract = oracle_contract; + config.oracle_atom_contract = oracle_contract; } if let Some(name) = new_name { config.name = name; @@ -153,8 +155,8 @@ pub fn execute_update_config( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) - .add_attribute("oracle_usdc_contract", config.usdc_cl_pool_contract) - .add_attribute("oracle_atom_contract", config.atom_cl_pool_contract)) + .add_attribute("oracle_usdc_contract", config.oracle_usdc_contract) + .add_attribute("oracle_atom_contract", config.oracle_atom_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -193,8 +195,8 @@ pub fn query_voting_power_at_height( let atom_power = get_voting_power_for_address( deps, config.lockdrop_contract.as_ref(), - config.usdc_cl_pool_contract.as_ref(), - config.atom_cl_pool_contract.as_ref(), + config.oracle_usdc_contract.as_ref(), + config.oracle_atom_contract.as_ref(), PoolType::ATOM, address.clone(), height, @@ -202,8 +204,8 @@ pub fn query_voting_power_at_height( let usdc_power = get_voting_power_for_address( deps, config.lockdrop_contract, - config.usdc_cl_pool_contract, - config.atom_cl_pool_contract, + config.oracle_usdc_contract, + config.oracle_atom_contract, PoolType::USDC, address, height, @@ -211,7 +213,10 @@ pub fn query_voting_power_at_height( let power = atom_power + usdc_power; - Ok(VotingPowerAtHeightResponse { power, height }) + Ok(VotingPowerAtHeightResponse { + power: power.numerator().try_into().map_err(StdError::from)?, + height, + }) } pub fn query_total_power_at_height( @@ -226,23 +231,26 @@ pub fn query_total_power_at_height( let atom_power = get_voting_power_total( deps, config.lockdrop_contract.as_ref(), - config.usdc_cl_pool_contract.as_ref(), - config.atom_cl_pool_contract.as_ref(), + config.oracle_usdc_contract.as_ref(), + config.oracle_atom_contract.as_ref(), PoolType::ATOM, height, )?; let usdc_power = get_voting_power_total( deps, config.lockdrop_contract, - config.usdc_cl_pool_contract, - config.atom_cl_pool_contract, + config.oracle_usdc_contract, + config.oracle_atom_contract, PoolType::USDC, height, )?; let power = atom_power + usdc_power; - Ok(TotalPowerAtHeightResponse { power, height }) + Ok(TotalPowerAtHeightResponse { + power: power.numerator().try_into().map_err(StdError::from)?, + height, + }) } pub fn query_info(deps: Deps) -> ContractResult { @@ -288,20 +296,7 @@ pub fn query_bonding_status( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> ContractResult { +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - - let old_config = OLD_CONFIG.load(deps.storage)?; - let new_config = Config { - name: old_config.name, - description: old_config.description, - atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, - usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, - owner: old_config.owner, - lockdrop_contract: old_config.lockdrop_contract, - }; - - CONFIG.save(deps.storage, &new_config)?; - Ok(Response::default()) } diff --git a/contracts/dao/voting/lockdrop-vault/src/state.rs b/contracts/dao/voting/lockdrop-vault/src/state.rs index 9b3a5df7..c3b2cc19 100644 --- a/contracts/dao/voting/lockdrop-vault/src/state.rs +++ b/contracts/dao/voting/lockdrop-vault/src/state.rs @@ -1,7 +1,6 @@ use cosmwasm_std::Addr; use cw_storage_plus::Item; -use neutron_lockdrop_vault::types::{Config, OldConfig}; +use neutron_lockdrop_vault::types::Config; pub const CONFIG: Item = Item::new("config"); -pub const OLD_CONFIG: Item = Item::new("config"); pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/lockdrop-vault/src/tests.rs b/contracts/dao/voting/lockdrop-vault/src/tests.rs index cf41125a..93430499 100644 --- a/contracts/dao/voting/lockdrop-vault/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault/src/tests.rs @@ -1,11 +1,19 @@ use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; -use crate::state::{CONFIG, OLD_CONFIG}; +use astroport::asset::AssetInfo; +use astroport::oracle::QueryMsg as OracleQueryMsg; +use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; use cosmwasm_std::testing::{mock_dependencies, mock_env}; -use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; +use cosmwasm_std::{ + coins, to_binary, Addr, Binary, Coin, Decimal256, Deps, Empty, Env, Response, StdResult, + Uint128, +}; use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; -use cwd_interface::voting::InfoResponse; +use cwd_interface::voting::{ + InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, +}; +use neutron_lockdrop_vault::error::ContractError; use neutron_lockdrop_vault::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use neutron_lockdrop_vault::types::{Config, OldConfig}; +use neutron_lockdrop_vault::types::Config; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -20,8 +28,6 @@ const ORACLE_ATOM_ADDR: &str = "oracle_atom"; const NEW_LOCKDROP_ADDR: &str = "new_lockdrop"; const NEW_ORACLE_USDC_ADDR: &str = "new_oracle_usdc"; const NEW_ORACLE_ATOM_ADDR: &str = "new_oracle_atom"; -const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; -const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -75,6 +81,118 @@ fn mock_app() -> App { #[serde(rename_all = "snake_case")] pub struct EmptyMsg {} +const USER_ATOM_LOCKUP_AT_HEIGHT: u64 = 1_000_000u64; +const USER_USDC_LOCKUP_AT_HEIGHT: u64 = 2_000_000u64; +const TOTAL_ATOM_LOCKUP_AT_HEIGHT: u64 = 3_000_000u64; +const TOTAL_USDC_LOCKUP_AT_HEIGHT: u64 = 4_000_000u64; + +fn lockdrop_query(_deps: Deps, _env: Env, msg: LockdropQueryMsg) -> StdResult { + match msg { + LockdropQueryMsg::QueryUserLockupTotalAtHeight { + pool_type, + user_address: _, + height: _, + } => { + let response = match pool_type { + PoolType::ATOM => Uint128::from(USER_ATOM_LOCKUP_AT_HEIGHT), + PoolType::USDC => Uint128::from(USER_USDC_LOCKUP_AT_HEIGHT), + }; + + to_binary(&response) + } + LockdropQueryMsg::QueryLockupTotalAtHeight { + pool_type, + height: _, + } => { + let response = match pool_type { + PoolType::ATOM => Uint128::from(TOTAL_ATOM_LOCKUP_AT_HEIGHT), + PoolType::USDC => Uint128::from(TOTAL_USDC_LOCKUP_AT_HEIGHT), + }; + + to_binary(&response) + } + _ => unreachable!(), + } +} + +fn lockdrop_contract() -> Box> { + let contract: ContractWrapper< + EmptyMsg, + EmptyMsg, + LockdropQueryMsg, + ContractError, + ContractError, + cosmwasm_std::StdError, + > = ContractWrapper::new( + |_, _, _, _: EmptyMsg| Ok(Response::new()), + |_, _, _, _: EmptyMsg| Ok(Response::new()), + lockdrop_query, + ); + Box::new(contract) +} + +fn instantiate_lockdrop_contract(app: &mut App) -> Addr { + let contract_id = app.store_code(lockdrop_contract()); + app.instantiate_contract( + contract_id, + Addr::unchecked(DAO_ADDR), + &EmptyMsg {}, + &[], + "lockdrop contract", + None, + ) + .unwrap() +} + +const NTRN_TWAP: u64 = 4; + +fn oracle_query(_deps: Deps, _env: Env, msg: OracleQueryMsg) -> StdResult { + match msg { + OracleQueryMsg::TWAPAtHeight { token, height: _ } => { + let twap = match token.clone() { + AssetInfo::NativeToken { denom } => match denom.as_str() { + "untrn" => Decimal256::from_ratio(NTRN_TWAP, 1u64), + _ => Decimal256::from_ratio(1u64, NTRN_TWAP), + }, + AssetInfo::Token { contract_addr: _ } => Decimal256::from_ratio(1u64, NTRN_TWAP), + }; + + let response = vec![(token, twap)]; + to_binary(&response) + } + _ => unreachable!(), + } +} + +fn oracle_contract() -> Box> { + let contract: ContractWrapper< + EmptyMsg, + EmptyMsg, + OracleQueryMsg, + ContractError, + ContractError, + cosmwasm_std::StdError, + > = ContractWrapper::new( + |_, _, _, _: EmptyMsg| Ok(Response::new()), + |_, _, _, _: EmptyMsg| Ok(Response::new()), + oracle_query, + ); + Box::new(contract) +} + +fn instantiate_oracle_contract(app: &mut App) -> Addr { + let contract_id = app.store_code(oracle_contract()); + app.instantiate_contract( + contract_id, + Addr::unchecked(DAO_ADDR), + &EmptyMsg {}, + &[], + "oracle contract", + None, + ) + .unwrap() +} + fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vault", None) .unwrap() @@ -138,6 +256,30 @@ fn update_config( ) } +fn get_voting_power_at_height( + app: &mut App, + contract_addr: Addr, + address: String, + height: Option, +) -> VotingPowerAtHeightResponse { + app.wrap() + .query_wasm_smart( + contract_addr, + &QueryMsg::VotingPowerAtHeight { address, height }, + ) + .unwrap() +} + +fn get_total_power_at_height( + app: &mut App, + contract_addr: Addr, + height: Option, +) -> TotalPowerAtHeightResponse { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::TotalPowerAtHeight { height }) + .unwrap() +} + fn get_config(app: &mut App, contract_addr: Addr) -> Config { app.wrap() .query_wasm_smart(contract_addr, &QueryMsg::Config {}) @@ -162,8 +304,8 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -182,8 +324,8 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -204,8 +346,8 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -225,8 +367,8 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -257,8 +399,8 @@ fn test_update_config_as_owner() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -283,8 +425,8 @@ fn test_update_config_as_owner() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), lockdrop_contract: Addr::unchecked(NEW_LOCKDROP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), - atom_cl_pool_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), + oracle_usdc_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), + oracle_atom_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), }, config ); @@ -303,8 +445,8 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -336,8 +478,8 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -368,8 +510,8 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -390,8 +532,8 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -412,8 +554,8 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + oracle_usdc_contract: ORACLE_USDC_ADDR.to_string(), + oracle_atom_contract: ORACLE_ATOM_ADDR.to_string(), }, ); @@ -425,49 +567,72 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(ORACLE_USDC_ADDR), - atom_cl_pool_contract: Addr::unchecked(ORACLE_ATOM_ADDR), + oracle_usdc_contract: Addr::unchecked(ORACLE_USDC_ADDR), + oracle_atom_contract: Addr::unchecked(ORACLE_ATOM_ADDR), } ) } +#[test] +fn test_voting_power_at_height() { + let mut app = mock_app(); + + let lockdrop_contract = instantiate_lockdrop_contract(&mut app); + let oracle_usdc_contract = instantiate_oracle_contract(&mut app); + let oracle_atom_contract = instantiate_oracle_contract(&mut app); + + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: lockdrop_contract.to_string(), + oracle_usdc_contract: oracle_usdc_contract.to_string(), + oracle_atom_contract: oracle_atom_contract.to_string(), + }, + ); + + let resp = get_voting_power_at_height(&mut app, addr, ADDR1.to_string(), None); + // (USER_ATOM_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + (USER_USDC_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + assert_eq!(resp.power, Uint128::from(500_000u128 + 1_000_000u128)); +} + +#[test] +fn test_total_power_at_height() { + let mut app = mock_app(); + + let lockdrop_contract = instantiate_lockdrop_contract(&mut app); + let oracle_usdc_contract = instantiate_oracle_contract(&mut app); + let oracle_atom_contract = instantiate_oracle_contract(&mut app); + + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + lockdrop_contract: lockdrop_contract.to_string(), + oracle_usdc_contract: oracle_usdc_contract.to_string(), + oracle_atom_contract: oracle_atom_contract.to_string(), + }, + ); + + let resp = get_total_power_at_height(&mut app, addr, None); + // (TOTAL_ATOM_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + (TOTAL_USDC_LOCKUP_AT_HEIGHT / sqrt(NTRN_TWAP)) + assert_eq!(resp.power, Uint128::from(1_500_000u128 + 2_000_000u128)); +} + #[test] pub fn test_migrate_update_version() { let mut deps = mock_dependencies(); cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); - - let old_config = OldConfig { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), - oracle_usdc_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), - oracle_atom_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), - owner: Addr::unchecked(DAO_ADDR.to_string()), - }; - OLD_CONFIG.save(&mut deps.storage, &old_config).unwrap(); - - let new_config = Config { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - owner: Addr::unchecked(DAO_ADDR.to_string()), - atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR.to_string()), - usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR.to_string()), - lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), - }; - - migrate( - deps.as_mut(), - mock_env(), - MigrateMsg { - atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), - usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), - }, - ) - .unwrap(); + migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); let version = cw2::get_contract_version(&deps.storage).unwrap(); - let config = CONFIG.load(&deps.storage).unwrap(); - - assert_eq!(new_config, config); assert_eq!(version.version, CONTRACT_VERSION); assert_eq!(version.contract, CONTRACT_NAME); } diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/.cargo/config b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/.cargo/config new file mode 100644 index 00000000..336b618a --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/Cargo.toml b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/Cargo.toml new file mode 100644 index 00000000..b950ea48 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "vesting-lp-vault-for-cl-pools" +version = "0.1.0" +authors = ["Sergei Sotnikov ", "Murad Karammaev "] +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/neutron/neutron-dao" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-std = { version = "1.3.0" } +cw-storage-plus = "1.1.0" +cw2 = "1.1.0" +schemars = "0.8.8" +serde = { version = "1.0.175", default-features = false, features = ["derive"] } +thiserror = { version = "1.0" } +cwd-macros = { path = "../../../../packages/cwd-macros" } +cwd-interface = { path = "../../../../packages/cwd-interface" } +neutron-vesting-lp-vault-for-cl-pools = { path = "../../../../packages/neutron-vesting-lp-vault-for-cl-pools" } +neutron-voting-power = { path = "../../../../packages/neutron-voting-power" } +vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } +vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } + +[dev-dependencies] +cosmwasm-schema = { version = "1.3.0" } +cw-multi-test = "0.16.5" +anyhow = "1.0.57" +astroport-xastro-token = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } +astroport-pair-concentrated = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } +astroport-original = { package = "astroport", git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } \ No newline at end of file diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/README.md b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/README.md new file mode 100644 index 00000000..b7c0e790 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/README.md @@ -0,0 +1,3 @@ +### Neutron Vesting LP Voting Vault + +This contract is not really a voting vault. It's rather an interface to get voting power from a Vesting LP contract. It's not possible to Bond or Unbond funds to this vault cause these ExecuteMsg handlers are introduced just to make the contract comply with the voting vault interface. diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/examples/schema.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/examples/schema.rs new file mode 100644 index 00000000..2d4c537b --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/examples/schema.rs @@ -0,0 +1,34 @@ +use std::env::current_dir; +use std::fs::create_dir_all; + +use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for}; +use cosmwasm_std::Addr; +use cwd_interface::voting::{ + BondingStatusResponse, InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, +}; +use neutron_vesting_lp_vault_for_cl_pools::{ + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + types::Config, +}; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); + export_schema(&schema_for!(MigrateMsg), &out_dir); + + export_schema(&schema_for!(InfoResponse), &out_dir); + export_schema(&schema_for!(TotalPowerAtHeightResponse), &out_dir); + export_schema(&schema_for!(VotingPowerAtHeightResponse), &out_dir); + export_schema(&schema_for!(BondingStatusResponse), &out_dir); + + // Auto TS code generation expects the query return type as QueryNameResponse + // Here we map query resonses to the correct name + export_schema_with_title(&schema_for!(Addr), &out_dir, "DaoResponse"); + export_schema_with_title(&schema_for!(Config), &out_dir, "GetConfigResponse"); +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/bonding_status_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/bonding_status_response.json new file mode 100644 index 00000000..8fcbb2be --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/bonding_status_response.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "BondingStatusResponse", + "type": "object", + "required": [ + "bonding_enabled", + "height", + "unbondable_abount" + ], + "properties": { + "bonding_enabled": { + "type": "boolean" + }, + "height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "unbondable_abount": { + "$ref": "#/definitions/Uint128" + } + }, + "definitions": { + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/dao_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/dao_response.json new file mode 100644 index 00000000..9518ba3b --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/dao_response.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "DaoResponse", + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/execute_msg.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/execute_msg.json new file mode 100644 index 00000000..ad012325 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/execute_msg.json @@ -0,0 +1,88 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "update_config" + ], + "properties": { + "update_config": { + "type": "object", + "required": [ + "atom_cl_pool_contract", + "atom_vesting_lp_contract", + "description", + "name", + "owner", + "usdc_cl_pool_contract", + "usdc_vesting_lp_contract" + ], + "properties": { + "atom_cl_pool_contract": { + "type": "string" + }, + "atom_vesting_lp_contract": { + "type": "string" + }, + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "usdc_cl_pool_contract": { + "type": "string" + }, + "usdc_vesting_lp_contract": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bond" + ], + "properties": { + "bond": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "unbond" + ], + "properties": { + "unbond": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/get_config_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/get_config_response.json new file mode 100644 index 00000000..9d7c2f88 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/get_config_response.json @@ -0,0 +1,43 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "GetConfigResponse", + "type": "object", + "required": [ + "atom_cl_pool_contract", + "atom_vesting_lp_contract", + "description", + "name", + "owner", + "usdc_cl_pool_contract", + "usdc_vesting_lp_contract" + ], + "properties": { + "atom_cl_pool_contract": { + "$ref": "#/definitions/Addr" + }, + "atom_vesting_lp_contract": { + "$ref": "#/definitions/Addr" + }, + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "owner": { + "$ref": "#/definitions/Addr" + }, + "usdc_cl_pool_contract": { + "$ref": "#/definitions/Addr" + }, + "usdc_vesting_lp_contract": { + "$ref": "#/definitions/Addr" + } + }, + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/info_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/info_response.json new file mode 100644 index 00000000..1419f2c2 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/info_response.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InfoResponse", + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "$ref": "#/definitions/ContractVersion" + } + }, + "definitions": { + "ContractVersion": { + "type": "object", + "required": [ + "contract", + "version" + ], + "properties": { + "contract": { + "description": "contract is the crate name of the implementing contract, eg. `crate:cw20-base` we will use other prefixes for other languages, and their standard global namespacing", + "type": "string" + }, + "version": { + "description": "version is any string that this implementation knows. It may be simple counter \"1\", \"2\". or semantic version on release tags \"v0.7.0\", or some custom feature flag list. the only code that needs to understand the version parsing is code that knows how to migrate from the given contract (and is tied to it's implementation somehow)", + "type": "string" + } + }, + "additionalProperties": false + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/instantiate_msg.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/instantiate_msg.json new file mode 100644 index 00000000..ea001c18 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/instantiate_msg.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object", + "required": [ + "atom_cl_pool_contract", + "atom_vesting_lp_contract", + "description", + "name", + "owner", + "usdc_cl_pool_contract", + "usdc_vesting_lp_contract" + ], + "properties": { + "atom_cl_pool_contract": { + "description": "The ATOM/NTRN CL pool contract.", + "type": "string" + }, + "atom_vesting_lp_contract": { + "description": "The ATOM Vesting LP contract behind the vault.", + "type": "string" + }, + "description": { + "description": "Description contains information that characterizes the vault.", + "type": "string" + }, + "name": { + "description": "Name contains the vault name which is used to ease the vault's recognition.", + "type": "string" + }, + "owner": { + "description": "Owner can update all configs including changing the owner. This will generally be a DAO.", + "type": "string" + }, + "usdc_cl_pool_contract": { + "description": "The USDC/NTRN CL pool oracle contract.", + "type": "string" + }, + "usdc_vesting_lp_contract": { + "description": "The USDC Vesting LP contract behind the vault.", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/migrate_msg.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/migrate_msg.json new file mode 100644 index 00000000..87b18ea7 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/migrate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "MigrateMsg", + "type": "object" +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json new file mode 100644 index 00000000..a7567a73 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json @@ -0,0 +1,172 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "voting_power_at_height" + ], + "properties": { + "voting_power_at_height": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + }, + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "total_power_at_height" + ], + "properties": { + "total_power_at_height": { + "type": "object", + "properties": { + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "bonding_status" + ], + "properties": { + "bonding_status": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + }, + "height": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "dao" + ], + "properties": { + "dao": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "object" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "list_bonders" + ], + "properties": { + "list_bonders": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "string", + "null" + ] + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "info" + ], + "properties": { + "info": { + "type": "object" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/total_power_at_height_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/total_power_at_height_response.json new file mode 100644 index 00000000..8018462b --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/total_power_at_height_response.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "TotalPowerAtHeightResponse", + "type": "object", + "required": [ + "height", + "power" + ], + "properties": { + "height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "power": { + "$ref": "#/definitions/Uint128" + } + }, + "definitions": { + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/voting_power_at_height_response.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/voting_power_at_height_response.json new file mode 100644 index 00000000..15e986bf --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/voting_power_at_height_response.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "VotingPowerAtHeightResponse", + "type": "object", + "required": [ + "height", + "power" + ], + "properties": { + "height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "power": { + "$ref": "#/definitions/Uint128" + } + }, + "definitions": { + "Uint128": { + "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/contract.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/contract.rs new file mode 100644 index 00000000..898677b8 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/contract.rs @@ -0,0 +1,302 @@ +use astroport::asset::AssetInfo; +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{ + to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, Uint128, +}; +use cw2::set_contract_version; +use cwd_interface::voting::{ + BondingStatusResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, +}; +use serde::Serialize; + +use crate::state::{CONFIG, DAO}; +use neutron_vesting_lp_vault_for_cl_pools::{ + error::{ContractError, ContractResult}, + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + types::Config, +}; +use neutron_voting_power::voting_power::voting_power_from_lp_tokens; +use vesting_base::msg::{QueryMsg as VestingLpQueryMsg, QueryMsgHistorical}; +use vesting_base::types::Config as VestingBaseConfig; + +pub(crate) const CONTRACT_NAME: &str = + "crates.io:neutron-vesting-lp-vault-for-cl-pools-for-cl-pools"; +pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: InstantiateMsg, +) -> ContractResult { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let owner = deps.api.addr_validate(&msg.owner)?; + + let config = Config { + name: msg.name, + description: msg.description, + atom_vesting_lp_contract: deps.api.addr_validate(&msg.atom_vesting_lp_contract)?, + atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, + usdc_vesting_lp_contract: deps.api.addr_validate(&msg.usdc_vesting_lp_contract)?, + usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, + owner, + }; + config.validate()?; + CONFIG.save(deps.storage, &config)?; + DAO.save(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_attribute("action", "instantiate") + .add_attribute("name", config.name) + .add_attribute("description", config.description) + .add_attribute("owner", config.owner) + .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) + .add_attribute("atom_cl_pool_contract", config.atom_cl_pool_contract) + .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) + .add_attribute("usdc_cl_pool_contract", config.usdc_cl_pool_contract)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> ContractResult { + match msg { + ExecuteMsg::Bond {} => execute_bond(deps, env, info), + ExecuteMsg::Unbond { amount } => execute_unbond(deps, env, info, amount), + ExecuteMsg::UpdateConfig { + owner, + atom_vesting_lp_contract, + atom_cl_pool_contract: atom_oracle_contract, + usdc_vesting_lp_contract, + usdc_cl_pool_contract: usdc_oracle_contract, + name, + description, + } => execute_update_config( + deps, + info, + owner, + atom_vesting_lp_contract, + atom_oracle_contract, + usdc_vesting_lp_contract, + usdc_oracle_contract, + name, + description, + ), + } +} + +pub fn execute_bond(_deps: DepsMut, _env: Env, _info: MessageInfo) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +pub fn execute_unbond( + _deps: DepsMut, + _env: Env, + _info: MessageInfo, + _amount: Uint128, +) -> ContractResult { + Err(ContractError::DirectUnbondingDisabled {}) +} + +#[allow(clippy::too_many_arguments)] +pub fn execute_update_config( + deps: DepsMut, + info: MessageInfo, + new_owner: String, + new_atom_vesting_lp_contract: String, + new_atom_oracle_contract: String, + new_usdc_vesting_lp_contract: String, + new_usdc_oracle_contract: String, + new_name: String, + new_description: String, +) -> ContractResult { + let mut config: Config = CONFIG.load(deps.storage)?; + if info.sender != config.owner { + return Err(ContractError::Unauthorized {}); + } + + let new_owner = deps.api.addr_validate(&new_owner)?; + let new_atom_vesting_lp_contract = deps.api.addr_validate(&new_atom_vesting_lp_contract)?; + let new_atom_oracle_contract = deps.api.addr_validate(&new_atom_oracle_contract)?; + let new_usdc_vesting_lp_contract = deps.api.addr_validate(&new_usdc_vesting_lp_contract)?; + let new_usdc_oracle_contract = deps.api.addr_validate(&new_usdc_oracle_contract)?; + + config.owner = new_owner; + config.atom_vesting_lp_contract = new_atom_vesting_lp_contract; + config.atom_cl_pool_contract = new_atom_oracle_contract; + config.usdc_vesting_lp_contract = new_usdc_vesting_lp_contract; + config.usdc_cl_pool_contract = new_usdc_oracle_contract; + config.name = new_name; + config.description = new_description; + config.validate()?; + CONFIG.save(deps.storage, &config)?; + + Ok(Response::new() + .add_attribute("action", "update_config") + .add_attribute("description", config.description) + .add_attribute("owner", config.owner) + .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) + .add_attribute("atom_oracle_contract", config.atom_cl_pool_contract) + .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) + .add_attribute("usdc_oracle_contract", config.usdc_cl_pool_contract)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> ContractResult { + match msg { + QueryMsg::VotingPowerAtHeight { address, height } => Ok(to_binary( + &query_voting_power_at_height(deps, env, address, height)?, + )?), + QueryMsg::TotalPowerAtHeight { height } => { + Ok(to_binary(&query_total_power_at_height(deps, env, height)?)?) + } + QueryMsg::Info {} => query_info(deps), + QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Name {} => query_name(deps), + QueryMsg::Description {} => query_description(deps), + QueryMsg::Config {} => query_config(deps), + QueryMsg::ListBonders { start_after, limit } => { + query_list_bonders(deps, start_after, limit) + } + QueryMsg::BondingStatus { height, address } => Ok(to_binary(&query_bonding_status( + deps, env, height, address, + )?)?), + } +} + +fn get_voting_power( + deps: Deps, + config: &Config, + height: u64, + query_msg: &impl Serialize, +) -> ContractResult { + let mut voting_power = Uint128::zero(); + for (vesting_lp, cl_pool) in [ + ( + &config.atom_vesting_lp_contract, + &config.atom_cl_pool_contract, + ), + ( + &config.usdc_vesting_lp_contract, + &config.usdc_cl_pool_contract, + ), + ] { + let vesting_base_config: VestingBaseConfig = deps + .querier + .query_wasm_smart(vesting_lp, &VestingLpQueryMsg::Config {})?; + let lp_token_address: AssetInfo = if vesting_base_config.vesting_token.is_some() { + vesting_base_config.vesting_token.unwrap() + } else { + return Err(ContractError::Std(StdError::generic_err(format!( + "vesting token is not set in {:?} contract", + vesting_lp + )))); + }; + + let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( + lp_token_address.to_string(), + &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, + )?; + + voting_power = voting_power.checked_add(voting_power_from_lp_tokens( + deps, + deps.querier + .query_wasm_smart::>(vesting_lp, &query_msg)? + .unwrap_or_default(), + lp_total_supply, + cl_pool, + height, + )?)?; + } + Ok(voting_power) +} + +pub fn query_voting_power_at_height( + deps: Deps, + env: Env, + address: String, + height: Option, +) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + let height = height.unwrap_or(env.block.height); + let query_msg = VestingLpQueryMsg::HistoricalExtension { + msg: QueryMsgHistorical::UnclaimedAmountAtHeight { address, height }, + }; + + Ok(VotingPowerAtHeightResponse { + power: get_voting_power(deps, &config, height, &query_msg)?, + height, + }) +} + +pub fn query_total_power_at_height( + deps: Deps, + env: Env, + height: Option, +) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + let height = height.unwrap_or(env.block.height); + let query_msg = VestingLpQueryMsg::HistoricalExtension { + msg: QueryMsgHistorical::UnclaimedTotalAmountAtHeight { height }, + }; + + Ok(TotalPowerAtHeightResponse { + power: get_voting_power(deps, &config, height, &query_msg)?, + height, + }) +} + +pub fn query_info(deps: Deps) -> ContractResult { + let info = cw2::get_contract_version(deps.storage)?; + Ok(to_binary(&cwd_interface::voting::InfoResponse { info })?) +} + +pub fn query_dao(deps: Deps) -> ContractResult { + let dao = DAO.load(deps.storage)?; + Ok(to_binary(&dao)?) +} + +pub fn query_name(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config.name)?) +} + +pub fn query_description(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config.description)?) +} + +pub fn query_config(deps: Deps) -> ContractResult { + let config = CONFIG.load(deps.storage)?; + Ok(to_binary(&config)?) +} + +pub fn query_list_bonders( + _deps: Deps, + _start_after: Option, + _limit: Option, +) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +pub fn query_bonding_status( + _deps: Deps, + _env: Env, + _height: Option, + _address: String, +) -> ContractResult { + Err(ContractError::BondingDisabled {}) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _: MigrateMsg) -> ContractResult { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + Ok(Response::default()) +} diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/lib.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/lib.rs new file mode 100644 index 00000000..da3bbc25 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/lib.rs @@ -0,0 +1,5 @@ +pub mod contract; +pub mod state; + +#[cfg(test)] +mod tests; diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/state.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/state.rs new file mode 100644 index 00000000..bfdb04be --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/state.rs @@ -0,0 +1,6 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; +use neutron_vesting_lp_vault_for_cl_pools::types::Config; + +pub const CONFIG: Item = Item::new("config"); +pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs new file mode 100644 index 00000000..a52a5b83 --- /dev/null +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs @@ -0,0 +1,727 @@ +use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; +use astroport::asset::AssetInfo; +use cosmwasm_std::testing::{mock_dependencies, mock_env}; +use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; +use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; +use cwd_interface::voting::{ + InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, +}; +use neutron_vesting_lp_vault_for_cl_pools::{ + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + types::Config, +}; + +const DAO_ADDR: &str = "dao"; +const NAME: &str = "name"; +const NEW_NAME: &str = "new_name"; +const DESCRIPTION: &str = "description"; +const NEW_DESCRIPTION: &str = "new description"; +const ATOM_VESTING_LP_ADDR: &str = "atom_vesting_lp"; +const USDC_VESTING_LP_ADDR: &str = "usdc_vesting_lp"; +const ATOM_ORACLE_ADDR: &str = "atom_oracle"; +const USDC_ORACLE_ADDR: &str = "usdc_oracle"; +const NEW_ATOM_VESTING_LP_ADDR: &str = "new_atom_vesting_lp"; +const NEW_USDC_VESTING_LP_ADDR: &str = "new_usdc_vesting_lp"; +const NEW_ATOM_ORACLE_ADDR: &str = "new_atom_oracle"; +const NEW_USDC_ORACLE_ADDR: &str = "new_usdc_oracle"; +const ADDR1: &str = "addr1"; +const ADDR2: &str = "addr2"; +const DENOM: &str = "ujuno"; +const INIT_BALANCE: Uint128 = Uint128::new(10000); + +fn vault_contract() -> Box> { + let contract = ContractWrapper::new( + crate::contract::execute, + crate::contract::instantiate, + crate::contract::query, + ); + Box::new(contract) +} + +fn lp_token_contract() -> Box> { + let contract = ContractWrapper::new( + astroport_xastro_token::contract::execute, + astroport_xastro_token::contract::instantiate, + astroport_xastro_token::contract::query, + ); + Box::new(contract) +} + +fn vesting_lp_contract() -> Box> { + let contract = ContractWrapper::new( + vesting_lp::contract::execute, + vesting_lp::contract::instantiate, + vesting_lp::contract::query, + ); + Box::new(contract) +} + +fn mock_app() -> App { + custom_app(|r, _a, s| { + r.bank + .init_balance( + s, + &Addr::unchecked(DAO_ADDR), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + r.bank + .init_balance( + s, + &Addr::unchecked(ADDR1), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + r.bank + .init_balance( + s, + &Addr::unchecked(ADDR2), + vec![Coin { + denom: DENOM.to_string(), + amount: INIT_BALANCE, + }], + ) + .unwrap(); + }) +} + +fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { + app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vault", None) + .unwrap() +} + +fn instantiate_lp_token( + app: &mut App, + id: u64, + msg: astroport_original::xastro_token::InstantiateMsg, +) -> Addr { + app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "lp-token", None) + .unwrap() +} + +fn instantiate_vesting_lp(app: &mut App, id: u64, msg: vesting_lp::msg::InstantiateMsg) -> Addr { + app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vesting_lp", None) + .unwrap() +} + +fn set_vesting_token( + app: &mut App, + sender: Addr, + vesting_contract: Addr, + vesting_token: AssetInfo, +) { + app.execute_contract( + sender, + vesting_contract, + &vesting_base::msg::ExecuteMsg::SetVestingToken { vesting_token }, + &[], + ) + .unwrap(); +} + +fn bond_tokens( + app: &mut App, + contract_addr: Addr, + sender: &str, + amount: u128, + denom: &str, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::Bond {}, + &coins(amount, denom), + ) +} + +fn unbond_tokens( + app: &mut App, + contract_addr: Addr, + sender: &str, + amount: u128, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::Unbond { + amount: Uint128::new(amount), + }, + &[], + ) +} + +#[allow(clippy::too_many_arguments)] +fn update_config( + app: &mut App, + contract_addr: Addr, + sender: &str, + owner: String, + atom_vesting_lp_contract: String, + atom_oracle_contract: String, + usdc_vesting_lp_contract: String, + usdc_oracle_contract: String, + name: String, + description: String, +) -> anyhow::Result { + app.execute_contract( + Addr::unchecked(sender), + contract_addr, + &ExecuteMsg::UpdateConfig { + owner, + atom_vesting_lp_contract, + atom_cl_pool_contract: atom_oracle_contract, + usdc_vesting_lp_contract, + usdc_cl_pool_contract: usdc_oracle_contract, + name, + description, + }, + &[], + ) +} + +fn get_voting_power_at_height( + app: &mut App, + contract_addr: Addr, + address: String, + height: Option, +) -> VotingPowerAtHeightResponse { + app.wrap() + .query_wasm_smart( + contract_addr, + &QueryMsg::VotingPowerAtHeight { address, height }, + ) + .unwrap() +} + +fn get_total_power_at_height( + app: &mut App, + contract_addr: Addr, + height: Option, +) -> TotalPowerAtHeightResponse { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::TotalPowerAtHeight { height }) + .unwrap() +} + +fn get_config(app: &mut App, contract_addr: Addr) -> Config { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::Config {}) + .unwrap() +} + +fn get_dao(app: &App, contract_addr: &Addr) -> String { + app.wrap() + .query_wasm_smart(contract_addr, &QueryMsg::Dao {}) + .unwrap() +} + +#[test] +fn test_instantiate() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + // Populated fields + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); + + // Non populated fields + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); +} + +#[test] +#[should_panic(expected = "Bonding is not available for this contract")] +fn test_bond() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // Try and bond an invalid denom + bond_tokens(&mut app, addr, ADDR1, 100, DENOM).unwrap(); +} + +#[test] +#[should_panic(expected = "Direct unbonding is not available for this contract")] +fn test_unbond() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + unbond_tokens(&mut app, addr, ADDR1, 100).unwrap(); +} + +#[test] +#[should_panic(expected = "Unauthorized")] +fn test_update_config_unauthorized() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // From ADDR2, so not owner + update_config( + &mut app, + addr, + ADDR2, + ADDR1.to_string(), + NEW_ATOM_VESTING_LP_ADDR.to_string(), + NEW_ATOM_ORACLE_ADDR.to_string(), + NEW_USDC_VESTING_LP_ADDR.to_string(), + NEW_USDC_ORACLE_ADDR.to_string(), + NEW_NAME.to_string(), + NEW_DESCRIPTION.to_string(), + ) + .unwrap(); +} + +#[test] +fn test_update_config() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // Change owner, description, name, lp-vesting and oracle contracts + update_config( + &mut app, + addr.clone(), + DAO_ADDR, + ADDR1.to_string(), + NEW_ATOM_VESTING_LP_ADDR.to_string(), + NEW_ATOM_ORACLE_ADDR.to_string(), + NEW_USDC_VESTING_LP_ADDR.to_string(), + NEW_USDC_ORACLE_ADDR.to_string(), + NEW_NAME.to_string(), + NEW_DESCRIPTION.to_string(), + ) + .unwrap(); + + let config = get_config(&mut app, addr); + assert_eq!( + Config { + name: NEW_NAME.to_string(), + description: NEW_DESCRIPTION.to_string(), + owner: Addr::unchecked(ADDR1), + atom_vesting_lp_contract: Addr::unchecked(NEW_ATOM_VESTING_LP_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), + usdc_vesting_lp_contract: Addr::unchecked(NEW_USDC_VESTING_LP_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), + }, + config + ); +} + +#[test] +#[should_panic(expected = "config description cannot be empty.")] +fn test_update_config_invalid_description() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // Change name + update_config( + &mut app, + addr, + DAO_ADDR, + DAO_ADDR.to_string(), + ATOM_VESTING_LP_ADDR.to_string(), + ATOM_ORACLE_ADDR.to_string(), + USDC_VESTING_LP_ADDR.to_string(), + USDC_ORACLE_ADDR.to_string(), + NEW_NAME.to_string(), + String::from(""), + ) + .unwrap(); +} + +#[test] +#[should_panic(expected = "config name cannot be empty.")] +fn test_update_config_invalid_name() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // Change description + update_config( + &mut app, + addr, + DAO_ADDR, + DAO_ADDR.to_string(), + ATOM_VESTING_LP_ADDR.to_string(), + ATOM_ORACLE_ADDR.to_string(), + USDC_VESTING_LP_ADDR.to_string(), + USDC_ORACLE_ADDR.to_string(), + String::from(""), + NEW_DESCRIPTION.to_string(), + ) + .unwrap(); +} + +#[test] +fn test_query_dao() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + let msg = QueryMsg::Dao {}; + let dao: Addr = app.wrap().query_wasm_smart(addr, &msg).unwrap(); + assert_eq!(dao, Addr::unchecked(DAO_ADDR)); +} + +#[test] +fn test_query_info() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + let msg = QueryMsg::Info {}; + let resp: InfoResponse = app.wrap().query_wasm_smart(addr, &msg).unwrap(); + assert_eq!( + resp.info.contract, + "crates.io:neutron-vesting-lp-vault-for-cl-pools-for-cl-pools" + ); +} + +#[test] +fn test_query_get_config() { + let mut app = mock_app(); + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + let config = get_config(&mut app, addr); + assert_eq!( + config, + Config { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: Addr::unchecked(DAO_ADDR), + atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR), + atom_cl_pool_contract: Addr::unchecked(ATOM_ORACLE_ADDR), + usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR), + usdc_cl_pool_contract: Addr::unchecked(USDC_ORACLE_ADDR), + } + ) +} + +#[test] +fn test_voting_power_at_height() { + let mut app = mock_app(); + + let vesting_lp_id = app.store_code(vesting_lp_contract()); + let lp_token_id = app.store_code(lp_token_contract()); + + let atom_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "atom".to_string(), + symbol: "atom-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let usdc_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "usdc".to_string(), + symbol: "usdc-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + + let atom_vesting_lp_addr = instantiate_vesting_lp( + &mut app, + vesting_lp_id, + vesting_lp::msg::InstantiateMsg { + owner: DAO_ADDR.to_string(), + vesting_managers: vec![], + token_info_manager: "manager".to_string(), + }, + ); + let usdc_vesting_lp_addr = instantiate_vesting_lp( + &mut app, + vesting_lp_id, + vesting_lp::msg::InstantiateMsg { + owner: DAO_ADDR.to_string(), + vesting_managers: vec![], + token_info_manager: "manager".to_string(), + }, + ); + + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + usdc_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: usdc_lp_token_address, + }, + ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + atom_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: atom_lp_token_address, + }, + ); + + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // describe test when lockdrop contract is implemented. use neutron vault tests as template. + let resp = get_voting_power_at_height(&mut app, addr, ADDR1.to_string(), None); + assert!(resp.power.is_zero()); +} + +#[test] +fn test_total_power_at_height() { + let mut app = mock_app(); + + let vesting_lp_id = app.store_code(vesting_lp_contract()); + let lp_token_id = app.store_code(lp_token_contract()); + + let atom_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "atom".to_string(), + symbol: "atom-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + let usdc_lp_token_address = instantiate_lp_token( + &mut app, + lp_token_id, + astroport_original::xastro_token::InstantiateMsg { + name: "usdc".to_string(), + symbol: "usdc-lp".to_string(), + decimals: 6, + initial_balances: vec![], + mint: None, + marketing: None, + }, + ); + + let atom_vesting_lp_addr = instantiate_vesting_lp( + &mut app, + vesting_lp_id, + vesting_lp::msg::InstantiateMsg { + owner: DAO_ADDR.to_string(), + vesting_managers: vec![], + token_info_manager: "manager".to_string(), + }, + ); + let usdc_vesting_lp_addr = instantiate_vesting_lp( + &mut app, + vesting_lp_id, + vesting_lp::msg::InstantiateMsg { + owner: DAO_ADDR.to_string(), + vesting_managers: vec![], + token_info_manager: "manager".to_string(), + }, + ); + + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + usdc_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: usdc_lp_token_address, + }, + ); + set_vesting_token( + &mut app, + Addr::unchecked("manager".to_string()), + atom_vesting_lp_addr.clone(), + AssetInfo::Token { + contract_addr: atom_lp_token_address, + }, + ); + + let vault_id = app.store_code(vault_contract()); + let addr = instantiate_vault( + &mut app, + vault_id, + InstantiateMsg { + name: NAME.to_string(), + description: DESCRIPTION.to_string(), + owner: DAO_ADDR.to_string(), + atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), + atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), + usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + }, + ); + + // describe test when lockdrop contract is implemented. use neutron vault tests as template. + let resp = get_total_power_at_height(&mut app, addr, None); + assert!(resp.power.is_zero()); +} + +#[test] +pub fn test_migrate_update_version() { + let mut deps = mock_dependencies(); + cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); + + migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); + let version = cw2::get_contract_version(&deps.storage).unwrap(); + + assert_eq!(version.version, CONTRACT_VERSION); + assert_eq!(version.contract, CONTRACT_NAME); +} diff --git a/contracts/dao/voting/vesting-lp-vault/Cargo.toml b/contracts/dao/voting/vesting-lp-vault/Cargo.toml index 61fa5adb..1f880246 100644 --- a/contracts/dao/voting/vesting-lp-vault/Cargo.toml +++ b/contracts/dao/voting/vesting-lp-vault/Cargo.toml @@ -25,15 +25,11 @@ thiserror = { version = "1.0" } cwd-macros = { path = "../../../../packages/cwd-macros" } cwd-interface = { path = "../../../../packages/cwd-interface" } neutron-vesting-lp-vault = { path = "../../../../packages/neutron-vesting-lp-vault" } -neutron-oracle = { path = "../../../../packages/neutron-voting-power" } -vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } -vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", rev = "e306308dd23d567399c15d899f295a910ede945b" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +neutron-oracle = { path = "../../../../packages/neutron-oracle" } +vesting-base = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } +vesting-lp = { git = "https://github.com/neutron-org/neutron-tge-contracts", branch = "main" } [dev-dependencies] cosmwasm-schema = { version = "1.3.0" } cw-multi-test = "0.16.5" anyhow = "1.0.57" -astroport-xastro-token = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } -astroport-pair-concentrated = { git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } -astroport-original = { package = "astroport", git = "https://github.com/astroport-fi/astroport-core.git", tag = "v2.8.0" } \ No newline at end of file diff --git a/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json index ad012325..5920d68b 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/execute_msg.json @@ -11,16 +11,16 @@ "update_config": { "type": "object", "required": [ - "atom_cl_pool_contract", + "atom_oracle_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_cl_pool_contract", + "usdc_oracle_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_cl_pool_contract": { + "atom_oracle_contract": { "type": "string" }, "atom_vesting_lp_contract": { @@ -35,7 +35,7 @@ "owner": { "type": "string" }, - "usdc_cl_pool_contract": { + "usdc_oracle_contract": { "type": "string" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json b/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json index 9d7c2f88..adda59d3 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/get_config_response.json @@ -3,16 +3,16 @@ "title": "GetConfigResponse", "type": "object", "required": [ - "atom_cl_pool_contract", + "atom_oracle_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_cl_pool_contract", + "usdc_oracle_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_cl_pool_contract": { + "atom_oracle_contract": { "$ref": "#/definitions/Addr" }, "atom_vesting_lp_contract": { @@ -27,7 +27,7 @@ "owner": { "$ref": "#/definitions/Addr" }, - "usdc_cl_pool_contract": { + "usdc_oracle_contract": { "$ref": "#/definitions/Addr" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json index ea001c18..9dbb4e25 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/instantiate_msg.json @@ -3,17 +3,17 @@ "title": "InstantiateMsg", "type": "object", "required": [ - "atom_cl_pool_contract", + "atom_oracle_contract", "atom_vesting_lp_contract", "description", "name", "owner", - "usdc_cl_pool_contract", + "usdc_oracle_contract", "usdc_vesting_lp_contract" ], "properties": { - "atom_cl_pool_contract": { - "description": "The ATOM/NTRN CL pool contract.", + "atom_oracle_contract": { + "description": "The ATOM oracle contract behind the vault.", "type": "string" }, "atom_vesting_lp_contract": { @@ -32,8 +32,8 @@ "description": "Owner can update all configs including changing the owner. This will generally be a DAO.", "type": "string" }, - "usdc_cl_pool_contract": { - "description": "The USDC/NTRN CL pool oracle contract.", + "usdc_oracle_contract": { + "description": "The USDC oracle contract behind the vault.", "type": "string" }, "usdc_vesting_lp_contract": { diff --git a/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json b/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json index 688bcc83..87b18ea7 100644 --- a/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json +++ b/contracts/dao/voting/vesting-lp-vault/schema/migrate_msg.json @@ -1,17 +1,5 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "MigrateMsg", - "type": "object", - "required": [ - "atom_cl_pool", - "usdc_cl_pool" - ], - "properties": { - "atom_cl_pool": { - "type": "string" - }, - "usdc_cl_pool": { - "type": "string" - } - } + "type": "object" } diff --git a/contracts/dao/voting/vesting-lp-vault/src/contract.rs b/contracts/dao/voting/vesting-lp-vault/src/contract.rs index 741fb5f8..a3d7eb22 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/contract.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/contract.rs @@ -1,8 +1,8 @@ -use astroport::asset::AssetInfo; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, Uint128, + to_binary, Binary, Decimal256, Deps, DepsMut, Env, Fraction, MessageInfo, Response, StdError, + Uint128, }; use cw2::set_contract_version; use cwd_interface::voting::{ @@ -10,7 +10,7 @@ use cwd_interface::voting::{ }; use serde::Serialize; -use crate::state::{CONFIG, DAO, OLD_CONFIG}; +use crate::state::{CONFIG, DAO}; use neutron_oracle::voting_power::voting_power_from_lp_tokens; use neutron_vesting_lp_vault::{ error::{ContractError, ContractResult}, @@ -18,7 +18,6 @@ use neutron_vesting_lp_vault::{ types::Config, }; use vesting_base::msg::{QueryMsg as VestingLpQueryMsg, QueryMsgHistorical}; -use vesting_base::types::Config as VestingBaseConfig; pub(crate) const CONTRACT_NAME: &str = "crates.io:neutron-vesting-lp-vault"; pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -38,9 +37,9 @@ pub fn instantiate( name: msg.name, description: msg.description, atom_vesting_lp_contract: deps.api.addr_validate(&msg.atom_vesting_lp_contract)?, - atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool_contract)?, + atom_oracle_contract: deps.api.addr_validate(&msg.atom_oracle_contract)?, usdc_vesting_lp_contract: deps.api.addr_validate(&msg.usdc_vesting_lp_contract)?, - usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool_contract)?, + usdc_oracle_contract: deps.api.addr_validate(&msg.usdc_oracle_contract)?, owner, }; config.validate()?; @@ -53,9 +52,9 @@ pub fn instantiate( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) - .add_attribute("atom_cl_pool_contract", config.atom_cl_pool_contract) + .add_attribute("atom_oracle_contract", config.atom_oracle_contract) .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) - .add_attribute("usdc_cl_pool_contract", config.usdc_cl_pool_contract)) + .add_attribute("usdc_oracle_contract", config.usdc_oracle_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -71,9 +70,9 @@ pub fn execute( ExecuteMsg::UpdateConfig { owner, atom_vesting_lp_contract, - atom_cl_pool_contract: atom_oracle_contract, + atom_oracle_contract, usdc_vesting_lp_contract, - usdc_cl_pool_contract: usdc_oracle_contract, + usdc_oracle_contract, name, description, } => execute_update_config( @@ -128,9 +127,9 @@ pub fn execute_update_config( config.owner = new_owner; config.atom_vesting_lp_contract = new_atom_vesting_lp_contract; - config.atom_cl_pool_contract = new_atom_oracle_contract; + config.atom_oracle_contract = new_atom_oracle_contract; config.usdc_vesting_lp_contract = new_usdc_vesting_lp_contract; - config.usdc_cl_pool_contract = new_usdc_oracle_contract; + config.usdc_oracle_contract = new_usdc_oracle_contract; config.name = new_name; config.description = new_description; config.validate()?; @@ -141,9 +140,9 @@ pub fn execute_update_config( .add_attribute("description", config.description) .add_attribute("owner", config.owner) .add_attribute("atom_vesting_lp_contract", config.atom_vesting_lp_contract) - .add_attribute("atom_oracle_contract", config.atom_cl_pool_contract) + .add_attribute("atom_oracle_contract", config.atom_oracle_contract) .add_attribute("usdc_vesting_lp_contract", config.usdc_vesting_lp_contract) - .add_attribute("usdc_oracle_contract", config.usdc_cl_pool_contract)) + .add_attribute("usdc_oracle_contract", config.usdc_oracle_contract)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -174,44 +173,26 @@ fn get_voting_power( config: &Config, height: u64, query_msg: &impl Serialize, -) -> ContractResult { - let mut voting_power = Uint128::zero(); - for (vesting_lp, cl_pool) in [ +) -> ContractResult { + let mut voting_power = Decimal256::zero(); + for (vesting_lp, oracle) in [ ( &config.atom_vesting_lp_contract, - &config.atom_cl_pool_contract, + &config.atom_oracle_contract, ), ( &config.usdc_vesting_lp_contract, - &config.usdc_cl_pool_contract, + &config.usdc_oracle_contract, ), ] { - let vesting_base_config: VestingBaseConfig = deps - .querier - .query_wasm_smart(vesting_lp, &VestingLpQueryMsg::Config {})?; - let lp_token_address: AssetInfo = if vesting_base_config.vesting_token.is_some() { - vesting_base_config.vesting_token.unwrap() - } else { - return Err(ContractError::Std(StdError::generic_err(format!( - "vesting token is not set in {:?} contract", - vesting_lp - )))); - }; - - let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( - lp_token_address.to_string(), - &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, - )?; - - voting_power = voting_power.checked_add(voting_power_from_lp_tokens( + voting_power += voting_power_from_lp_tokens( deps, deps.querier .query_wasm_smart::>(vesting_lp, &query_msg)? .unwrap_or_default(), - lp_total_supply, - cl_pool, + oracle, height, - )?)?; + )?; } Ok(voting_power) } @@ -229,7 +210,10 @@ pub fn query_voting_power_at_height( }; Ok(VotingPowerAtHeightResponse { - power: get_voting_power(deps, &config, height, &query_msg)?, + power: get_voting_power(deps, &config, height, &query_msg)? + .numerator() + .try_into() + .map_err(StdError::from)?, height, }) } @@ -246,7 +230,10 @@ pub fn query_total_power_at_height( }; Ok(TotalPowerAtHeightResponse { - power: get_voting_power(deps, &config, height, &query_msg)?, + power: get_voting_power(deps, &config, height, &query_msg)? + .numerator() + .try_into() + .map_err(StdError::from)?, height, }) } @@ -294,21 +281,7 @@ pub fn query_bonding_status( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> ContractResult { +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - - let old_config = OLD_CONFIG.load(deps.storage)?; - let new_config = Config { - name: old_config.name, - description: old_config.description, - atom_vesting_lp_contract: old_config.atom_vesting_lp_contract, - atom_cl_pool_contract: deps.api.addr_validate(&msg.atom_cl_pool)?, - usdc_vesting_lp_contract: old_config.usdc_vesting_lp_contract, - usdc_cl_pool_contract: deps.api.addr_validate(&msg.usdc_cl_pool)?, - owner: old_config.owner, - }; - - CONFIG.save(deps.storage, &new_config)?; - Ok(Response::default()) } diff --git a/contracts/dao/voting/vesting-lp-vault/src/state.rs b/contracts/dao/voting/vesting-lp-vault/src/state.rs index 6ed3cba3..1638b96d 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/state.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/state.rs @@ -1,7 +1,6 @@ use cosmwasm_std::Addr; use cw_storage_plus::Item; -use neutron_vesting_lp_vault::types::{Config, OldConfig}; +use neutron_vesting_lp_vault::types::Config; -pub const OLD_CONFIG: Item = Item::new("config"); pub const CONFIG: Item = Item::new("config"); pub const DAO: Item = Item::new("dao"); diff --git a/contracts/dao/voting/vesting-lp-vault/src/tests.rs b/contracts/dao/voting/vesting-lp-vault/src/tests.rs index 2a163d10..fc141c09 100644 --- a/contracts/dao/voting/vesting-lp-vault/src/tests.rs +++ b/contracts/dao/voting/vesting-lp-vault/src/tests.rs @@ -1,13 +1,10 @@ use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION}; -use crate::state::{CONFIG, OLD_CONFIG}; -use astroport::asset::AssetInfo; use cosmwasm_std::testing::{mock_dependencies, mock_env}; use cosmwasm_std::{coins, Addr, Coin, Empty, Uint128}; use cw_multi_test::{custom_app, App, AppResponse, Contract, ContractWrapper, Executor}; use cwd_interface::voting::{ InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse, }; -use neutron_vesting_lp_vault::types::OldConfig; use neutron_vesting_lp_vault::{ msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, types::Config, @@ -26,8 +23,6 @@ const NEW_ATOM_VESTING_LP_ADDR: &str = "new_atom_vesting_lp"; const NEW_USDC_VESTING_LP_ADDR: &str = "new_usdc_vesting_lp"; const NEW_ATOM_ORACLE_ADDR: &str = "new_atom_oracle"; const NEW_USDC_ORACLE_ADDR: &str = "new_usdc_oracle"; -const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; -const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -42,15 +37,6 @@ fn vault_contract() -> Box> { Box::new(contract) } -fn lp_token_contract() -> Box> { - let contract = ContractWrapper::new( - astroport_xastro_token::contract::execute, - astroport_xastro_token::contract::instantiate, - astroport_xastro_token::contract::query, - ); - Box::new(contract) -} - fn vesting_lp_contract() -> Box> { let contract = ContractWrapper::new( vesting_lp::contract::execute, @@ -100,35 +86,11 @@ fn instantiate_vault(app: &mut App, id: u64, msg: InstantiateMsg) -> Addr { .unwrap() } -fn instantiate_lp_token( - app: &mut App, - id: u64, - msg: astroport_original::xastro_token::InstantiateMsg, -) -> Addr { - app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "lp-token", None) - .unwrap() -} - fn instantiate_vesting_lp(app: &mut App, id: u64, msg: vesting_lp::msg::InstantiateMsg) -> Addr { app.instantiate_contract(id, Addr::unchecked(DAO_ADDR), &msg, &[], "vesting_lp", None) .unwrap() } -fn set_vesting_token( - app: &mut App, - sender: Addr, - vesting_contract: Addr, - vesting_token: AssetInfo, -) { - app.execute_contract( - sender, - vesting_contract, - &vesting_base::msg::ExecuteMsg::SetVestingToken { vesting_token }, - &[], - ) - .unwrap(); -} - fn bond_tokens( app: &mut App, contract_addr: Addr, @@ -179,9 +141,9 @@ fn update_config( &ExecuteMsg::UpdateConfig { owner, atom_vesting_lp_contract, - atom_cl_pool_contract: atom_oracle_contract, + atom_oracle_contract, usdc_vesting_lp_contract, - usdc_cl_pool_contract: usdc_oracle_contract, + usdc_oracle_contract, name, description, }, @@ -238,9 +200,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -254,9 +216,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -275,9 +237,9 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -298,9 +260,9 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -320,9 +282,9 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -354,9 +316,9 @@ fn test_update_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -382,9 +344,9 @@ fn test_update_config() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), atom_vesting_lp_contract: Addr::unchecked(NEW_ATOM_VESTING_LP_ADDR), - atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), + atom_oracle_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), usdc_vesting_lp_contract: Addr::unchecked(NEW_USDC_VESTING_LP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), + usdc_oracle_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), }, config ); @@ -403,9 +365,9 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -438,9 +400,9 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -472,9 +434,9 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -495,9 +457,9 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -518,9 +480,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -532,9 +494,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR), - atom_cl_pool_contract: Addr::unchecked(ATOM_ORACLE_ADDR), + atom_oracle_contract: Addr::unchecked(ATOM_ORACLE_ADDR), usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(USDC_ORACLE_ADDR), + usdc_oracle_contract: Addr::unchecked(USDC_ORACLE_ADDR), } ) } @@ -544,33 +506,6 @@ fn test_voting_power_at_height() { let mut app = mock_app(); let vesting_lp_id = app.store_code(vesting_lp_contract()); - let lp_token_id = app.store_code(lp_token_contract()); - - let atom_lp_token_address = instantiate_lp_token( - &mut app, - lp_token_id, - astroport_original::xastro_token::InstantiateMsg { - name: "atom".to_string(), - symbol: "atom-lp".to_string(), - decimals: 6, - initial_balances: vec![], - mint: None, - marketing: None, - }, - ); - let usdc_lp_token_address = instantiate_lp_token( - &mut app, - lp_token_id, - astroport_original::xastro_token::InstantiateMsg { - name: "usdc".to_string(), - symbol: "usdc-lp".to_string(), - decimals: 6, - initial_balances: vec![], - mint: None, - marketing: None, - }, - ); - let atom_vesting_lp_addr = instantiate_vesting_lp( &mut app, vesting_lp_id, @@ -590,23 +525,6 @@ fn test_voting_power_at_height() { }, ); - set_vesting_token( - &mut app, - Addr::unchecked("manager".to_string()), - usdc_vesting_lp_addr.clone(), - AssetInfo::Token { - contract_addr: usdc_lp_token_address, - }, - ); - set_vesting_token( - &mut app, - Addr::unchecked("manager".to_string()), - atom_vesting_lp_addr.clone(), - AssetInfo::Token { - contract_addr: atom_lp_token_address, - }, - ); - let vault_id = app.store_code(vault_contract()); let addr = instantiate_vault( &mut app, @@ -616,9 +534,9 @@ fn test_voting_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -632,33 +550,6 @@ fn test_total_power_at_height() { let mut app = mock_app(); let vesting_lp_id = app.store_code(vesting_lp_contract()); - let lp_token_id = app.store_code(lp_token_contract()); - - let atom_lp_token_address = instantiate_lp_token( - &mut app, - lp_token_id, - astroport_original::xastro_token::InstantiateMsg { - name: "atom".to_string(), - symbol: "atom-lp".to_string(), - decimals: 6, - initial_balances: vec![], - mint: None, - marketing: None, - }, - ); - let usdc_lp_token_address = instantiate_lp_token( - &mut app, - lp_token_id, - astroport_original::xastro_token::InstantiateMsg { - name: "usdc".to_string(), - symbol: "usdc-lp".to_string(), - decimals: 6, - initial_balances: vec![], - mint: None, - marketing: None, - }, - ); - let atom_vesting_lp_addr = instantiate_vesting_lp( &mut app, vesting_lp_id, @@ -678,23 +569,6 @@ fn test_total_power_at_height() { }, ); - set_vesting_token( - &mut app, - Addr::unchecked("manager".to_string()), - usdc_vesting_lp_addr.clone(), - AssetInfo::Token { - contract_addr: usdc_lp_token_address, - }, - ); - set_vesting_token( - &mut app, - Addr::unchecked("manager".to_string()), - atom_vesting_lp_addr.clone(), - AssetInfo::Token { - contract_addr: atom_lp_token_address, - }, - ); - let vault_id = app.store_code(vault_contract()); let addr = instantiate_vault( &mut app, @@ -704,9 +578,9 @@ fn test_total_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_oracle_contract: ATOM_ORACLE_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_oracle_contract: USDC_ORACLE_ADDR.to_string(), }, ); @@ -719,40 +593,8 @@ fn test_total_power_at_height() { pub fn test_migrate_update_version() { let mut deps = mock_dependencies(); cw2::set_contract_version(&mut deps.storage, "my-contract", "old-version").unwrap(); - - let old_config = OldConfig { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - owner: Addr::unchecked(DAO_ADDR.to_string()), - atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR.to_string()), - atom_oracle_contract: Addr::unchecked(ATOM_ORACLE_ADDR.to_string()), - usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR.to_string()), - usdc_oracle_contract: Addr::unchecked(USDC_ORACLE_ADDR.to_string()), - }; - OLD_CONFIG.save(&mut deps.storage, &old_config).unwrap(); - - let new_config = Config { - name: NAME.to_string(), - description: DESCRIPTION.to_string(), - owner: Addr::unchecked(DAO_ADDR.to_string()), - atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR.to_string()), - atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR.to_string()), - usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR.to_string()), - usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR.to_string()), - }; - - migrate( - deps.as_mut(), - mock_env(), - MigrateMsg { - atom_cl_pool: ATOM_CL_POOL_ADDR.to_string(), - usdc_cl_pool: USDC_CL_POOL_ADDR.to_string(), - }, - ) - .unwrap(); + migrate(deps.as_mut(), mock_env(), MigrateMsg {}).unwrap(); let version = cw2::get_contract_version(&deps.storage).unwrap(); - let config = CONFIG.load(&deps.storage).unwrap(); assert_eq!(version.version, CONTRACT_VERSION); assert_eq!(version.contract, CONTRACT_NAME); - assert_eq!(config, new_config); } diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/Cargo.toml b/packages/neutron-lockdrop-vault-for-cl-pools/Cargo.toml new file mode 100644 index 00000000..9dfa8b26 --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "neutron-lockdrop-vault-for-cl-pools" +version = "0.1.0" +authors = ["Sergei Sotnikov "] +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/neutron/neutron-dao" + +[dependencies] +cosmwasm-std = { version = "1.3.0" } +cwd-macros = { path = "../cwd-macros" } +schemars = "0.8.8" +serde = { version = "1.0.175", default-features = false, features = ["derive"] } +thiserror = { version = "1.0" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +neutron-voting-power = { path = "../neutron-voting-power" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/error.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/error.rs new file mode 100644 index 00000000..2f42b205 --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/error.rs @@ -0,0 +1,25 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, + + #[error("Bonding is not available for this contract")] + BondingDisabled {}, + + #[error("Direct unbonding is not available for this contract")] + DirectUnbondingDisabled {}, + + #[error("config name cannot be empty.")] + NameIsEmpty {}, + + #[error("config description cannot be empty.")] + DescriptionIsEmpty {}, +} + +pub type ContractResult = Result; diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/lib.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/lib.rs new file mode 100644 index 00000000..428eca92 --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/lib.rs @@ -0,0 +1,4 @@ +pub mod error; +pub mod msg; +pub mod types; +pub mod voting_power; diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs new file mode 100644 index 00000000..afbfcfaf --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs @@ -0,0 +1,45 @@ +use cwd_macros::{info_query, voting_query, voting_vault, voting_vault_query}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +pub struct InstantiateMsg { + /// Name contains the vault name which is used to ease the vault's recognition. + pub name: String, + /// Description contains information that characterizes the vault. + pub description: String, + /// The lockdrop contract behind the vault. + pub lockdrop_contract: String, + /// The USDC/NTRN CL pool contract. + pub usdc_cl_pool_contract: String, + /// The ATOM/NTRN CL pool oracle contract. + pub atom_cl_pool_contract: String, + /// Owner can update all configs including changing the owner. This will generally be a DAO. + pub owner: String, +} + +#[voting_vault] +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[serde(rename_all = "snake_case")] +pub enum ExecuteMsg { + UpdateConfig { + owner: Option, + lockdrop_contract: Option, + oracle_usdc_contract: Option, + oracle_atom_contract: Option, + name: Option, + description: Option, + }, +} + +#[voting_query] +#[voting_vault_query] +#[info_query] +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + Config {}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct MigrateMsg {} diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/types.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/types.rs new file mode 100644 index 00000000..e6c48440 --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/types.rs @@ -0,0 +1,73 @@ +use crate::error::ContractError; +use cosmwasm_std::Addr; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] +pub struct Config { + pub name: String, + pub description: String, + pub lockdrop_contract: Addr, + pub usdc_cl_pool_contract: Addr, + pub atom_cl_pool_contract: Addr, + pub owner: Addr, +} + +impl Config { + /// checks whether the config fields are valid. + pub fn validate(&self) -> Result<(), ContractError> { + if self.name.is_empty() { + return Err(ContractError::NameIsEmpty {}); + }; + if self.description.is_empty() { + return Err(ContractError::DescriptionIsEmpty {}); + }; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::Config; + use crate::error::ContractError; + use cosmwasm_std::Addr; + + #[test] + fn test_config_validate() { + let cfg_ok = Config { + name: String::from("name"), + description: String::from("description"), + lockdrop_contract: Addr::unchecked("lockdrop_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + owner: Addr::unchecked("owner"), + }; + assert_eq!(cfg_ok.validate(), Ok(())); + + let cfg_empty_name = Config { + name: String::from(""), + description: String::from("description"), + lockdrop_contract: Addr::unchecked("lockdrop_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + owner: Addr::unchecked("owner"), + }; + assert_eq!( + cfg_empty_name.validate(), + Err(ContractError::NameIsEmpty {}) + ); + + let cfg_empty_description = Config { + name: String::from("name"), + description: String::from(""), + lockdrop_contract: Addr::unchecked("lockdrop_contract"), + usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), + atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + owner: Addr::unchecked("owner"), + }; + assert_eq!( + cfg_empty_description.validate(), + Err(ContractError::DescriptionIsEmpty {}) + ); + } +} diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs new file mode 100644 index 00000000..bd55f989 --- /dev/null +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs @@ -0,0 +1,81 @@ +use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; +use cosmwasm_std::{Deps, StdResult, Uint128}; +use neutron_voting_power::voting_power::voting_power_from_lp_tokens; +use serde::Serialize; + +pub fn get_voting_power_for_address( + deps: Deps, + lockdrop_contract: impl Into, + usdc_cl_pool_contract: impl Into, + atom_cl_pool_contract: impl Into, + pool_type: PoolType, + address: String, + height: u64, +) -> StdResult { + let pool_contract: String = match pool_type { + PoolType::ATOM => atom_cl_pool_contract.into(), + PoolType::USDC => usdc_cl_pool_contract.into(), + }; + + get_voting_power( + deps, + lockdrop_contract, + pool_contract, + &LockdropQueryMsg::QueryUserLockupTotalAtHeight { + pool_type, + user_address: address, + height, + }, + height, + ) +} + +pub fn get_voting_power_total( + deps: Deps, + lp_contract: impl Into, + oracle_usdc_contract: impl Into, + oracle_atom_contract: impl Into, + pool_type: PoolType, + height: u64, +) -> StdResult { + let oracle_contract: String = match pool_type { + PoolType::ATOM => oracle_atom_contract.into(), + PoolType::USDC => oracle_usdc_contract.into(), + }; + + get_voting_power( + deps, + lp_contract, + oracle_contract, + &LockdropQueryMsg::QueryLockupTotalAtHeight { pool_type, height }, + height, + ) +} + +pub fn get_voting_power( + deps: Deps, + lockdrop_contract: impl Into, + pool_contract: String, + msg: &impl Serialize, + height: u64, +) -> StdResult { + let lp_tokens: Option = deps.querier.query_wasm_smart(lockdrop_contract, msg)?; + + let pair_info: astroport::asset::PairInfo = deps.querier.query_wasm_smart( + &pool_contract, + &astroport::pair_concentrated::QueryMsg::Pair {}, + )?; + + let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( + pair_info.liquidity_token, + &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, + )?; + + voting_power_from_lp_tokens( + deps, + lp_tokens.unwrap_or_default(), + lp_total_supply, + pool_contract, + height, + ) +} diff --git a/packages/neutron-lockdrop-vault/Cargo.toml b/packages/neutron-lockdrop-vault/Cargo.toml index 71957afb..bd89ce67 100644 --- a/packages/neutron-lockdrop-vault/Cargo.toml +++ b/packages/neutron-lockdrop-vault/Cargo.toml @@ -12,6 +12,5 @@ cwd-macros = { path = "../cwd-macros" } schemars = "0.8.8" serde = { version = "1.0.175", default-features = false, features = ["derive"] } thiserror = { version = "1.0" } -astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } -neutron-oracle = { path = "../neutron-voting-power" } -astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", rev = "e306308dd23d567399c15d899f295a910ede945b" } +astroport-periphery = { package="astroport-periphery", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } +neutron-oracle = { path = "../neutron-oracle" } diff --git a/packages/neutron-lockdrop-vault/src/msg.rs b/packages/neutron-lockdrop-vault/src/msg.rs index 3f72628f..b429bea3 100644 --- a/packages/neutron-lockdrop-vault/src/msg.rs +++ b/packages/neutron-lockdrop-vault/src/msg.rs @@ -10,10 +10,10 @@ pub struct InstantiateMsg { pub description: String, /// The lockdrop contract behind the vault. pub lockdrop_contract: String, - /// The USDC/NTRN CL pool contract. - pub usdc_cl_pool_contract: String, - /// The ATOM/NTRN CL pool oracle contract. - pub atom_cl_pool_contract: String, + /// The oracle USDC/NTRN contract behind the vault. + pub oracle_usdc_contract: String, + /// The oracle ATOM/NTRN contract behind the vault. + pub oracle_atom_contract: String, /// Owner can update all configs including changing the owner. This will generally be a DAO. pub owner: String, } @@ -42,7 +42,4 @@ pub enum QueryMsg { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct MigrateMsg { - pub atom_cl_pool_contract: String, - pub usdc_cl_pool_contract: String, -} +pub struct MigrateMsg {} diff --git a/packages/neutron-lockdrop-vault/src/types.rs b/packages/neutron-lockdrop-vault/src/types.rs index ee515c97..1df6066f 100644 --- a/packages/neutron-lockdrop-vault/src/types.rs +++ b/packages/neutron-lockdrop-vault/src/types.rs @@ -4,7 +4,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct OldConfig { +pub struct Config { pub name: String, pub description: String, pub lockdrop_contract: Addr, @@ -13,16 +13,6 @@ pub struct OldConfig { pub owner: Addr, } -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct Config { - pub name: String, - pub description: String, - pub lockdrop_contract: Addr, - pub usdc_cl_pool_contract: Addr, - pub atom_cl_pool_contract: Addr, - pub owner: Addr, -} - impl Config { /// checks whether the config fields are valid. pub fn validate(&self) -> Result<(), ContractError> { @@ -48,8 +38,8 @@ mod tests { name: String::from("name"), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), - atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), + oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg_ok.validate(), Ok(())); @@ -58,8 +48,8 @@ mod tests { name: String::from(""), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), - atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), + oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!( @@ -71,8 +61,8 @@ mod tests { name: String::from("name"), description: String::from(""), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - usdc_cl_pool_contract: Addr::unchecked("cl_pool_usdc_contract"), - atom_cl_pool_contract: Addr::unchecked("cl_pool_atom_contract"), + oracle_usdc_contract: Addr::unchecked("oracle_usdc_contract"), + oracle_atom_contract: Addr::unchecked("oracle_atom_contract"), owner: Addr::unchecked("owner"), }; assert_eq!( diff --git a/packages/neutron-lockdrop-vault/src/voting_power.rs b/packages/neutron-lockdrop-vault/src/voting_power.rs index f8b9496b..8ebc8148 100644 --- a/packages/neutron-lockdrop-vault/src/voting_power.rs +++ b/packages/neutron-lockdrop-vault/src/voting_power.rs @@ -1,26 +1,26 @@ use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; -use cosmwasm_std::{Deps, StdResult, Uint128}; +use cosmwasm_std::{Decimal256, Deps, StdResult, Uint128}; use neutron_oracle::voting_power::voting_power_from_lp_tokens; use serde::Serialize; pub fn get_voting_power_for_address( deps: Deps, - lockdrop_contract: impl Into, - usdc_cl_pool_contract: impl Into, - atom_cl_pool_contract: impl Into, + lp_contract: impl Into, + oracle_usdc_contract: impl Into, + oracle_atom_contract: impl Into, pool_type: PoolType, address: String, height: u64, -) -> StdResult { - let pool_contract: String = match pool_type { - PoolType::ATOM => atom_cl_pool_contract.into(), - PoolType::USDC => usdc_cl_pool_contract.into(), +) -> StdResult { + let oracle_contract: String = match pool_type { + PoolType::ATOM => oracle_atom_contract.into(), + PoolType::USDC => oracle_usdc_contract.into(), }; get_voting_power( deps, - lockdrop_contract, - pool_contract, + lp_contract, + oracle_contract, &LockdropQueryMsg::QueryUserLockupTotalAtHeight { pool_type, user_address: address, @@ -37,7 +37,7 @@ pub fn get_voting_power_total( oracle_atom_contract: impl Into, pool_type: PoolType, height: u64, -) -> StdResult { +) -> StdResult { let oracle_contract: String = match pool_type { PoolType::ATOM => oracle_atom_contract.into(), PoolType::USDC => oracle_usdc_contract.into(), @@ -54,28 +54,12 @@ pub fn get_voting_power_total( pub fn get_voting_power( deps: Deps, - lockdrop_contract: impl Into, - pool_contract: String, + lp_contract: impl Into, + oracle_contract: impl Into, msg: &impl Serialize, height: u64, -) -> StdResult { - let lp_tokens: Option = deps.querier.query_wasm_smart(lockdrop_contract, msg)?; - - let pair_info: astroport::asset::PairInfo = deps.querier.query_wasm_smart( - &pool_contract, - &astroport::pair_concentrated::QueryMsg::Pair {}, - )?; - - let lp_total_supply: Uint128 = deps.querier.query_wasm_smart( - pair_info.liquidity_token, - &astroport::xastro_token::QueryMsg::TotalSupplyAt { block: height }, - )?; +) -> StdResult { + let lp_tokens: Option = deps.querier.query_wasm_smart(lp_contract, msg)?; - voting_power_from_lp_tokens( - deps, - lp_tokens.unwrap_or_default(), - lp_total_supply, - pool_contract, - height, - ) + voting_power_from_lp_tokens(deps, lp_tokens.unwrap_or_default(), oracle_contract, height) } diff --git a/packages/neutron-oracle/Cargo.toml b/packages/neutron-oracle/Cargo.toml new file mode 100644 index 00000000..32371404 --- /dev/null +++ b/packages/neutron-oracle/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "neutron-oracle" +version = "0.1.0" +authors = ["Murad Karammaev "] +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/neutron/neutron-dao" + +[dependencies] +cosmwasm-std = { version = "1.3.0" } +astroport = { package="astroport", git = "https://github.com/neutron-org/neutron-tge-contracts.git", branch = "main" } diff --git a/packages/neutron-oracle/src/lib.rs b/packages/neutron-oracle/src/lib.rs new file mode 100644 index 00000000..2febfaf6 --- /dev/null +++ b/packages/neutron-oracle/src/lib.rs @@ -0,0 +1 @@ +pub mod voting_power; diff --git a/packages/neutron-oracle/src/voting_power.rs b/packages/neutron-oracle/src/voting_power.rs new file mode 100644 index 00000000..ca3b37e4 --- /dev/null +++ b/packages/neutron-oracle/src/voting_power.rs @@ -0,0 +1,32 @@ +use astroport::{asset::AssetInfo, oracle::QueryMsg as OracleQueryMsg}; +use cosmwasm_std::{Decimal256, Deps, StdError, StdResult, Uint128, Uint256, Uint64}; + +pub fn voting_power_from_lp_tokens( + deps: Deps, + lp_tokens: Uint128, + oracle_contract: impl Into, + height: u64, +) -> StdResult { + Ok(if lp_tokens.is_zero() { + Decimal256::zero() + } else { + let twap: Decimal256 = deps + .querier + .query_wasm_smart::>( + oracle_contract, + &OracleQueryMsg::TWAPAtHeight { + token: AssetInfo::NativeToken { + denom: "untrn".to_string(), + }, + height: Uint64::new(height), + }, + )? + .into_iter() + .map(|x| x.1) + .sum::(); + + Decimal256::new(Uint256::from(lp_tokens)) + .checked_div(twap.sqrt()) + .map_err(|err| StdError::generic_err(format!("{}", err)))? + }) +} diff --git a/packages/neutron-vesting-lp-vault-for-cl-pools/Cargo.toml b/packages/neutron-vesting-lp-vault-for-cl-pools/Cargo.toml new file mode 100644 index 00000000..5f80be1d --- /dev/null +++ b/packages/neutron-vesting-lp-vault-for-cl-pools/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "neutron-vesting-lp-vault-for-cl-pools" +version = "0.1.0" +authors = ["Sergei Sotnikov ", "Murad Karammaev "] +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/neutron/neutron-dao" + +[dependencies] +serde = { version = "1.0.175", default-features = false, features = ["derive"] } +schemars = "0.8.8" +cwd-macros = { path = "../cwd-macros" } +cosmwasm-std = { version = "1.3.0" } +thiserror = { version = "1.0" } diff --git a/packages/neutron-vesting-lp-vault-for-cl-pools/src/error.rs b/packages/neutron-vesting-lp-vault-for-cl-pools/src/error.rs new file mode 100644 index 00000000..3d0bd284 --- /dev/null +++ b/packages/neutron-vesting-lp-vault-for-cl-pools/src/error.rs @@ -0,0 +1,28 @@ +use cosmwasm_std::{OverflowError, StdError}; +use thiserror::Error; + +#[derive(Error, Debug, PartialEq)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, + + #[error("Bonding is not available for this contract")] + BondingDisabled {}, + + #[error("Direct unbonding is not available for this contract")] + DirectUnbondingDisabled {}, + + #[error("config name cannot be empty.")] + NameIsEmpty {}, + + #[error("config description cannot be empty.")] + DescriptionIsEmpty {}, + + #[error("{0}")] + OverflowError(#[from] OverflowError), +} + +pub type ContractResult = Result; diff --git a/packages/neutron-vesting-lp-vault-for-cl-pools/src/lib.rs b/packages/neutron-vesting-lp-vault-for-cl-pools/src/lib.rs new file mode 100644 index 00000000..691626ce --- /dev/null +++ b/packages/neutron-vesting-lp-vault-for-cl-pools/src/lib.rs @@ -0,0 +1,3 @@ +pub mod error; +pub mod msg; +pub mod types; diff --git a/packages/neutron-vesting-lp-vault-for-cl-pools/src/msg.rs b/packages/neutron-vesting-lp-vault-for-cl-pools/src/msg.rs new file mode 100644 index 00000000..db99c1b2 --- /dev/null +++ b/packages/neutron-vesting-lp-vault-for-cl-pools/src/msg.rs @@ -0,0 +1,48 @@ +use cwd_macros::{info_query, voting_query, voting_vault, voting_vault_query}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +pub struct InstantiateMsg { + /// Name contains the vault name which is used to ease the vault's recognition. + pub name: String, + /// Description contains information that characterizes the vault. + pub description: String, + /// The ATOM Vesting LP contract behind the vault. + pub atom_vesting_lp_contract: String, + /// The ATOM/NTRN CL pool contract. + pub atom_cl_pool_contract: String, + /// The USDC Vesting LP contract behind the vault. + pub usdc_vesting_lp_contract: String, + /// The USDC/NTRN CL pool oracle contract. + pub usdc_cl_pool_contract: String, + /// Owner can update all configs including changing the owner. This will generally be a DAO. + pub owner: String, +} + +#[voting_vault] +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[serde(rename_all = "snake_case")] +pub enum ExecuteMsg { + UpdateConfig { + owner: String, + atom_vesting_lp_contract: String, + atom_cl_pool_contract: String, + usdc_vesting_lp_contract: String, + usdc_cl_pool_contract: String, + name: String, + description: String, + }, +} + +#[voting_query] +#[voting_vault_query] +#[info_query] +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + Config {}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct MigrateMsg {} diff --git a/packages/neutron-vesting-lp-vault-for-cl-pools/src/types.rs b/packages/neutron-vesting-lp-vault-for-cl-pools/src/types.rs new file mode 100644 index 00000000..46fe9972 --- /dev/null +++ b/packages/neutron-vesting-lp-vault-for-cl-pools/src/types.rs @@ -0,0 +1,76 @@ +use crate::error::{ContractError, ContractResult}; +use cosmwasm_std::Addr; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] +pub struct Config { + pub name: String, + pub description: String, + pub atom_vesting_lp_contract: Addr, + pub atom_cl_pool_contract: Addr, + pub usdc_vesting_lp_contract: Addr, + pub usdc_cl_pool_contract: Addr, + pub owner: Addr, +} + +impl Config { + /// checks whether the config fields are valid. + pub fn validate(&self) -> ContractResult<()> { + if self.name.is_empty() { + return Err(ContractError::NameIsEmpty {}); + } + if self.description.is_empty() { + return Err(ContractError::DescriptionIsEmpty {}); + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use crate::{error::ContractError, types::Config}; + use cosmwasm_std::Addr; + + #[test] + fn valid_config() { + let cfg = Config { + name: String::from("name"), + description: String::from("description"), + atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + owner: Addr::unchecked("owner"), + }; + assert!(cfg.validate().is_ok()); + } + + #[test] + fn empty_name() { + let cfg = Config { + name: String::from(""), + description: String::from("description"), + atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + owner: Addr::unchecked("owner"), + }; + assert_eq!(cfg.validate(), Err(ContractError::NameIsEmpty {})); + } + + #[test] + fn empty_description() { + let cfg = Config { + name: String::from("name"), + description: String::from(""), + atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), + atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), + usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + owner: Addr::unchecked("owner"), + }; + assert_eq!(cfg.validate(), Err(ContractError::DescriptionIsEmpty {})); + } +} diff --git a/packages/neutron-vesting-lp-vault/src/error.rs b/packages/neutron-vesting-lp-vault/src/error.rs index 3d0bd284..2f42b205 100644 --- a/packages/neutron-vesting-lp-vault/src/error.rs +++ b/packages/neutron-vesting-lp-vault/src/error.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{OverflowError, StdError}; +use cosmwasm_std::StdError; use thiserror::Error; #[derive(Error, Debug, PartialEq)] @@ -20,9 +20,6 @@ pub enum ContractError { #[error("config description cannot be empty.")] DescriptionIsEmpty {}, - - #[error("{0}")] - OverflowError(#[from] OverflowError), } pub type ContractResult = Result; diff --git a/packages/neutron-vesting-lp-vault/src/msg.rs b/packages/neutron-vesting-lp-vault/src/msg.rs index c3a27b1b..01b5a6ba 100644 --- a/packages/neutron-vesting-lp-vault/src/msg.rs +++ b/packages/neutron-vesting-lp-vault/src/msg.rs @@ -10,12 +10,12 @@ pub struct InstantiateMsg { pub description: String, /// The ATOM Vesting LP contract behind the vault. pub atom_vesting_lp_contract: String, - /// The ATOM/NTRN CL pool contract. - pub atom_cl_pool_contract: String, + /// The ATOM oracle contract behind the vault. + pub atom_oracle_contract: String, /// The USDC Vesting LP contract behind the vault. pub usdc_vesting_lp_contract: String, - /// The USDC/NTRN CL pool oracle contract. - pub usdc_cl_pool_contract: String, + /// The USDC oracle contract behind the vault. + pub usdc_oracle_contract: String, /// Owner can update all configs including changing the owner. This will generally be a DAO. pub owner: String, } @@ -27,9 +27,9 @@ pub enum ExecuteMsg { UpdateConfig { owner: String, atom_vesting_lp_contract: String, - atom_cl_pool_contract: String, + atom_oracle_contract: String, usdc_vesting_lp_contract: String, - usdc_cl_pool_contract: String, + usdc_oracle_contract: String, name: String, description: String, }, @@ -45,7 +45,4 @@ pub enum QueryMsg { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct MigrateMsg { - pub atom_cl_pool: String, - pub usdc_cl_pool: String, -} +pub struct MigrateMsg {} diff --git a/packages/neutron-vesting-lp-vault/src/types.rs b/packages/neutron-vesting-lp-vault/src/types.rs index 06174ec8..bedee1b8 100644 --- a/packages/neutron-vesting-lp-vault/src/types.rs +++ b/packages/neutron-vesting-lp-vault/src/types.rs @@ -4,7 +4,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct OldConfig { +pub struct Config { pub name: String, pub description: String, pub atom_vesting_lp_contract: Addr, @@ -14,17 +14,6 @@ pub struct OldConfig { pub owner: Addr, } -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] -pub struct Config { - pub name: String, - pub description: String, - pub atom_vesting_lp_contract: Addr, - pub atom_cl_pool_contract: Addr, - pub usdc_vesting_lp_contract: Addr, - pub usdc_cl_pool_contract: Addr, - pub owner: Addr, -} - impl Config { /// checks whether the config fields are valid. pub fn validate(&self) -> ContractResult<()> { @@ -49,9 +38,9 @@ mod tests { name: String::from("name"), description: String::from("description"), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), owner: Addr::unchecked("owner"), }; assert!(cfg.validate().is_ok()); @@ -63,9 +52,9 @@ mod tests { name: String::from(""), description: String::from("description"), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg.validate(), Err(ContractError::NameIsEmpty {})); @@ -77,9 +66,9 @@ mod tests { name: String::from("name"), description: String::from(""), atom_vesting_lp_contract: Addr::unchecked("atom_vesting_lp_contract"), - atom_cl_pool_contract: Addr::unchecked("atom_cl_pool_contract"), + atom_oracle_contract: Addr::unchecked("atom_oracle_contract"), usdc_vesting_lp_contract: Addr::unchecked("usdc_vesting_lp_contract"), - usdc_cl_pool_contract: Addr::unchecked("usdc_cl_pool_contract"), + usdc_oracle_contract: Addr::unchecked("usdc_oracle_contract"), owner: Addr::unchecked("owner"), }; assert_eq!(cfg.validate(), Err(ContractError::DescriptionIsEmpty {})); diff --git a/packages/neutron-voting-power/Cargo.toml b/packages/neutron-voting-power/Cargo.toml index 4f623b69..de4f5172 100644 --- a/packages/neutron-voting-power/Cargo.toml +++ b/packages/neutron-voting-power/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "neutron-oracle" +name = "neutron-voting-power" version = "0.1.0" authors = ["Murad Karammaev "] edition = "2021" From 71981b5a5c5f87e13aee72f4a4b3248d78e350ce Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Mon, 4 Sep 2023 17:05:36 +0300 Subject: [PATCH 20/23] check_contracts --locked --- Makefile | 2 +- .../schema/query_msg.json | 27 ++++++++++++------- .../schema/query_msg.json | 27 ++++++++++++------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index b771bc9d..9bdfd8e7 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ fmt: @cargo fmt -- --check check_contracts: - @cargo install cosmwasm-check + @cargo install cosmwasm-check --locked @cosmwasm-check --available-capabilities iterator,staking,stargate,neutron artifacts/*.wasm compile: diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json index a7567a73..da19bedd 100644 --- a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/query_msg.json @@ -9,7 +9,8 @@ ], "properties": { "config": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -37,7 +38,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -59,7 +61,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -87,7 +90,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -99,7 +103,8 @@ ], "properties": { "dao": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -111,7 +116,8 @@ ], "properties": { "name": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -123,7 +129,8 @@ ], "properties": { "description": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -151,7 +158,8 @@ "null" ] } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -163,7 +171,8 @@ ], "properties": { "info": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json index a7567a73..da19bedd 100644 --- a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/schema/query_msg.json @@ -9,7 +9,8 @@ ], "properties": { "config": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -37,7 +38,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -59,7 +61,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -87,7 +90,8 @@ "format": "uint64", "minimum": 0.0 } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -99,7 +103,8 @@ ], "properties": { "dao": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -111,7 +116,8 @@ ], "properties": { "name": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -123,7 +129,8 @@ ], "properties": { "description": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false @@ -151,7 +158,8 @@ "null" ] } - } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -163,7 +171,8 @@ ], "properties": { "info": { - "type": "object" + "type": "object", + "additionalProperties": false } }, "additionalProperties": false From f22fbf5d0e20a7c0cccbecb42249fd4358614e94 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Tue, 5 Sep 2023 12:31:52 +0300 Subject: [PATCH 21/23] review fixes --- .../src/contract.rs | 36 +++++++++---------- .../src/voting_power.rs | 30 +++++----------- .../neutron-voting-power/src/voting_power.rs | 4 +-- 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs index 1bc07c8f..090df57b 100644 --- a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs @@ -101,8 +101,8 @@ pub fn execute_update_config( info: MessageInfo, new_owner: Option, new_lockdrop_contract: Option, - new_oracle_usdc_contract: Option, - new_oracle_atom_contract: Option, + new_usdc_cl_pool_contract: Option, + new_atom_cl_pool_contract: Option, new_name: Option, new_description: Option, ) -> ContractResult { @@ -119,12 +119,12 @@ pub fn execute_update_config( .map(|new_lockdrop_contract| deps.api.addr_validate(&new_lockdrop_contract)) .transpose()?; - let new_oracle_usdc_contract = new_oracle_usdc_contract - .map(|new_oracle_usdc_contract| deps.api.addr_validate(&new_oracle_usdc_contract)) + let new_usdc_pool_contract = new_usdc_cl_pool_contract + .map(|new_usdc_pool_contract| deps.api.addr_validate(&new_usdc_pool_contract)) .transpose()?; - let new_oracle_atom_contract = new_oracle_atom_contract - .map(|new_oracle_atom_contract| deps.api.addr_validate(&new_oracle_atom_contract)) + let new_atom_pool_contract = new_atom_cl_pool_contract + .map(|new_atom_pool_contract| deps.api.addr_validate(&new_atom_pool_contract)) .transpose()?; if let Some(owner) = new_owner { @@ -134,10 +134,10 @@ pub fn execute_update_config( if let Some(lockdrop_contract) = new_lockdrop_contract { config.lockdrop_contract = lockdrop_contract; } - if let Some(oracle_contract) = new_oracle_usdc_contract { + if let Some(oracle_contract) = new_usdc_pool_contract { config.usdc_cl_pool_contract = oracle_contract; } - if let Some(oracle_contract) = new_oracle_atom_contract { + if let Some(oracle_contract) = new_atom_pool_contract { config.atom_cl_pool_contract = oracle_contract; } if let Some(name) = new_name { @@ -194,18 +194,16 @@ pub fn query_voting_power_at_height( let atom_power = get_voting_power_for_address( deps, - config.lockdrop_contract.as_ref(), - config.usdc_cl_pool_contract.as_ref(), - config.atom_cl_pool_contract.as_ref(), + &config.lockdrop_contract, + &config.atom_cl_pool_contract, PoolType::ATOM, address.clone(), height, )?; let usdc_power = get_voting_power_for_address( deps, - config.lockdrop_contract, - config.usdc_cl_pool_contract, - config.atom_cl_pool_contract, + &config.lockdrop_contract, + &config.usdc_cl_pool_contract, PoolType::USDC, address, height, @@ -227,17 +225,15 @@ pub fn query_total_power_at_height( let atom_power = get_voting_power_total( deps, - config.lockdrop_contract.as_ref(), - config.usdc_cl_pool_contract.as_ref(), - config.atom_cl_pool_contract.as_ref(), + &config.lockdrop_contract, + &config.atom_cl_pool_contract, PoolType::ATOM, height, )?; let usdc_power = get_voting_power_total( deps, - config.lockdrop_contract, - config.usdc_cl_pool_contract, - config.atom_cl_pool_contract, + &config.lockdrop_contract, + &config.usdc_cl_pool_contract, PoolType::USDC, height, )?; diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs index bd55f989..7ddcb919 100644 --- a/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/voting_power.rs @@ -1,22 +1,16 @@ use astroport_periphery::lockdrop::{PoolType, QueryMsg as LockdropQueryMsg}; -use cosmwasm_std::{Deps, StdResult, Uint128}; +use cosmwasm_std::{Addr, Deps, StdResult, Uint128}; use neutron_voting_power::voting_power::voting_power_from_lp_tokens; use serde::Serialize; pub fn get_voting_power_for_address( deps: Deps, - lockdrop_contract: impl Into, - usdc_cl_pool_contract: impl Into, - atom_cl_pool_contract: impl Into, + lockdrop_contract: &Addr, + pool_contract: &Addr, pool_type: PoolType, address: String, height: u64, ) -> StdResult { - let pool_contract: String = match pool_type { - PoolType::ATOM => atom_cl_pool_contract.into(), - PoolType::USDC => usdc_cl_pool_contract.into(), - }; - get_voting_power( deps, lockdrop_contract, @@ -32,21 +26,15 @@ pub fn get_voting_power_for_address( pub fn get_voting_power_total( deps: Deps, - lp_contract: impl Into, - oracle_usdc_contract: impl Into, - oracle_atom_contract: impl Into, + lp_contract: &Addr, + pool_contract: &Addr, pool_type: PoolType, height: u64, ) -> StdResult { - let oracle_contract: String = match pool_type { - PoolType::ATOM => oracle_atom_contract.into(), - PoolType::USDC => oracle_usdc_contract.into(), - }; - get_voting_power( deps, lp_contract, - oracle_contract, + pool_contract, &LockdropQueryMsg::QueryLockupTotalAtHeight { pool_type, height }, height, ) @@ -54,15 +42,15 @@ pub fn get_voting_power_total( pub fn get_voting_power( deps: Deps, - lockdrop_contract: impl Into, - pool_contract: String, + lockdrop_contract: &Addr, + pool_contract: &Addr, msg: &impl Serialize, height: u64, ) -> StdResult { let lp_tokens: Option = deps.querier.query_wasm_smart(lockdrop_contract, msg)?; let pair_info: astroport::asset::PairInfo = deps.querier.query_wasm_smart( - &pool_contract, + pool_contract, &astroport::pair_concentrated::QueryMsg::Pair {}, )?; diff --git a/packages/neutron-voting-power/src/voting_power.rs b/packages/neutron-voting-power/src/voting_power.rs index 12cefc30..6fb019c3 100644 --- a/packages/neutron-voting-power/src/voting_power.rs +++ b/packages/neutron-voting-power/src/voting_power.rs @@ -1,10 +1,10 @@ -use cosmwasm_std::{Deps, StdResult, Uint128, Uint64}; +use cosmwasm_std::{Addr, Deps, StdResult, Uint128, Uint64}; pub fn voting_power_from_lp_tokens( deps: Deps, lp_tokens: Uint128, total_lp_tokens: Uint128, - cl_pool: impl Into, + cl_pool: &Addr, height: u64, ) -> StdResult { if lp_tokens.is_zero() { From eb244d31baa4185c29097f0bb47d9b6f816b9011 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Tue, 5 Sep 2023 14:36:31 +0300 Subject: [PATCH 22/23] oracles -> cl_pools --- .../src/contract.rs | 8 +- .../lockdrop-vault-for-cl-pools/src/tests.rs | 80 ++++++++-------- .../src/tests.rs | 94 +++++++++---------- .../src/msg.rs | 4 +- 4 files changed, 93 insertions(+), 93 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs index 090df57b..e65c6a19 100644 --- a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/contract.rs @@ -65,8 +65,8 @@ pub fn execute( ExecuteMsg::UpdateConfig { owner, lockdrop_contract, - oracle_usdc_contract, - oracle_atom_contract, + usdc_cl_pool_contract, + atom_cl_pool_contract, name, description, } => execute_update_config( @@ -74,8 +74,8 @@ pub fn execute( info, owner, lockdrop_contract, - oracle_usdc_contract, - oracle_atom_contract, + usdc_cl_pool_contract, + atom_cl_pool_contract, name, description, ), diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs index db446ccd..b077bd3c 100644 --- a/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/src/tests.rs @@ -14,11 +14,11 @@ const NEW_NAME: &str = "new_name"; const DESCRIPTION: &str = "description"; const NEW_DESCRIPTION: &str = "new description"; const LOCKDROP_ADDR: &str = "lockdrop"; -const ORACLE_USDC_ADDR: &str = "oracle_usdc"; -const ORACLE_ATOM_ADDR: &str = "oracle_atom"; +const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; +const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; const NEW_LOCKDROP_ADDR: &str = "new_lockdrop"; -const NEW_ORACLE_USDC_ADDR: &str = "new_oracle_usdc"; -const NEW_ORACLE_ATOM_ADDR: &str = "new_oracle_atom"; +const NEW_USDC_CL_POOL_ADDR: &str = "new_usdc_cl_pool"; +const NEW_ATOM_CL_POOL_ADDR: &str = "new_atom_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -115,8 +115,8 @@ fn update_config( sender: &str, owner: Option, lockdrop_contract: Option, - oracle_usdc_contract: Option, - oracle_atom_contract: Option, + usdc_cl_pool_contract: Option, + atom_cl_pool_contract: Option, name: Option, description: Option, ) -> anyhow::Result { @@ -126,8 +126,8 @@ fn update_config( &ExecuteMsg::UpdateConfig { owner, lockdrop_contract, - oracle_usdc_contract, - oracle_atom_contract, + usdc_cl_pool_contract, + atom_cl_pool_contract, name, description, }, @@ -159,8 +159,8 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -179,8 +179,8 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -201,8 +201,8 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -222,8 +222,8 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -234,8 +234,8 @@ fn test_update_config_unauthorized() { ADDR2, Some(ADDR1.to_string()), Some(NEW_LOCKDROP_ADDR.to_string()), - Some(NEW_ORACLE_USDC_ADDR.to_string()), - Some(NEW_ORACLE_ATOM_ADDR.to_string()), + Some(NEW_USDC_CL_POOL_ADDR.to_string()), + Some(NEW_ATOM_CL_POOL_ADDR.to_string()), Some(NEW_NAME.to_string()), Some(NEW_DESCRIPTION.to_string()), ) @@ -254,8 +254,8 @@ fn test_update_config_as_owner() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -266,8 +266,8 @@ fn test_update_config_as_owner() { DAO_ADDR, Some(ADDR1.to_string()), Some(NEW_LOCKDROP_ADDR.to_string()), - Some(NEW_ORACLE_USDC_ADDR.to_string()), - Some(NEW_ORACLE_ATOM_ADDR.to_string()), + Some(NEW_USDC_CL_POOL_ADDR.to_string()), + Some(NEW_ATOM_CL_POOL_ADDR.to_string()), Some(NEW_NAME.to_string()), Some(NEW_DESCRIPTION.to_string()), ) @@ -280,8 +280,8 @@ fn test_update_config_as_owner() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), lockdrop_contract: Addr::unchecked(NEW_LOCKDROP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(NEW_ORACLE_USDC_ADDR), - atom_cl_pool_contract: Addr::unchecked(NEW_ORACLE_ATOM_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_CL_POOL_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_CL_POOL_ADDR), }, config ); @@ -300,8 +300,8 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -312,8 +312,8 @@ fn test_update_config_invalid_description() { DAO_ADDR, Some(DAO_ADDR.to_string()), Some(LOCKDROP_ADDR.to_string()), - Some(ORACLE_USDC_ADDR.to_string()), - Some(ORACLE_ATOM_ADDR.to_string()), + Some(USDC_CL_POOL_ADDR.to_string()), + Some(ATOM_CL_POOL_ADDR.to_string()), Some(NEW_NAME.to_string()), Some(String::from("")), ) @@ -333,8 +333,8 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -345,8 +345,8 @@ fn test_update_config_invalid_name() { DAO_ADDR, Some(DAO_ADDR.to_string()), Some(LOCKDROP_ADDR.to_string()), - Some(ORACLE_USDC_ADDR.to_string()), - Some(ORACLE_ATOM_ADDR.to_string()), + Some(USDC_CL_POOL_ADDR.to_string()), + Some(ATOM_CL_POOL_ADDR.to_string()), Some(String::from("")), Some(NEW_DESCRIPTION.to_string()), ) @@ -365,8 +365,8 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -387,8 +387,8 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -412,8 +412,8 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), lockdrop_contract: LOCKDROP_ADDR.to_string(), - usdc_cl_pool_contract: ORACLE_USDC_ADDR.to_string(), - atom_cl_pool_contract: ORACLE_ATOM_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), }, ); @@ -425,8 +425,8 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(ORACLE_USDC_ADDR), - atom_cl_pool_contract: Addr::unchecked(ORACLE_ATOM_ADDR), + usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR), + atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR), } ) } diff --git a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs index a52a5b83..35d8ba7d 100644 --- a/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs +++ b/contracts/dao/voting/vesting-lp-vault-for-cl-pools/src/tests.rs @@ -18,12 +18,12 @@ const DESCRIPTION: &str = "description"; const NEW_DESCRIPTION: &str = "new description"; const ATOM_VESTING_LP_ADDR: &str = "atom_vesting_lp"; const USDC_VESTING_LP_ADDR: &str = "usdc_vesting_lp"; -const ATOM_ORACLE_ADDR: &str = "atom_oracle"; -const USDC_ORACLE_ADDR: &str = "usdc_oracle"; +const ATOM_CL_POOL_ADDR: &str = "atom_cl_pool"; +const USDC_CL_POOL_ADDR: &str = "usdc_cl_pool"; const NEW_ATOM_VESTING_LP_ADDR: &str = "new_atom_vesting_lp"; const NEW_USDC_VESTING_LP_ADDR: &str = "new_usdc_vesting_lp"; -const NEW_ATOM_ORACLE_ADDR: &str = "new_atom_oracle"; -const NEW_USDC_ORACLE_ADDR: &str = "new_usdc_oracle"; +const NEW_ATOM_CL_POOL_ADDR: &str = "new_atom_cl_pool"; +const NEW_USDC_CL_POOL_ADDR: &str = "new_usdc_cl_pool"; const ADDR1: &str = "addr1"; const ADDR2: &str = "addr2"; const DENOM: &str = "ujuno"; @@ -163,9 +163,9 @@ fn update_config( sender: &str, owner: String, atom_vesting_lp_contract: String, - atom_oracle_contract: String, + atom_cl_pool_contract: String, usdc_vesting_lp_contract: String, - usdc_oracle_contract: String, + usdc_cl_pool_contract: String, name: String, description: String, ) -> anyhow::Result { @@ -175,9 +175,9 @@ fn update_config( &ExecuteMsg::UpdateConfig { owner, atom_vesting_lp_contract, - atom_cl_pool_contract: atom_oracle_contract, + atom_cl_pool_contract, usdc_vesting_lp_contract, - usdc_cl_pool_contract: usdc_oracle_contract, + usdc_cl_pool_contract, name, description, }, @@ -234,9 +234,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -250,9 +250,9 @@ fn test_instantiate() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); assert_eq!(get_dao(&app, &addr), String::from(DAO_ADDR)); @@ -271,9 +271,9 @@ fn test_bond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -294,9 +294,9 @@ fn test_unbond() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -316,9 +316,9 @@ fn test_update_config_unauthorized() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -329,9 +329,9 @@ fn test_update_config_unauthorized() { ADDR2, ADDR1.to_string(), NEW_ATOM_VESTING_LP_ADDR.to_string(), - NEW_ATOM_ORACLE_ADDR.to_string(), + NEW_ATOM_CL_POOL_ADDR.to_string(), NEW_USDC_VESTING_LP_ADDR.to_string(), - NEW_USDC_ORACLE_ADDR.to_string(), + NEW_USDC_CL_POOL_ADDR.to_string(), NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), ) @@ -350,22 +350,22 @@ fn test_update_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); - // Change owner, description, name, lp-vesting and oracle contracts + // Change owner, description, name, lp-vesting and cl pool contracts update_config( &mut app, addr.clone(), DAO_ADDR, ADDR1.to_string(), NEW_ATOM_VESTING_LP_ADDR.to_string(), - NEW_ATOM_ORACLE_ADDR.to_string(), + NEW_ATOM_CL_POOL_ADDR.to_string(), NEW_USDC_VESTING_LP_ADDR.to_string(), - NEW_USDC_ORACLE_ADDR.to_string(), + NEW_USDC_CL_POOL_ADDR.to_string(), NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), ) @@ -378,9 +378,9 @@ fn test_update_config() { description: NEW_DESCRIPTION.to_string(), owner: Addr::unchecked(ADDR1), atom_vesting_lp_contract: Addr::unchecked(NEW_ATOM_VESTING_LP_ADDR), - atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_ORACLE_ADDR), + atom_cl_pool_contract: Addr::unchecked(NEW_ATOM_CL_POOL_ADDR), usdc_vesting_lp_contract: Addr::unchecked(NEW_USDC_VESTING_LP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_ORACLE_ADDR), + usdc_cl_pool_contract: Addr::unchecked(NEW_USDC_CL_POOL_ADDR), }, config ); @@ -399,9 +399,9 @@ fn test_update_config_invalid_description() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -412,9 +412,9 @@ fn test_update_config_invalid_description() { DAO_ADDR, DAO_ADDR.to_string(), ATOM_VESTING_LP_ADDR.to_string(), - ATOM_ORACLE_ADDR.to_string(), + ATOM_CL_POOL_ADDR.to_string(), USDC_VESTING_LP_ADDR.to_string(), - USDC_ORACLE_ADDR.to_string(), + USDC_CL_POOL_ADDR.to_string(), NEW_NAME.to_string(), String::from(""), ) @@ -434,9 +434,9 @@ fn test_update_config_invalid_name() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -447,9 +447,9 @@ fn test_update_config_invalid_name() { DAO_ADDR, DAO_ADDR.to_string(), ATOM_VESTING_LP_ADDR.to_string(), - ATOM_ORACLE_ADDR.to_string(), + ATOM_CL_POOL_ADDR.to_string(), USDC_VESTING_LP_ADDR.to_string(), - USDC_ORACLE_ADDR.to_string(), + USDC_CL_POOL_ADDR.to_string(), String::from(""), NEW_DESCRIPTION.to_string(), ) @@ -468,9 +468,9 @@ fn test_query_dao() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -491,9 +491,9 @@ fn test_query_info() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -517,9 +517,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: ATOM_VESTING_LP_ADDR.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: USDC_VESTING_LP_ADDR.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -531,9 +531,9 @@ fn test_query_get_config() { description: DESCRIPTION.to_string(), owner: Addr::unchecked(DAO_ADDR), atom_vesting_lp_contract: Addr::unchecked(ATOM_VESTING_LP_ADDR), - atom_cl_pool_contract: Addr::unchecked(ATOM_ORACLE_ADDR), + atom_cl_pool_contract: Addr::unchecked(ATOM_CL_POOL_ADDR), usdc_vesting_lp_contract: Addr::unchecked(USDC_VESTING_LP_ADDR), - usdc_cl_pool_contract: Addr::unchecked(USDC_ORACLE_ADDR), + usdc_cl_pool_contract: Addr::unchecked(USDC_CL_POOL_ADDR), } ) } @@ -615,9 +615,9 @@ fn test_voting_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); @@ -703,9 +703,9 @@ fn test_total_power_at_height() { description: DESCRIPTION.to_string(), owner: DAO_ADDR.to_string(), atom_vesting_lp_contract: atom_vesting_lp_addr.to_string(), - atom_cl_pool_contract: ATOM_ORACLE_ADDR.to_string(), + atom_cl_pool_contract: ATOM_CL_POOL_ADDR.to_string(), usdc_vesting_lp_contract: usdc_vesting_lp_addr.to_string(), - usdc_cl_pool_contract: USDC_ORACLE_ADDR.to_string(), + usdc_cl_pool_contract: USDC_CL_POOL_ADDR.to_string(), }, ); diff --git a/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs b/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs index a65ad8bf..4c4b787b 100644 --- a/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs +++ b/packages/neutron-lockdrop-vault-for-cl-pools/src/msg.rs @@ -30,8 +30,8 @@ pub enum ExecuteMsg { UpdateConfig { owner: Option, lockdrop_contract: Option, - oracle_usdc_contract: Option, - oracle_atom_contract: Option, + usdc_cl_pool_contract: Option, + atom_cl_pool_contract: Option, name: Option, description: Option, }, From f02ec440bfaf9047d0a440c4112fe86812d541d2 Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Tue, 5 Sep 2023 14:37:20 +0300 Subject: [PATCH 23/23] schema --- .../schema/execute_msg.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json index a654b145..f9553568 100644 --- a/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json +++ b/contracts/dao/voting/lockdrop-vault-for-cl-pools/schema/execute_msg.json @@ -11,37 +11,37 @@ "update_config": { "type": "object", "properties": { - "description": { + "atom_cl_pool_contract": { "type": [ "string", "null" ] }, - "lockdrop_contract": { + "description": { "type": [ "string", "null" ] }, - "name": { + "lockdrop_contract": { "type": [ "string", "null" ] }, - "oracle_atom_contract": { + "name": { "type": [ "string", "null" ] }, - "oracle_usdc_contract": { + "owner": { "type": [ "string", "null" ] }, - "owner": { + "usdc_cl_pool_contract": { "type": [ "string", "null"