From e56f1cb39508c4620b3ece58a44f179d9d67c5b4 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Wed, 18 Oct 2023 12:12:46 +0100 Subject: [PATCH 1/4] fix: max spread assertion --- .../terraswap_pair/src/commands.rs | 11 +- .../terraswap_pair/src/helpers.rs | 78 +- .../terraswap_pair/src/tests/testing.rs | 197 +- .../vault-manager/schema/raw/execute.json | 1310 +++++++++ .../vault-manager/schema/raw/instantiate.json | 133 + .../vault-manager/schema/raw/query.json | 205 ++ .../schema/raw/response_to_config.json | 151 ++ .../schema/raw/response_to_ownership.json | 95 + .../raw/response_to_payback_amount.json | 100 + .../schema/raw/response_to_share.json | 89 + .../schema/raw/response_to_vault.json | 135 + .../schema/raw/response_to_vaults.json | 135 + .../vault-manager/schema/vault-manager.json | 2362 +++++++++++++++++ 13 files changed, 4818 insertions(+), 183 deletions(-) create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/execute.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/query.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json create mode 100644 contracts/liquidity_hub/vault-manager/schema/vault-manager.json diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs index 5ebb6e9c..806c8cbf 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs @@ -403,15 +403,18 @@ pub fn swap( amount: swap_computation.return_amount, }; + let fees = swap_computation + .swap_fee_amount + .checked_add(swap_computation.protocol_fee_amount)? + .checked_add(swap_computation.burn_fee_amount)?; // check max spread limit if exist + helpers::assert_max_spread( belief_price, max_spread, - offer_asset.clone(), - return_asset.clone(), + offer_asset.amount, + return_asset.amount.checked_add(fees)?, swap_computation.spread_amount, - offer_decimal, - ask_decimal, )?; let receiver = to.unwrap_or_else(|| sender.clone()); diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs index cebfd1a2..480a1376 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs @@ -1,16 +1,17 @@ use std::cmp::Ordering; use std::ops::Mul; +use std::str::FromStr; use cosmwasm_schema::cw_serde; +#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))] +use cosmwasm_std::CosmosMsg; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, DepsMut, Env, ReplyOn, Response, StdError, StdResult, Storage, - SubMsg, Uint128, Uint256, WasmMsg, + to_binary, Decimal, Decimal256, DepsMut, Env, Fraction, ReplyOn, Response, StdError, StdResult, + Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; -#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))] -use cosmwasm_std::CosmosMsg; use white_whale::pool_network::asset::{Asset, AssetInfo, AssetInfoRaw, PairType}; #[cfg(feature = "token_factory")] use white_whale::pool_network::denom::MsgCreateDenom; @@ -322,58 +323,32 @@ pub struct OfferAmountComputation { pub burn_fee_amount: Uint128, } +/// Default swap slippage in case max_spread is not specified +pub const DEFAULT_SLIPPAGE: &str = "0.005"; +/// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will +/// be capped to this value. +pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; + /// If `belief_price` and `max_spread` both are given, /// we compute new spread else we just use pool network /// spread to check `max_spread` pub fn assert_max_spread( belief_price: Option, max_spread: Option, - offer_asset: Asset, - return_asset: Asset, + offer_amount: Uint128, + return_amount: Uint128, spread_amount: Uint128, - offer_decimal: u8, - return_decimal: u8, ) -> Result<(), ContractError> { - let (offer_amount, return_amount, spread_amount): (Uint256, Uint256, Uint256) = - match offer_decimal.cmp(&return_decimal) { - Ordering::Greater => { - let diff_decimal = 10u64.pow((offer_decimal - return_decimal).into()); - - ( - offer_asset.amount.into(), - return_asset - .amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - spread_amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - ) - } - Ordering::Less => { - let diff_decimal = 10u64.pow((return_decimal - offer_decimal).into()); - - ( - offer_asset - .amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - return_asset.amount.into(), - spread_amount.into(), - ) - } - Ordering::Equal => ( - offer_asset.amount.into(), - return_asset.amount.into(), - spread_amount.into(), - ), - }; - - if let (Some(max_spread), Some(belief_price)) = (max_spread, belief_price) { - let belief_price: Decimal256 = belief_price.into(); - let max_spread: Decimal256 = max_spread.into(); - - let expected_return = offer_amount * (Decimal256::one() / belief_price); + let max_spread: Decimal256 = max_spread + .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) + .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) + .into(); + + if let Some(belief_price) = belief_price { + let expected_return = offer_amount + * belief_price + .inv() + .ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?; let spread_amount = expected_return.saturating_sub(return_amount); if return_amount < expected_return @@ -381,11 +356,8 @@ pub fn assert_max_spread( { return Err(ContractError::MaxSpreadAssertion {}); } - } else if let Some(max_spread) = max_spread { - let max_spread: Decimal256 = max_spread.into(); - if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { - return Err(ContractError::MaxSpreadAssertion {}); - } + } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { + return Err(ContractError::MaxSpreadAssertion {}); } Ok(()) diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs index c22e73bd..1d25ff70 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs @@ -348,175 +348,120 @@ fn test_initialization_invalid_fees() { #[test] fn test_max_spread() { - let offer_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; - let ask_asset_info = AssetInfo::NativeToken { - denom: "ask_asset_info".to_string(), - }; - assert_max_spread( - Some(Decimal::from_ratio(1_200u128, 1u128)), + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1_200_000_000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(989_999u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(989_999u128), Uint128::zero(), - 6u8, - 6u8, ) .unwrap_err(); + // same example as above but using 6 and 18 decimal places assert_max_spread( - Some(Decimal::from_ratio(1_200u128, 1u128)), + Some(Decimal::from_ratio( + 1200_000_000u128, + 1_000_000_000_000_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1_200_000_000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(990_000u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(989_999_900_000_000_000u128), + Uint128::zero(), + ) + .unwrap_err(); + + assert_max_spread( + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + None, // defaults to 0.5% + Uint128::from(1200_000_000u128), + Uint128::from(995_000u128), // all good Uint128::zero(), - 6u8, - 6u8, ) .unwrap(); assert_max_spread( - None, - Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::zero(), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(989_999u128), - }, - Uint128::from(1_0001u128), - 6u8, - 6u8, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + None, // defaults to 0.5% + Uint128::from(1200_000_000u128), + Uint128::from(990_000u128), // fails + Uint128::zero(), ) .unwrap_err(); assert_max_spread( - None, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::zero(), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(990_000u128), - }, - Uint128::from(10_000u128), - 6u8, - 6u8, + Uint128::from(1200_000_000u128), + Uint128::from(990_000u128), + Uint128::zero(), ) .unwrap(); -} - -#[test] -fn test_max_spread_with_diff_decimal() { - let token_addr = "ask_asset_info".to_string(); - - let mut deps = mock_dependencies(&[]); - deps.querier.with_token_balances(&[( - &token_addr, - &[( - &MOCK_CONTRACT_ADDR.to_string(), - &Uint128::from(10000000000u64), - )], - )]); - let offer_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; - let ask_asset_info = AssetInfo::Token { - contract_addr: token_addr.to_string(), - }; + // same example as above but using 6 and 18 decimal place assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio( + 1200_000_000u128, + 1_000_000_000_000_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(100000000u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(990_000__000_000_000_000u128), + Uint128::zero(), + ) + .unwrap(); + + // similar example with 18 and 6 decimal places + assert_max_spread( + Some(Decimal::from_ratio( + 1_000_000_000_000_000_000u128, + 10_000_000u128, + )), + Some(Decimal::percent(2)), + Uint128::from(1_000_000_000_000_000_000u128), + Uint128::from(9_800_000u128), Uint128::zero(), - 6u8, - 8u8, ) .unwrap(); + // same as before but error because spread is 1% assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio( + 1_000_000_000_000_000_000u128, + 10_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(98999999u128), - }, + Uint128::from(1_000_000_000_000_000_000u128), + Uint128::from(9_800_000u128), Uint128::zero(), - 6u8, - 8u8, ) .unwrap_err(); - let offer_asset_info = AssetInfo::Token { - contract_addr: token_addr, - }; - let ask_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; + assert_max_spread( + None, + Some(Decimal::percent(1)), + Uint128::zero(), + Uint128::from(989_999u128), + Uint128::from(10001u128), + ) + .unwrap_err(); assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + None, Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(120000000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(1000000u128), - }, Uint128::zero(), - 8u8, - 6u8, + Uint128::from(990_000u128), + Uint128::from(10000u128), ) .unwrap(); assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), - Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::from(120000000000u128), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(989999u128), - }, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + Some(Decimal::percent(60)), // this will default to 50% + Uint128::from(1200_000_000u128), + Uint128::from(989_999u128), Uint128::zero(), - 8u8, - 6u8, ) - .unwrap_err(); + .unwrap(); } #[test] diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/execute.json b/contracts/liquidity_hub/vault-manager/schema/raw/execute.json new file mode 100644 index 00000000..e83e325d --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/execute.json @@ -0,0 +1,1310 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "description": "The execution messages", + "oneOf": [ + { + "description": "Creates a new vault given the asset info the vault should manage deposits and withdrawals for and the fees", + "type": "object", + "required": [ + "create_vault" + ], + "properties": { + "create_vault": { + "type": "object", + "required": [ + "asset_info", + "fees" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + }, + "fees": { + "$ref": "#/definitions/VaultFee" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Removes a vault given its [AssetInfo]", + "type": "object", + "required": [ + "remove_vault" + ], + "properties": { + "remove_vault": { + "type": "object", + "required": [ + "asset_info" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Updates a vault config", + "type": "object", + "required": [ + "update_vault_fees" + ], + "properties": { + "update_vault_fees": { + "type": "object", + "required": [ + "vault_asset_info", + "vault_fee" + ], + "properties": { + "vault_asset_info": { + "$ref": "#/definitions/AssetInfo" + }, + "vault_fee": { + "$ref": "#/definitions/VaultFee" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Updates the configuration of the vault manager. If a field is not specified, it will not be modified.", + "type": "object", + "required": [ + "update_config" + ], + "properties": { + "update_config": { + "type": "object", + "properties": { + "cw20_lp_code_id": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "deposit_enabled": { + "type": [ + "boolean", + "null" + ] + }, + "flash_loan_enabled": { + "type": [ + "boolean", + "null" + ] + }, + "vault_creation_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Asset" + }, + { + "type": "null" + } + ] + }, + "whale_lair_addr": { + "type": [ + "string", + "null" + ] + }, + "withdraw_enabled": { + "type": [ + "boolean", + "null" + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Deposits a given asset into the vault manager.", + "type": "object", + "required": [ + "deposit" + ], + "properties": { + "deposit": { + "type": "object", + "required": [ + "asset" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Withdraws from the vault manager. Used when the LP token is a token manager token.", + "type": "object", + "required": [ + "withdraw" + ], + "properties": { + "withdraw": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "receive" + ], + "properties": { + "receive": { + "$ref": "#/definitions/Cw20ReceiveMsg" + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the desired `asset` and runs the `payload`, paying the required amount back to the vault after running the messages in the payload, and returning the profit to the sender.", + "type": "object", + "required": [ + "flash_loan" + ], + "properties": { + "flash_loan": { + "type": "object", + "required": [ + "asset", + "payload" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + }, + "payload": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Callback message for post-processing flash-loans.", + "type": "object", + "required": [ + "callback" + ], + "properties": { + "callback": { + "$ref": "#/definitions/CallbackMsg" + } + }, + "additionalProperties": false + }, + { + "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", + "type": "object", + "required": [ + "update_ownership" + ], + "properties": { + "update_ownership": { + "$ref": "#/definitions/Action" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Action": { + "description": "Actions that can be taken to alter the contract's ownership", + "oneOf": [ + { + "description": "Propose to transfer the contract's ownership to another account, optionally with an expiry time.\n\nCan only be called by the contract's current owner.\n\nAny existing pending ownership transfer is overwritten.", + "type": "object", + "required": [ + "transfer_ownership" + ], + "properties": { + "transfer_ownership": { + "type": "object", + "required": [ + "new_owner" + ], + "properties": { + "expiry": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "new_owner": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Accept the pending ownership transfer.\n\nCan only be called by the pending owner.", + "type": "string", + "enum": [ + "accept_ownership" + ] + }, + { + "description": "Give up the contract's ownership and the possibility of appointing a new owner.\n\nCan only be invoked by the contract's current owner.\n\nAny existing pending ownership transfer is canceled.", + "type": "string", + "enum": [ + "renounce_ownership" + ] + } + ] + }, + "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" + }, + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "BankMsg": { + "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", + "oneOf": [ + { + "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "send" + ], + "properties": { + "send": { + "type": "object", + "required": [ + "amount", + "to_address" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "to_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", + "type": "object", + "required": [ + "burn" + ], + "properties": { + "burn": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" + }, + "CallbackMsg": { + "description": "The callback messages available. Only callable by the vault contract itself.", + "oneOf": [ + { + "type": "object", + "required": [ + "after_flashloan" + ], + "properties": { + "after_flashloan": { + "type": "object", + "required": [ + "loan_asset", + "old_asset_balance", + "sender" + ], + "properties": { + "loan_asset": { + "$ref": "#/definitions/Asset" + }, + "old_asset_balance": { + "$ref": "#/definitions/Uint128" + }, + "sender": { + "$ref": "#/definitions/Addr" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "additionalProperties": false + } + ] + }, + "Cw20ReceiveMsg": { + "type": "object", + "required": [ + "amount", + "msg", + "sender" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "msg": { + "$ref": "#/definitions/Binary" + }, + "sender": { + "type": "string" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "GovMsg": { + "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "description": "The vote option.\n\nThis should be called \"option\" for consistency with Cosmos SDK. Sorry for that. See .", + "allOf": [ + { + "$ref": "#/definitions/VoteOption" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote_weighted" + ], + "properties": { + "vote_weighted": { + "type": "object", + "required": [ + "options", + "proposal_id" + ], + "properties": { + "options": { + "type": "array", + "items": { + "$ref": "#/definitions/WeightedVoteOption" + } + }, + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "WasmMsg": { + "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", + "oneOf": [ + { + "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "contract_addr", + "funds", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "msg": { + "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "instantiate" + ], + "properties": { + "instantiate": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readbale label for the contract", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code using a predictable address derivation algorithm implemented in [`cosmwasm_std::instantiate2_address`].\n\nThis is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). `sender` is automatically filled with the current contract's address. `fix_msg` is automatically set to false.", + "type": "object", + "required": [ + "instantiate2" + ], + "properties": { + "instantiate2": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg", + "salt" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readbale label for the contract", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "salt": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin", + "contract_addr" + ], + "properties": { + "admin": { + "type": "string" + }, + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "clear_admin" + ], + "properties": { + "clear_admin": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "WeightedVoteOption": { + "type": "object", + "required": [ + "option", + "weight" + ], + "properties": { + "option": { + "$ref": "#/definitions/VoteOption" + }, + "weight": { + "$ref": "#/definitions/Decimal" + } + } + } + } +} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json b/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json new file mode 100644 index 00000000..1edb0e51 --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json @@ -0,0 +1,133 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "description": "The instantiation message", + "type": "object", + "required": [ + "lp_token_type", + "owner", + "vault_creation_fee", + "whale_lair_addr" + ], + "properties": { + "lp_token_type": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "allOf": [ + { + "$ref": "#/definitions/LpTokenType" + } + ] + }, + "owner": { + "description": "The owner of the contract", + "type": "string" + }, + "vault_creation_fee": { + "description": "The fee to create a vault", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + }, + "whale_lair_addr": { + "description": "The whale lair address, where protocol fees are distributed", + "type": "string" + } + }, + "additionalProperties": false, + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "LpTokenType": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "oneOf": [ + { + "type": "string", + "enum": [ + "token_factory" + ] + }, + { + "type": "object", + "required": [ + "cw20" + ], + "properties": { + "cw20": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "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/liquidity_hub/vault-manager/schema/raw/query.json b/contracts/liquidity_hub/vault-manager/schema/raw/query.json new file mode 100644 index 00000000..092d439c --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/query.json @@ -0,0 +1,205 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "description": "The query messages", + "oneOf": [ + { + "description": "Retrieves the configuration of the manager.", + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves a vault given the asset_info.", + "type": "object", + "required": [ + "vault" + ], + "properties": { + "vault": { + "type": "object", + "required": [ + "asset_info" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the addresses for all the vaults.", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "array", + "null" + ], + "items": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the share of the assets stored in the vault that a given `lp_share` is entitled to.", + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "type": "object", + "required": [ + "lp_share" + ], + "properties": { + "lp_share": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the [`Uint128`] amount that must be sent back to the contract to pay off a loan taken out.", + "type": "object", + "required": [ + "payback_amount" + ], + "properties": { + "payback_amount": { + "type": "object", + "required": [ + "asset" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Query the contract's ownership information", + "type": "object", + "required": [ + "ownership" + ], + "properties": { + "ownership": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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/liquidity_hub/vault-manager/schema/raw/response_to_config.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json new file mode 100644 index 00000000..dcdbe103 --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json @@ -0,0 +1,151 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "description": "Configuration for the contract (manager)", + "type": "object", + "required": [ + "deposit_enabled", + "flash_loan_enabled", + "lp_token_type", + "vault_creation_fee", + "whale_lair_addr", + "withdraw_enabled" + ], + "properties": { + "deposit_enabled": { + "description": "If deposits are enabled", + "type": "boolean" + }, + "flash_loan_enabled": { + "description": "If flash-loans are enabled", + "type": "boolean" + }, + "lp_token_type": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "allOf": [ + { + "$ref": "#/definitions/LpTokenType" + } + ] + }, + "vault_creation_fee": { + "description": "The fee to create a new vault", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + }, + "whale_lair_addr": { + "description": "The whale lair contract address", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + }, + "withdraw_enabled": { + "description": "If withdrawals are enabled", + "type": "boolean" + } + }, + "additionalProperties": false, + "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" + }, + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "LpTokenType": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "oneOf": [ + { + "type": "string", + "enum": [ + "token_factory" + ] + }, + { + "type": "object", + "required": [ + "cw20" + ], + "properties": { + "cw20": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "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/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json new file mode 100644 index 00000000..afe1713f --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json @@ -0,0 +1,95 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Ownership_for_String", + "description": "The contract's ownership info", + "type": "object", + "properties": { + "owner": { + "description": "The contract's current owner. `None` if the ownership has been renounced.", + "type": [ + "string", + "null" + ] + }, + "pending_expiry": { + "description": "The deadline for the pending owner to accept the ownership. `None` if there isn't a pending ownership transfer, or if a transfer exists and it doesn't have a deadline.", + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "pending_owner": { + "description": "The account who has been proposed to take over the ownership. `None` if there isn't a pending ownership transfer.", + "type": [ + "string", + "null" + ] + } + }, + "additionalProperties": false, + "definitions": { + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json new file mode 100644 index 00000000..fc7261f2 --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json @@ -0,0 +1,100 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PaybackAssetResponse", + "description": "Response for the PaybackAmount query. Contains the amount that must be paid back to the contract if taken a flashloan.", + "type": "object", + "required": [ + "asset_info", + "flash_loan_fee", + "payback_amount", + "protocol_fee" + ], + "properties": { + "asset_info": { + "description": "The asset info of the asset that must be paid back", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "flash_loan_fee": { + "description": "The amount of fee paid to vault holders", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "payback_amount": { + "description": "The total amount that must be returned. Equivalent to `amount` + `protocol_fee` + `flash_loan_fee`.", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "protocol_fee": { + "description": "The amount of fee paid to the protocol", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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/liquidity_hub/vault-manager/schema/raw/response_to_share.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json new file mode 100644 index 00000000..3a5e1183 --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json @@ -0,0 +1,89 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ShareResponse", + "description": "Response for the Share query. Contains the amount of assets that the given `lp_share` is entitled to.", + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "description": "The amount of assets that the given `lp_share` is entitled to.", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + } + }, + "additionalProperties": false, + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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/liquidity_hub/vault-manager/schema/raw/response_to_vault.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json new file mode 100644 index 00000000..b1b0014e --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json @@ -0,0 +1,135 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "VaultsResponse", + "description": "Response for the vaults query", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "array", + "items": { + "$ref": "#/definitions/Vault" + } + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "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" + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "Vault": { + "description": "Vault representation", + "type": "object", + "required": [ + "asset_info", + "fees", + "lp_asset" + ], + "properties": { + "asset_info": { + "description": "The asset info the vault manages", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "fees": { + "description": "The fees associated with the vault", + "allOf": [ + { + "$ref": "#/definitions/VaultFee" + } + ] + }, + "lp_asset": { + "description": "The LP asset", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + } + }, + "additionalProperties": false + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + } + } +} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json new file mode 100644 index 00000000..b1b0014e --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json @@ -0,0 +1,135 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "VaultsResponse", + "description": "Response for the vaults query", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "array", + "items": { + "$ref": "#/definitions/Vault" + } + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "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" + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "Vault": { + "description": "Vault representation", + "type": "object", + "required": [ + "asset_info", + "fees", + "lp_asset" + ], + "properties": { + "asset_info": { + "description": "The asset info the vault manages", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "fees": { + "description": "The fees associated with the vault", + "allOf": [ + { + "$ref": "#/definitions/VaultFee" + } + ] + }, + "lp_asset": { + "description": "The LP asset", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + } + }, + "additionalProperties": false + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + } + } +} diff --git a/contracts/liquidity_hub/vault-manager/schema/vault-manager.json b/contracts/liquidity_hub/vault-manager/schema/vault-manager.json new file mode 100644 index 00000000..af50149a --- /dev/null +++ b/contracts/liquidity_hub/vault-manager/schema/vault-manager.json @@ -0,0 +1,2362 @@ +{ + "contract_name": "vault-manager", + "contract_version": "0.1.0", + "idl_version": "1.0.0", + "instantiate": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "description": "The instantiation message", + "type": "object", + "required": [ + "lp_token_type", + "owner", + "vault_creation_fee", + "whale_lair_addr" + ], + "properties": { + "lp_token_type": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "allOf": [ + { + "$ref": "#/definitions/LpTokenType" + } + ] + }, + "owner": { + "description": "The owner of the contract", + "type": "string" + }, + "vault_creation_fee": { + "description": "The fee to create a vault", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + }, + "whale_lair_addr": { + "description": "The whale lair address, where protocol fees are distributed", + "type": "string" + } + }, + "additionalProperties": false, + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "LpTokenType": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "oneOf": [ + { + "type": "string", + "enum": [ + "token_factory" + ] + }, + { + "type": "object", + "required": [ + "cw20" + ], + "properties": { + "cw20": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "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" + } + } + }, + "execute": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "description": "The execution messages", + "oneOf": [ + { + "description": "Creates a new vault given the asset info the vault should manage deposits and withdrawals for and the fees", + "type": "object", + "required": [ + "create_vault" + ], + "properties": { + "create_vault": { + "type": "object", + "required": [ + "asset_info", + "fees" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + }, + "fees": { + "$ref": "#/definitions/VaultFee" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Removes a vault given its [AssetInfo]", + "type": "object", + "required": [ + "remove_vault" + ], + "properties": { + "remove_vault": { + "type": "object", + "required": [ + "asset_info" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Updates a vault config", + "type": "object", + "required": [ + "update_vault_fees" + ], + "properties": { + "update_vault_fees": { + "type": "object", + "required": [ + "vault_asset_info", + "vault_fee" + ], + "properties": { + "vault_asset_info": { + "$ref": "#/definitions/AssetInfo" + }, + "vault_fee": { + "$ref": "#/definitions/VaultFee" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Updates the configuration of the vault manager. If a field is not specified, it will not be modified.", + "type": "object", + "required": [ + "update_config" + ], + "properties": { + "update_config": { + "type": "object", + "properties": { + "cw20_lp_code_id": { + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "deposit_enabled": { + "type": [ + "boolean", + "null" + ] + }, + "flash_loan_enabled": { + "type": [ + "boolean", + "null" + ] + }, + "vault_creation_fee": { + "anyOf": [ + { + "$ref": "#/definitions/Asset" + }, + { + "type": "null" + } + ] + }, + "whale_lair_addr": { + "type": [ + "string", + "null" + ] + }, + "withdraw_enabled": { + "type": [ + "boolean", + "null" + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Deposits a given asset into the vault manager.", + "type": "object", + "required": [ + "deposit" + ], + "properties": { + "deposit": { + "type": "object", + "required": [ + "asset" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Withdraws from the vault manager. Used when the LP token is a token manager token.", + "type": "object", + "required": [ + "withdraw" + ], + "properties": { + "withdraw": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "receive" + ], + "properties": { + "receive": { + "$ref": "#/definitions/Cw20ReceiveMsg" + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the desired `asset` and runs the `payload`, paying the required amount back to the vault after running the messages in the payload, and returning the profit to the sender.", + "type": "object", + "required": [ + "flash_loan" + ], + "properties": { + "flash_loan": { + "type": "object", + "required": [ + "asset", + "payload" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + }, + "payload": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Callback message for post-processing flash-loans.", + "type": "object", + "required": [ + "callback" + ], + "properties": { + "callback": { + "$ref": "#/definitions/CallbackMsg" + } + }, + "additionalProperties": false + }, + { + "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", + "type": "object", + "required": [ + "update_ownership" + ], + "properties": { + "update_ownership": { + "$ref": "#/definitions/Action" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Action": { + "description": "Actions that can be taken to alter the contract's ownership", + "oneOf": [ + { + "description": "Propose to transfer the contract's ownership to another account, optionally with an expiry time.\n\nCan only be called by the contract's current owner.\n\nAny existing pending ownership transfer is overwritten.", + "type": "object", + "required": [ + "transfer_ownership" + ], + "properties": { + "transfer_ownership": { + "type": "object", + "required": [ + "new_owner" + ], + "properties": { + "expiry": { + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "new_owner": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Accept the pending ownership transfer.\n\nCan only be called by the pending owner.", + "type": "string", + "enum": [ + "accept_ownership" + ] + }, + { + "description": "Give up the contract's ownership and the possibility of appointing a new owner.\n\nCan only be invoked by the contract's current owner.\n\nAny existing pending ownership transfer is canceled.", + "type": "string", + "enum": [ + "renounce_ownership" + ] + } + ] + }, + "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" + }, + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "BankMsg": { + "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", + "oneOf": [ + { + "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "send" + ], + "properties": { + "send": { + "type": "object", + "required": [ + "amount", + "to_address" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "to_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", + "type": "object", + "required": [ + "burn" + ], + "properties": { + "burn": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" + }, + "CallbackMsg": { + "description": "The callback messages available. Only callable by the vault contract itself.", + "oneOf": [ + { + "type": "object", + "required": [ + "after_flashloan" + ], + "properties": { + "after_flashloan": { + "type": "object", + "required": [ + "loan_asset", + "old_asset_balance", + "sender" + ], + "properties": { + "loan_asset": { + "$ref": "#/definitions/Asset" + }, + "old_asset_balance": { + "$ref": "#/definitions/Uint128" + }, + "sender": { + "$ref": "#/definitions/Addr" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "staking" + ], + "properties": { + "staking": { + "$ref": "#/definitions/StakingMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "distribution" + ], + "properties": { + "distribution": { + "$ref": "#/definitions/DistributionMsg" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "additionalProperties": false + } + ] + }, + "Cw20ReceiveMsg": { + "type": "object", + "required": [ + "amount", + "msg", + "sender" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "msg": { + "$ref": "#/definitions/Binary" + }, + "sender": { + "type": "string" + } + }, + "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" + }, + "DistributionMsg": { + "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "set_withdraw_address" + ], + "properties": { + "set_withdraw_address": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "description": "The `withdraw_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "withdraw_delegator_reward" + ], + "properties": { + "withdraw_delegator_reward": { + "type": "object", + "required": [ + "validator" + ], + "properties": { + "validator": { + "description": "The `validator_address`", + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "GovMsg": { + "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "description": "The vote option.\n\nThis should be called \"option\" for consistency with Cosmos SDK. Sorry for that. See .", + "allOf": [ + { + "$ref": "#/definitions/VoteOption" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote_weighted" + ], + "properties": { + "vote_weighted": { + "type": "object", + "required": [ + "options", + "proposal_id" + ], + "properties": { + "options": { + "type": "array", + "items": { + "$ref": "#/definitions/WeightedVoteOption" + } + }, + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "exisiting channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "StakingMsg": { + "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", + "oneOf": [ + { + "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "delegate" + ], + "properties": { + "delegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "undelegate" + ], + "properties": { + "undelegate": { + "type": "object", + "required": [ + "amount", + "validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "redelegate" + ], + "properties": { + "redelegate": { + "type": "object", + "required": [ + "amount", + "dst_validator", + "src_validator" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + }, + "dst_validator": { + "type": "string" + }, + "src_validator": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "WasmMsg": { + "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", + "oneOf": [ + { + "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "contract_addr", + "funds", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "msg": { + "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "instantiate" + ], + "properties": { + "instantiate": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readbale label for the contract", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code using a predictable address derivation algorithm implemented in [`cosmwasm_std::instantiate2_address`].\n\nThis is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). `sender` is automatically filled with the current contract's address. `fix_msg` is automatically set to false.", + "type": "object", + "required": [ + "instantiate2" + ], + "properties": { + "instantiate2": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg", + "salt" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readbale label for the contract", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "salt": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin", + "contract_addr" + ], + "properties": { + "admin": { + "type": "string" + }, + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "clear_admin" + ], + "properties": { + "clear_admin": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "WeightedVoteOption": { + "type": "object", + "required": [ + "option", + "weight" + ], + "properties": { + "option": { + "$ref": "#/definitions/VoteOption" + }, + "weight": { + "$ref": "#/definitions/Decimal" + } + } + } + } + }, + "query": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "description": "The query messages", + "oneOf": [ + { + "description": "Retrieves the configuration of the manager.", + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves a vault given the asset_info.", + "type": "object", + "required": [ + "vault" + ], + "properties": { + "vault": { + "type": "object", + "required": [ + "asset_info" + ], + "properties": { + "asset_info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the addresses for all the vaults.", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "object", + "properties": { + "limit": { + "type": [ + "integer", + "null" + ], + "format": "uint32", + "minimum": 0.0 + }, + "start_after": { + "type": [ + "array", + "null" + ], + "items": { + "type": "integer", + "format": "uint8", + "minimum": 0.0 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the share of the assets stored in the vault that a given `lp_share` is entitled to.", + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "type": "object", + "required": [ + "lp_share" + ], + "properties": { + "lp_share": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Retrieves the [`Uint128`] amount that must be sent back to the contract to pay off a loan taken out.", + "type": "object", + "required": [ + "payback_amount" + ], + "properties": { + "payback_amount": { + "type": "object", + "required": [ + "asset" + ], + "properties": { + "asset": { + "$ref": "#/definitions/Asset" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Query the contract's ownership information", + "type": "object", + "required": [ + "ownership" + ], + "properties": { + "ownership": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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" + } + } + }, + "migrate": null, + "sudo": null, + "responses": { + "config": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "description": "Configuration for the contract (manager)", + "type": "object", + "required": [ + "deposit_enabled", + "flash_loan_enabled", + "lp_token_type", + "vault_creation_fee", + "whale_lair_addr", + "withdraw_enabled" + ], + "properties": { + "deposit_enabled": { + "description": "If deposits are enabled", + "type": "boolean" + }, + "flash_loan_enabled": { + "description": "If flash-loans are enabled", + "type": "boolean" + }, + "lp_token_type": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "allOf": [ + { + "$ref": "#/definitions/LpTokenType" + } + ] + }, + "vault_creation_fee": { + "description": "The fee to create a new vault", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + }, + "whale_lair_addr": { + "description": "The whale lair contract address", + "allOf": [ + { + "$ref": "#/definitions/Addr" + } + ] + }, + "withdraw_enabled": { + "description": "If withdrawals are enabled", + "type": "boolean" + } + }, + "additionalProperties": false, + "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" + }, + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "LpTokenType": { + "description": "The type of LP token to use, whether a cw20 token or a token factory token", + "oneOf": [ + { + "type": "string", + "enum": [ + "token_factory" + ] + }, + { + "type": "object", + "required": [ + "cw20" + ], + "properties": { + "cw20": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + ] + }, + "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" + } + } + }, + "ownership": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Ownership_for_String", + "description": "The contract's ownership info", + "type": "object", + "properties": { + "owner": { + "description": "The contract's current owner. `None` if the ownership has been renounced.", + "type": [ + "string", + "null" + ] + }, + "pending_expiry": { + "description": "The deadline for the pending owner to accept the ownership. `None` if there isn't a pending ownership transfer, or if a transfer exists and it doesn't have a deadline.", + "anyOf": [ + { + "$ref": "#/definitions/Expiration" + }, + { + "type": "null" + } + ] + }, + "pending_owner": { + "description": "The account who has been proposed to take over the ownership. `None` if there isn't a pending ownership transfer.", + "type": [ + "string", + "null" + ] + } + }, + "additionalProperties": false, + "definitions": { + "Expiration": { + "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", + "oneOf": [ + { + "description": "AtHeight will expire when `env.block.height` >= height", + "type": "object", + "required": [ + "at_height" + ], + "properties": { + "at_height": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + { + "description": "AtTime will expire when `env.block.time` >= time", + "type": "object", + "required": [ + "at_time" + ], + "properties": { + "at_time": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + }, + { + "description": "Never will never expire. Used to express the empty variant", + "type": "object", + "required": [ + "never" + ], + "properties": { + "never": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } + }, + "payback_amount": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PaybackAssetResponse", + "description": "Response for the PaybackAmount query. Contains the amount that must be paid back to the contract if taken a flashloan.", + "type": "object", + "required": [ + "asset_info", + "flash_loan_fee", + "payback_amount", + "protocol_fee" + ], + "properties": { + "asset_info": { + "description": "The asset info of the asset that must be paid back", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "flash_loan_fee": { + "description": "The amount of fee paid to vault holders", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "payback_amount": { + "description": "The total amount that must be returned. Equivalent to `amount` + `protocol_fee` + `flash_loan_fee`.", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "protocol_fee": { + "description": "The amount of fee paid to the protocol", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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" + } + } + }, + "share": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ShareResponse", + "description": "Response for the Share query. Contains the amount of assets that the given `lp_share` is entitled to.", + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "description": "The amount of assets that the given `lp_share` is entitled to.", + "allOf": [ + { + "$ref": "#/definitions/Asset" + } + ] + } + }, + "additionalProperties": false, + "definitions": { + "Asset": { + "type": "object", + "required": [ + "amount", + "info" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "info": { + "$ref": "#/definitions/AssetInfo" + } + }, + "additionalProperties": false + }, + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "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" + } + } + }, + "vault": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "VaultsResponse", + "description": "Response for the vaults query", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "array", + "items": { + "$ref": "#/definitions/Vault" + } + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "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" + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "Vault": { + "description": "Vault representation", + "type": "object", + "required": [ + "asset_info", + "fees", + "lp_asset" + ], + "properties": { + "asset_info": { + "description": "The asset info the vault manages", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "fees": { + "description": "The fees associated with the vault", + "allOf": [ + { + "$ref": "#/definitions/VaultFee" + } + ] + }, + "lp_asset": { + "description": "The LP asset", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + } + }, + "additionalProperties": false + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + } + } + }, + "vaults": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "VaultsResponse", + "description": "Response for the vaults query", + "type": "object", + "required": [ + "vaults" + ], + "properties": { + "vaults": { + "type": "array", + "items": { + "$ref": "#/definitions/Vault" + } + } + }, + "additionalProperties": false, + "definitions": { + "AssetInfo": { + "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", + "oneOf": [ + { + "type": "object", + "required": [ + "token" + ], + "properties": { + "token": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "native_token" + ], + "properties": { + "native_token": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "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" + }, + "Fee": { + "type": "object", + "required": [ + "share" + ], + "properties": { + "share": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "Vault": { + "description": "Vault representation", + "type": "object", + "required": [ + "asset_info", + "fees", + "lp_asset" + ], + "properties": { + "asset_info": { + "description": "The asset info the vault manages", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + }, + "fees": { + "description": "The fees associated with the vault", + "allOf": [ + { + "$ref": "#/definitions/VaultFee" + } + ] + }, + "lp_asset": { + "description": "The LP asset", + "allOf": [ + { + "$ref": "#/definitions/AssetInfo" + } + ] + } + }, + "additionalProperties": false + }, + "VaultFee": { + "type": "object", + "required": [ + "flash_loan_fee", + "protocol_fee" + ], + "properties": { + "flash_loan_fee": { + "$ref": "#/definitions/Fee" + }, + "protocol_fee": { + "$ref": "#/definitions/Fee" + } + }, + "additionalProperties": false + } + } + } + } +} From a9d31b6df5c7d966a73dbfc9cc55c4459c445d9b Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Thu, 19 Oct 2023 16:58:51 +0100 Subject: [PATCH 2/4] feat: add max_spread property on pool router --- Cargo.lock | 8 +- .../liquidity_hub/fee_collector/Cargo.toml | 2 +- .../fee_collector/src/commands.rs | 5 +- .../src/tests/common_integration.rs | 2 +- .../fee_collector/src/tests/integration.rs | 177 ++++++++-------- .../pool-network/stableswap_3pool/Cargo.toml | 2 +- .../stableswap_3pool/src/commands.rs | 11 +- .../stableswap_3pool/src/helpers.rs | 97 ++++----- .../stableswap_3pool/src/tests/testing.rs | 197 +++++++----------- .../pool-network/terraswap_pair/Cargo.toml | 2 +- .../terraswap_pair/src/commands.rs | 2 +- .../terraswap_pair/src/helpers.rs | 15 +- .../terraswap_pair/src/tests/protocol_fees.rs | 40 ++-- .../terraswap_pair/src/tests/swap.rs | 6 +- .../terraswap_pair/src/tests/testing.rs | 6 +- .../pool-network/terraswap_router/Cargo.toml | 2 +- .../terraswap_router/src/contract.rs | 17 +- .../terraswap_router/src/operations.rs | 3 +- .../terraswap_router/src/testing/tests.rs | 19 +- .../white-whale/src/pool_network/router.rs | 5 +- 20 files changed, 295 insertions(+), 323 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e11160aa..85364201 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,7 +509,7 @@ dependencies = [ [[package]] name = "fee_collector" -version = "1.1.1" +version = "1.1.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1342,7 +1342,7 @@ dependencies = [ [[package]] name = "stableswap-3pool" -version = "1.2.1" +version = "1.2.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1434,7 +1434,7 @@ dependencies = [ [[package]] name = "terraswap-pair" -version = "1.3.1" +version = "1.3.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "terraswap-router" -version = "1.1.0" +version = "1.1.1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/liquidity_hub/fee_collector/Cargo.toml b/contracts/liquidity_hub/fee_collector/Cargo.toml index ec4702af..50b87a89 100644 --- a/contracts/liquidity_hub/fee_collector/Cargo.toml +++ b/contracts/liquidity_hub/fee_collector/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fee_collector" -version = "1.1.1" +version = "1.1.2" authors = ["Kerber0x "] edition.workspace = true description = "Contract to collect the fees accrued by the pools and vaults in the liquidity hub" diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index 3dd3d62d..bfa14771 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - to_binary, Addr, BalanceResponse, BankQuery, Coin, CosmosMsg, DepsMut, Env, MessageInfo, - QueryRequest, ReplyOn, Response, StdResult, SubMsg, Uint128, WasmMsg, WasmQuery, + to_binary, Addr, BalanceResponse, BankQuery, Coin, CosmosMsg, Decimal, DepsMut, Env, + MessageInfo, QueryRequest, ReplyOn, Response, StdResult, SubMsg, Uint128, WasmMsg, WasmQuery, }; use cw20::{Cw20ExecuteMsg, Cw20QueryMsg}; @@ -289,6 +289,7 @@ pub fn aggregate_fees( operations, minimum_receive: None, to: None, + max_spread: Some(Decimal::percent(50u64)), })?; match offer_asset_info.clone() { diff --git a/contracts/liquidity_hub/fee_collector/src/tests/common_integration.rs b/contracts/liquidity_hub/fee_collector/src/tests/common_integration.rs index 160bb030..0d39078b 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/common_integration.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/common_integration.rs @@ -181,7 +181,7 @@ pub fn increase_allowance(app: &mut App, sender: Addr, contract_addr: Addr, spen contract_addr, &cw20::Cw20ExecuteMsg::IncreaseAllowance { spender: spender.to_string(), - amount: Uint128::new(500_000_000_000u128), + amount: Uint128::new(5_000_000_000_000u128), expires: None, }, &[], diff --git a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs index 63ee67b1..030e1bb8 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs @@ -118,7 +118,7 @@ fn collect_all_factories_cw20_fees_successfully() { decimals: 6, initial_balances: vec![Cw20Coin { address: creator.clone().sender.to_string(), - amount: Uint128::new(1_000_000_000_000u128), + amount: Uint128::new(10_000_000_000_000u128), }], mint: Some(MinterResponse { minter: creator.clone().sender.to_string(), @@ -228,13 +228,13 @@ fn collect_all_factories_cw20_fees_successfully() { info: AssetInfo::Token { contract_addr: cw20_tokens[i as usize].to_string(), }, - amount: Uint128::new(500_000u128), + amount: Uint128::new(1_000_000_000_000u128), }, Asset { info: AssetInfo::Token { contract_addr: cw20_tokens[i as usize + 1].to_string(), }, - amount: Uint128::new(500_000u128), + amount: Uint128::new(1_000_000_000_000u128), }, ], slippage_tolerance: None, @@ -274,7 +274,7 @@ fn collect_all_factories_cw20_fees_successfully() { amount: Uint128::new(200_000_000_000u128), msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(20u64)), to: None, }) .unwrap(), @@ -711,10 +711,10 @@ fn collect_cw20_fees_for_specific_contracts_successfully() { cw20_tokens[i].clone(), &Cw20ExecuteMsg::Send { contract: pair_tokens[i - 1].to_string(), - amount: Uint128::new(100_000_000u128), + amount: Uint128::new(100_000u128), msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(30u64)), to: None, }) .unwrap(), @@ -728,10 +728,10 @@ fn collect_cw20_fees_for_specific_contracts_successfully() { cw20_tokens[i].clone(), &Cw20ExecuteMsg::Send { contract: pair_tokens[i].to_string(), - amount: Uint128::new(200_000_000_000u128), + amount: Uint128::new(200_000u128), msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(30u64)), to: None, }) .unwrap(), @@ -935,7 +935,7 @@ fn collect_pools_native_fees_successfully() { let creator = mock_creator(); let balances = vec![( creator.clone().sender, - coins(1_000_000_000u128, "native".to_string()), + coins(50_000_000_000_000u128, "native".to_string()), )]; let mut app = mock_app_with_balance(balances); @@ -1031,7 +1031,7 @@ fn collect_pools_native_fees_successfully() { decimals: 6, initial_balances: vec![Cw20Coin { address: creator.clone().sender.to_string(), - amount: Uint128::new(1_000_000_000_000u128), + amount: Uint128::new(10_000_000_000_000u128), }], mint: Some(MinterResponse { minter: creator.clone().sender.to_string(), @@ -1116,13 +1116,13 @@ fn collect_pools_native_fees_successfully() { info: AssetInfo::NativeToken { denom: "native".to_string(), }, - amount: Uint128::new(500_000u128), + amount: Uint128::new(5_000_000_000_000u128), }, Asset { info: AssetInfo::Token { contract_addr: cw20_token.to_string(), }, - amount: Uint128::new(500_000u128), + amount: Uint128::new(5_000_000_000_000u128), }, ], slippage_tolerance: None, @@ -1130,7 +1130,7 @@ fn collect_pools_native_fees_successfully() { }, &[Coin { denom: "native".to_string(), - amount: Uint128::new(500_000u128), + amount: Uint128::new(5_000_000_000_000u128), }], ) .unwrap(); @@ -1676,15 +1676,15 @@ fn collect_fees_with_pagination_successfully() { info: AssetInfo::NativeToken { denom: "native".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "native".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -1695,10 +1695,10 @@ fn collect_fees_with_pagination_successfully() { cw20_token.clone(), &Cw20ExecuteMsg::Send { contract: pair_tokens[i].to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }) .unwrap(), @@ -3047,15 +3047,15 @@ fn collect_and_distribute_fees_successfully() { info: AssetInfo::NativeToken { denom: "uwhale".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(30u64)), to: None, }, &[Coin { denom: "uwhale".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -3069,15 +3069,15 @@ fn collect_and_distribute_fees_successfully() { info: AssetInfo::NativeToken { denom: native_token.clone().to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: native_token.clone().to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -4419,15 +4419,15 @@ fn collect_and_distribute_fees_with_expiring_epoch_successfully() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(30u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -4473,15 +4473,15 @@ fn collect_and_distribute_fees_with_expiring_epoch_successfully() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(30u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -5670,15 +5670,15 @@ fn create_epoch_unsuccessfully() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -5713,15 +5713,15 @@ fn create_epoch_unsuccessfully() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -6116,15 +6116,15 @@ fn decrease_grace_period_fee_distributor() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -6155,15 +6155,15 @@ fn decrease_grace_period_fee_distributor() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -6545,15 +6545,15 @@ fn users_cannot_claim_rewards_from_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -6598,15 +6598,15 @@ fn users_cannot_claim_rewards_from_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -6680,15 +6680,15 @@ fn users_cannot_claim_rewards_from_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7105,15 +7105,15 @@ fn user_can_claim_even_when_his_weight_increases_for_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7158,15 +7158,15 @@ fn user_can_claim_even_when_his_weight_increases_for_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7306,15 +7306,15 @@ fn user_can_claim_even_when_his_weight_increases_for_past_epochs() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7759,15 +7759,15 @@ fn user_weight_accounts_for_unbondings() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7812,15 +7812,15 @@ fn user_weight_accounts_for_unbondings() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -7960,15 +7960,15 @@ fn user_weight_accounts_for_unbondings() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -8048,7 +8048,7 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::new(161u128) + amount: Uint128::new(1324u128) }] ); assert_eq!( @@ -8057,7 +8057,7 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::new(161u128) + amount: Uint128::new(1323u128) }] ); @@ -8070,7 +8070,7 @@ fn user_weight_accounts_for_unbondings() { ) .unwrap(); - let epoch_res: EpochResponse = app + let mut epoch_res: EpochResponse = app .wrap() .query_wasm_smart( fee_distributor_address.clone(), @@ -8087,7 +8087,7 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::zero() + amount: Uint128::one() }] ); assert_eq!( @@ -8096,10 +8096,15 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::new(322u128) + amount: Uint128::new(2646u128) }] ); - assert_eq!(epoch_res.epoch.claimed, epoch_res.epoch.total); + assert!( + (epoch_res.epoch.claimed.first().unwrap().amount.u128() as i128 + - epoch_res.epoch.total.first().unwrap().amount.u128() as i128) + .abs() + < 2i128 + ); //now unbond partially, check if weight is computed correctly app.execute_contract( @@ -8129,15 +8134,15 @@ fn user_weight_accounts_for_unbondings() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -8196,7 +8201,7 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::new(112u128) + amount: Uint128::new(1242u128) }] ); assert_eq!( @@ -8205,7 +8210,7 @@ fn user_weight_accounts_for_unbondings() { info: NativeToken { denom: "uwhale".to_string() }, - amount: Uint128::new(55u128) + amount: Uint128::new(620u128) }] ); } @@ -8555,15 +8560,15 @@ fn users_can_claim_even_when_global_index_was_taken_after_epoch_was_created() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); @@ -8614,15 +8619,15 @@ fn users_can_claim_even_when_global_index_was_taken_after_epoch_was_created() { info: AssetInfo::NativeToken { denom: "usdc".to_string(), }, - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(40u64)), to: None, }, &[Coin { denom: "usdc".to_string(), - amount: Uint128::new(200_000_000u128), + amount: Uint128::new(200_000u128), }], ) .unwrap(); diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml b/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml index 981c8641..85a07dee 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stableswap-3pool" -version = "1.2.1" +version = "1.2.2" authors = [ "Adam J. Weigold ", ] diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs index 709f294c..d2feb158 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs @@ -472,15 +472,18 @@ pub fn swap( amount: swap_computation.return_amount, }; + let fees = swap_computation + .swap_fee_amount + .checked_add(swap_computation.protocol_fee_amount)? + .checked_add(swap_computation.burn_fee_amount)?; + // check max spread limit if exist helpers::assert_max_spread( belief_price, max_spread, - offer_asset.clone(), - return_asset.clone(), + offer_asset.amount, + return_asset.amount.checked_add(fees)?, swap_computation.spread_amount, - offer_decimal, - ask_decimal, )?; let receiver = to.unwrap_or_else(|| sender.clone()); diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs index 7dd3cc24..14643e31 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs @@ -1,9 +1,10 @@ use std::cmp::Ordering; +use std::str::FromStr; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, Deps, DepsMut, Env, ReplyOn, Response, StdError, StdResult, - Storage, SubMsg, Uint128, Uint256, WasmMsg, + to_binary, Decimal, Decimal256, Deps, DepsMut, Env, Fraction, ReplyOn, Response, StdError, + StdResult, Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; @@ -127,77 +128,53 @@ pub struct OfferAmountComputation { pub burn_fee_amount: Uint128, } +/// Default swap slippage in case max_spread is not specified +pub const DEFAULT_SLIPPAGE: &str = "0.01"; +/// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will +/// be capped to this value. +pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; + /// If `belief_price` and `max_spread` both are given, -/// we compute new spread else we just use terraswap +/// we compute new spread else we just use pool network /// spread to check `max_spread` pub fn assert_max_spread( belief_price: Option, max_spread: Option, - offer_asset: Asset, - return_asset: Asset, + offer_amount: Uint128, + return_amount: Uint128, spread_amount: Uint128, - offer_decimal: u8, - return_decimal: u8, ) -> Result<(), ContractError> { - let (offer_amount, return_amount, spread_amount): (Uint256, Uint256, Uint256) = - match offer_decimal.cmp(&return_decimal) { - Ordering::Greater => { - let diff_decimal = 10u64.pow((offer_decimal - return_decimal).into()); - - ( - offer_asset.amount.into(), - return_asset - .amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - spread_amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - ) - } - Ordering::Less => { - let diff_decimal = 10u64.pow((return_decimal - offer_decimal).into()); - - ( - offer_asset - .amount - .checked_mul(Uint128::from(diff_decimal))? - .into(), - return_asset.amount.into(), - spread_amount.into(), - ) - } - Ordering::Equal => ( - offer_asset.amount.into(), - return_asset.amount.into(), - spread_amount.into(), - ), - }; - - if let (Some(max_spread), Some(belief_price)) = (max_spread, belief_price) { - let belief_price: Decimal256 = belief_price.into(); - let max_spread: Decimal256 = max_spread.into(); - if max_spread > Decimal256::one() { - return Err(StdError::generic_err("max spread cannot bigger than 1").into()); - } - - let expected_return = offer_amount * (Decimal256::one() / belief_price); - let spread_amount = if expected_return > return_amount { - expected_return - return_amount - } else { - Uint256::zero() - }; + println!("assert_max_spread: belief_price: {:?}, max_spread: {:?}, offer_amount: {:?}, return_amount: {:?}, spread_amount: {:?}", belief_price, max_spread, offer_amount, return_amount, spread_amount); + + let max_spread: Decimal256 = max_spread + .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) + .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) + .into(); + + println!("max_spread: {:?}", max_spread); + println!( + "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) {:?}", + Decimal256::from_ratio(spread_amount, return_amount + spread_amount) + ); + println!( + "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread: {:?}", + Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread + ); + + if let Some(belief_price) = belief_price { + let expected_return = offer_amount + * belief_price + .inv() + .ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?; + let spread_amount = expected_return.saturating_sub(return_amount); if return_amount < expected_return && Decimal256::from_ratio(spread_amount, expected_return) > max_spread { return Err(ContractError::MaxSpreadAssertion {}); } - } else if let Some(max_spread) = max_spread { - let max_spread: Decimal256 = max_spread.into(); - if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { - return Err(ContractError::MaxSpreadAssertion {}); - } + } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { + return Err(ContractError::MaxSpreadAssertion {}); } Ok(()) diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs index 58c1786c..334fe0ee 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs @@ -495,175 +495,120 @@ fn can_migrate_contract() { #[test] fn test_max_spread() { - let offer_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; - let ask_asset_info = AssetInfo::NativeToken { - denom: "ask_asset_info".to_string(), - }; - assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(989999u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(989_999u128), Uint128::zero(), - 6u8, - 6u8, ) .unwrap_err(); + // same example as above but using 6 and 18 decimal places assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio( + 1200_000_000u128, + 1_000_000_000_000_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(990000u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(989_999_900_000_000_000u128), + Uint128::zero(), + ) + .unwrap_err(); + + assert_max_spread( + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + None, // defaults to 0.5% + Uint128::from(1200_000_000u128), + Uint128::from(995_000u128), // all good Uint128::zero(), - 6u8, - 6u8, ) .unwrap(); assert_max_spread( - None, - Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::zero(), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(989999u128), - }, - Uint128::from(10001u128), - 6u8, - 6u8, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + None, // defaults to 0.1% + Uint128::from(1200_000_000u128), + Uint128::from(989_000u128), // fails + Uint128::zero(), ) .unwrap_err(); assert_max_spread( - None, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::zero(), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(990000u128), - }, - Uint128::from(10000u128), - 6u8, - 6u8, + Uint128::from(1200_000_000u128), + Uint128::from(990_000u128), + Uint128::zero(), ) .unwrap(); -} - -#[test] -fn test_max_spread_with_diff_decimal() { - let token_addr = "ask_asset_info".to_string(); - - let mut deps = mock_dependencies(&[]); - deps.querier.with_token_balances(&[( - &token_addr, - &[( - &MOCK_CONTRACT_ADDR.to_string(), - &Uint128::from(10000000000u64), - )], - )]); - let offer_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; - let ask_asset_info = AssetInfo::Token { - contract_addr: token_addr.to_string(), - }; + // same example as above but using 6 and 18 decimal place assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio( + 1200_000_000u128, + 1_000_000_000_000_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(100000000u128), - }, + Uint128::from(1200_000_000u128), + Uint128::from(990_000__000_000_000_000u128), Uint128::zero(), - 6u8, - 8u8, ) .unwrap(); + // similar example with 18 and 6 decimal places assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + Some(Decimal::from_ratio( + 1_000_000_000_000_000_000u128, + 10_000_000u128, + )), + Some(Decimal::percent(2)), + Uint128::from(1_000_000_000_000_000_000u128), + Uint128::from(9_800_000u128), + Uint128::zero(), + ) + .unwrap(); + + // same as before but error because spread is 1% + assert_max_spread( + Some(Decimal::from_ratio( + 1_000_000_000_000_000_000u128, + 10_000_000u128, + )), Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::from(1200000000u128), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(98999999u128), - }, + Uint128::from(1_000_000_000_000_000_000u128), + Uint128::from(9_800_000u128), Uint128::zero(), - 6u8, - 8u8, ) .unwrap_err(); - let offer_asset_info = AssetInfo::Token { - contract_addr: token_addr, - }; - let ask_asset_info = AssetInfo::NativeToken { - denom: "offer_asset".to_string(), - }; + assert_max_spread( + None, + Some(Decimal::percent(1)), + Uint128::zero(), + Uint128::from(989_999u128), + Uint128::from(10001u128), + ) + .unwrap_err(); assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), + None, Some(Decimal::percent(1)), - Asset { - info: offer_asset_info.clone(), - amount: Uint128::from(120000000000u128), - }, - Asset { - info: ask_asset_info.clone(), - amount: Uint128::from(1000000u128), - }, Uint128::zero(), - 8u8, - 6u8, + Uint128::from(990_000u128), + Uint128::from(10000u128), ) .unwrap(); assert_max_spread( - Some(Decimal::from_ratio(1200u128, 1u128)), - Some(Decimal::percent(1)), - Asset { - info: offer_asset_info, - amount: Uint128::from(120000000000u128), - }, - Asset { - info: ask_asset_info, - amount: Uint128::from(989999u128), - }, + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + Some(Decimal::percent(60)), // this will default to 50% + Uint128::from(1200_000_000u128), + Uint128::from(989_999u128), Uint128::zero(), - 8u8, - 6u8, ) - .unwrap_err(); + .unwrap(); } #[test] diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml b/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml index c498ea4a..4f1f403d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-pair" -version = "1.3.1" +version = "1.3.2" authors = [ "Terraform Labs, PTE.", "DELIGHT LABS", diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs index 806c8cbf..b637ed7d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs @@ -407,8 +407,8 @@ pub fn swap( .swap_fee_amount .checked_add(swap_computation.protocol_fee_amount)? .checked_add(swap_computation.burn_fee_amount)?; - // check max spread limit if exist + // check max spread limit if exist helpers::assert_max_spread( belief_price, max_spread, diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs index 480a1376..6092e0d9 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs @@ -1,4 +1,3 @@ -use std::cmp::Ordering; use std::ops::Mul; use std::str::FromStr; @@ -324,7 +323,7 @@ pub struct OfferAmountComputation { } /// Default swap slippage in case max_spread is not specified -pub const DEFAULT_SLIPPAGE: &str = "0.005"; +pub const DEFAULT_SLIPPAGE: &str = "0.01"; /// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will /// be capped to this value. pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; @@ -339,11 +338,23 @@ pub fn assert_max_spread( return_amount: Uint128, spread_amount: Uint128, ) -> Result<(), ContractError> { + println!("assert_max_spread: belief_price: {:?}, max_spread: {:?}, offer_amount: {:?}, return_amount: {:?}, spread_amount: {:?}", belief_price, max_spread, offer_amount, return_amount, spread_amount); + let max_spread: Decimal256 = max_spread .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) .into(); + println!("max_spread: {:?}", max_spread); + println!( + "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) {:?}", + Decimal256::from_ratio(spread_amount, return_amount + spread_amount) + ); + println!( + "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread: {:?}", + Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread + ); + if let Some(belief_price) = belief_price { let expected_return = offer_amount * belief_price diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs index 35e0c121..a979de45 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs @@ -14,9 +14,9 @@ use white_whale::pool_network::pair::{Cw20HookMsg, ExecuteMsg, InstantiateMsg, P #[test] fn test_protocol_fees() { - let total_share = Uint128::from(30_000_000_000u128); - let asset_pool_amount = Uint128::from(20_000_000_000u128); - let collateral_pool_amount = Uint128::from(30_000_000_000u128); + let total_share = Uint128::from(300_000_000_000u128); + let asset_pool_amount = Uint128::from(200_000_000_000u128); + let collateral_pool_amount = Uint128::from(300_000_000_000u128); let offer_amount = Uint128::from(1_500_000_000u128); let mut deps = mock_dependencies(&[Coin { @@ -107,8 +107,8 @@ fn test_protocol_fees() { execute(deps.as_mut(), env, info, msg).unwrap(); // ask_amount = ((ask_pool - accrued protocol fees) * offer_amount / (offer_pool - accrued protocol fees + offer_amount)) - // 952.380952 = (20000 - 0) * 1500 / (30000 - 0 + 1500) - swap_fee - protocol_fee - let expected_ret_amount = Uint128::from(952_380_952u128); + // 995.024875 = (200000 - 0) * 1500 / (300000 - 0 + 1500) - swap_fee - protocol_fee + let expected_ret_amount = Uint128::from(995_024_875u128); let expected_protocol_fee_amount = expected_ret_amount.multiply_ratio(1u128, 1000u128); // 0.1% // as we swapped native to token, we accumulate the protocol fees in token. Native token fees should be 0 @@ -162,8 +162,8 @@ fn test_protocol_fees() { execute(deps.as_mut(), env, info, msg).unwrap(); // ask_amount = ((ask_pool - accrued protocol fees) * offer_amount / (offer_pool - accrued protocol fees + offer_amount)) - // 952.335600 = (20000 - 0.952380 ) * 1500 / (30000 - 0 + 1500) - swap_fee - protocol_fee - let expected_ret_amount = Uint128::from(952_335_600u128); + // 995.019925 = (200000 - 0.995024 ) * 1500 / (300000 - 0 + 1500) - swap_fee - protocol_fee + let expected_ret_amount = Uint128::from(995_019_925u128); let new_expected_protocol_fee_amount = expected_ret_amount.multiply_ratio(1u128, 1000u128); // 0.1% // the new protocol fees should have increased from the previous time @@ -198,9 +198,9 @@ fn test_protocol_fees() { #[test] fn test_collect_protocol_fees_successful() { - let total_share = Uint128::from(30_000_000_000u128); - let asset_pool_amount = Uint128::from(20_000_000_000u128); - let collateral_pool_amount = Uint128::from(30_000_000_000u128); + let total_share = Uint128::from(300_000_000_000u128); + let asset_pool_amount = Uint128::from(200_000_000_000u128); + let collateral_pool_amount = Uint128::from(300_000_000_000u128); let offer_amount = Uint128::from(1_500_000_000u128); let mut deps = mock_dependencies(&[Coin { @@ -291,8 +291,8 @@ fn test_collect_protocol_fees_successful() { execute(deps.as_mut(), env.clone(), info, msg).unwrap(); // ask_amount = ((ask_pool - accrued protocol fees) * offer_amount / (offer_pool - accrued protocol fees + offer_amount)) - // 952.380952 = (20000 - 0) * 1500 / (30000 - 0 + 1500) - swap_fee - protocol_fee - let expected_ret_amount = Uint128::from(952_380_952u128); + // 995.024875 = (200000 - 0) * 1500 / (300000 - 0 + 1500) - swap_fee - protocol_fee + let expected_ret_amount = Uint128::from(995_024_875u128); let expected_protocol_fee_token_amount = expected_ret_amount.multiply_ratio(1u128, 1000u128); // 0.001% // second swap, token -> native @@ -310,8 +310,8 @@ fn test_collect_protocol_fees_successful() { execute(deps.as_mut(), env.clone(), info, msg).unwrap(); // ask_amount = ((ask_pool - accrued protocol fees) * offer_amount / (offer_pool - accrued protocol fees + offer_amount)) - // 2362.612505 = (31500 - 0) * 1500 / (18500 - 0.952380 + 1500) - swap_fee - protocol_fee - let expected_ret_amount = Uint128::from(2_362_612_505u128); + // 2261.261505 = (301500 - 0) * 1500 / (18500 - 0.995024 + 1500) - swap_fee - protocol_fee + let expected_ret_amount = Uint128::from(2_261_261_505u128); let expected_protocol_fee_native_amount = expected_ret_amount.multiply_ratio(1u128, 1000u128); // 0.001% // as we swapped both native and token, we should have collected fees in both of them @@ -426,10 +426,10 @@ fn test_collect_protocol_fees_successful() { #[test] fn test_collect_protocol_fees_successful_1_fee_only() { - let total_share = Uint128::from(30_000_000_000u128); - let asset_pool_amount = Uint128::from(20_000_000_000u128); - let collateral_pool_amount = Uint128::from(30_000_000_000u128); - let offer_amount = Uint128::from(1_500_000_000u128); + let total_share = Uint128::from(300_000_000_000u128); + let asset_pool_amount = Uint128::from(200_000_000_000u128); + let collateral_pool_amount = Uint128::from(300_000_000_000u128); + let offer_amount = Uint128::from(1_500_000u128); let mut deps = mock_dependencies(&[Coin { denom: "uusd".to_string(), @@ -519,8 +519,8 @@ fn test_collect_protocol_fees_successful_1_fee_only() { execute(deps.as_mut(), env.clone(), info, msg).unwrap(); // ask_amount = (ask_pool * offer_amount / (offer_pool + offer_amount)) - // 952.380952 = 20000 * 1500 / (30000 + 1500) - swap_fee - protocol_fee - let expected_ret_amount = Uint128::from(952_380_952u128); + // 9.995002 = 20000 * 15 / (30000 + 15) - swap_fee - protocol_fee + let expected_ret_amount = Uint128::from(999000u128); let expected_protocol_fee_token_amount = expected_ret_amount.multiply_ratio(1u128, 1000u128); // 0.1% // as did only one swap from native -> token, we should have collected fees in token diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs index f78f6d2d..4fa0a0ef 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs @@ -133,7 +133,7 @@ fn try_native_to_token() { amount: offer_amount, }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(5u64)), to: None, }; let env = mock_env(); @@ -597,7 +597,7 @@ fn try_token_to_native() { amount: offer_amount, msg: to_binary(&Cw20HookMsg::Swap { belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(5u64)), to: Some("third_party".to_string()), }) .unwrap(), @@ -926,7 +926,7 @@ fn test_swap_to_third_party() { amount: offer_amount, }, belief_price: None, - max_spread: None, + max_spread: Some(Decimal::percent(5u64)), to: Some("third_party".to_string()), }; let env = mock_env(); diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs index 1d25ff70..71fe8723 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs @@ -345,7 +345,6 @@ fn test_initialization_invalid_fees() { _ => panic!("should return StdError::generic_err(Invalid fee)"), } } - #[test] fn test_max_spread() { assert_max_spread( @@ -381,9 +380,9 @@ fn test_max_spread() { assert_max_spread( Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), - None, // defaults to 0.5% + None, // defaults to 0.1% Uint128::from(1200_000_000u128), - Uint128::from(990_000u128), // fails + Uint128::from(989_000u128), // fails Uint128::zero(), ) .unwrap_err(); @@ -463,7 +462,6 @@ fn test_max_spread() { ) .unwrap(); } - #[test] fn test_update_config_unsuccessful() { let mut deps = mock_dependencies(&[]); diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml b/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml index 27aa00f9..042bd53c 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-router" -version = "1.1.0" +version = "1.1.1" authors = [ "Terraform Labs, PTE.", "DELIGHT LABS", diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs index 404dd0e2..27724aaf 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - attr, from_binary, to_binary, Addr, Api, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, - Order, Response, StdError, StdResult, Uint128, WasmMsg, + attr, from_binary, to_binary, Addr, Api, Binary, CosmosMsg, Decimal, Deps, DepsMut, Env, + MessageInfo, Order, Response, StdError, StdResult, Uint128, WasmMsg, }; use cw2::{get_contract_version, set_contract_version}; use cw20::Cw20ReceiveMsg; @@ -59,6 +59,7 @@ pub fn execute( operations, minimum_receive, to, + max_spread, } => { let api = deps.api; execute_swap_operations( @@ -68,9 +69,14 @@ pub fn execute( operations, minimum_receive, optional_addr_validate(api, to)?, + max_spread, ) } - ExecuteMsg::ExecuteSwapOperation { operation, to } => { + ExecuteMsg::ExecuteSwapOperation { + operation, + to, + max_spread, + } => { let api = deps.api; execute_swap_operation( deps, @@ -78,6 +84,7 @@ pub fn execute( info, operation, optional_addr_validate(api, to)?.map(|v| v.to_string()), + max_spread, ) } ExecuteMsg::AssertMinimumReceive { @@ -123,6 +130,7 @@ pub fn receive_cw20( operations, minimum_receive, to, + max_spread, } => { let api = deps.api; execute_swap_operations( @@ -132,6 +140,7 @@ pub fn receive_cw20( operations, minimum_receive, optional_addr_validate(api, to)?, + max_spread, ) } } @@ -144,6 +153,7 @@ pub fn execute_swap_operations( operations: Vec, minimum_receive: Option, to: Option, + max_spread: Option, ) -> Result { let operations_len = operations.len(); if operations_len == 0 { @@ -174,6 +184,7 @@ pub fn execute_swap_operations( } else { None }, + max_spread, })?, })) }) diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs index c64b835f..804b8df0 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs @@ -20,6 +20,7 @@ pub fn execute_swap_operation( info: MessageInfo, operation: SwapOperation, to: Option, + max_spread: Option, ) -> Result { if env.contract.address != info.sender { return Err(ContractError::Unauthorized {}); @@ -57,7 +58,7 @@ pub fn execute_swap_operation( deps.as_ref(), Addr::unchecked(pair_info.contract_addr), offer_asset, - None, + max_spread, to, )?] } diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs index ecc84858..41728fec 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs @@ -1,6 +1,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, coin, from_binary, to_binary, Addr, Coin, CosmosMsg, StdError, SubMsg, Uint128, WasmMsg, + attr, coin, from_binary, to_binary, Addr, Coin, CosmosMsg, Decimal, StdError, SubMsg, Uint128, + WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use white_whale::pool_network; @@ -58,6 +59,7 @@ fn execute_swap_operations() { operations: vec![], minimum_receive: None, to: None, + max_spread: None, }; let info = mock_info("addr0000", &[]); @@ -99,6 +101,7 @@ fn execute_swap_operations() { ], minimum_receive: Some(Uint128::from(1000000u128)), to: None, + max_spread: None, }; let info = mock_info("addr0000", &[]); @@ -119,6 +122,7 @@ fn execute_swap_operations() { }, }, to: None, + max_spread: None, }) .unwrap(), })), @@ -135,6 +139,7 @@ fn execute_swap_operations() { }, }, to: None, + max_spread: None, }) .unwrap(), })), @@ -151,6 +156,7 @@ fn execute_swap_operations() { }, }, to: Some("addr0000".to_string()), + max_spread: None, }) .unwrap(), })), @@ -202,6 +208,7 @@ fn execute_swap_operations() { ], minimum_receive: None, to: Some("addr0002".to_string()), + max_spread: None, }) .unwrap(), }); @@ -224,6 +231,7 @@ fn execute_swap_operations() { }, }, to: None, + max_spread: None, }) .unwrap(), })), @@ -240,6 +248,7 @@ fn execute_swap_operations() { }, }, to: None, + max_spread: None, }) .unwrap(), })), @@ -256,6 +265,7 @@ fn execute_swap_operations() { }, }, to: Some("addr0002".to_string()), + max_spread: None, }) .unwrap(), })), @@ -316,6 +326,7 @@ fn execute_swap_operation() { }, }, to: None, + max_spread: None, }; let info = mock_info("addr0000", &[]); let res = execute(deps.as_mut(), mock_env(), info, msg.clone()); @@ -357,6 +368,7 @@ fn execute_swap_operation() { }, }, to: Some("addr0000".to_string()), + max_spread: None, }; let info = mock_info(MOCK_CONTRACT_ADDR, &[]); let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); @@ -415,6 +427,7 @@ fn execute_swap_operation() { }, }, to: Some("addr0000".to_string()), + max_spread: None, }; let info = mock_info(MOCK_CONTRACT_ADDR, &[]); @@ -661,6 +674,7 @@ fn query_reverse_routes_with_from_native() { }, }, to: None, + max_spread: None, }; let info = mock_info("addr0", &[coin(offer_amount.u128(), "ukrw")]); let res = execute(deps.as_mut(), mock_env(), info, msg.clone()); @@ -801,6 +815,7 @@ fn query_reverse_routes_with_to_native() { }], minimum_receive: None, to: None, + max_spread: None, }) .unwrap(), }); @@ -822,6 +837,7 @@ fn query_reverse_routes_with_to_native() { }, }, to: Some("addr0".to_string()), + max_spread: None, }) .unwrap(), })),], @@ -837,6 +853,7 @@ fn query_reverse_routes_with_to_native() { }, }, to: None, + max_spread: None, }; let info = mock_info(MOCK_CONTRACT_ADDR, &[]); diff --git a/packages/white-whale/src/pool_network/router.rs b/packages/white-whale/src/pool_network/router.rs index 49572f2d..20ab68e6 100644 --- a/packages/white-whale/src/pool_network/router.rs +++ b/packages/white-whale/src/pool_network/router.rs @@ -1,7 +1,7 @@ use std::fmt; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::Uint128; +use cosmwasm_std::{Decimal, Uint128}; use cw20::Cw20ReceiveMsg; use crate::pool_network::asset::AssetInfo; @@ -74,11 +74,13 @@ pub enum ExecuteMsg { operations: Vec, minimum_receive: Option, to: Option, + max_spread: Option, }, /// Swap the offer to ask token. This message can only be called internally by the router contract. ExecuteSwapOperation { operation: SwapOperation, to: Option, + max_spread: Option, }, /// Checks if the swap amount exceeds the minimum_receive. This message can only be called /// internally by the router contract. @@ -100,6 +102,7 @@ pub enum Cw20HookMsg { operations: Vec, minimum_receive: Option, to: Option, + max_spread: Option, }, } From 50b8c5d1e66a6c342913fd7211a4ef59102f32b0 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Fri, 20 Oct 2023 10:32:29 +0100 Subject: [PATCH 3/4] chore: cleanup --- .../fee_collector/src/tests/integration.rs | 2 +- .../stableswap_3pool/src/commands.rs | 23 +- .../stableswap_3pool/src/error.rs | 3 - .../stableswap_3pool/src/helpers.rs | 60 +- .../stableswap_3pool/src/tests/testing.rs | 3 +- .../terraswap_pair/src/commands.rs | 4 +- .../pool-network/terraswap_pair/src/error.rs | 3 - .../terraswap_pair/src/helpers.rs | 57 +- .../terraswap_pair/src/tests/testing.rs | 3 +- .../terraswap_router/schema/raw/execute.json | 24 + .../schema/terraswap-router.json | 24 + .../terraswap_router/src/testing/tests.rs | 3 +- .../vault-manager/schema/raw/execute.json | 1310 --------- .../vault-manager/schema/raw/instantiate.json | 133 - .../vault-manager/schema/raw/query.json | 205 -- .../schema/raw/response_to_config.json | 151 -- .../schema/raw/response_to_ownership.json | 95 - .../raw/response_to_payback_amount.json | 100 - .../schema/raw/response_to_share.json | 89 - .../schema/raw/response_to_vault.json | 135 - .../schema/raw/response_to_vaults.json | 135 - .../vault-manager/schema/vault-manager.json | 2362 ----------------- packages/white-whale/src/pool_network/mod.rs | 1 + packages/white-whale/src/pool_network/swap.rs | 42 + 24 files changed, 105 insertions(+), 4862 deletions(-) delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/execute.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/query.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json delete mode 100644 contracts/liquidity_hub/vault-manager/schema/vault-manager.json create mode 100644 packages/white-whale/src/pool_network/swap.rs diff --git a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs index 030e1bb8..fdb11861 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs @@ -8070,7 +8070,7 @@ fn user_weight_accounts_for_unbondings() { ) .unwrap(); - let mut epoch_res: EpochResponse = app + let epoch_res: EpochResponse = app .wrap() .query_wasm_smart( fee_distributor_address.clone(), diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs index d2feb158..bced40b2 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs @@ -16,6 +16,7 @@ use white_whale::pool_network::asset::{ use white_whale::pool_network::denom::{Coin, MsgBurn, MsgMint}; #[cfg(feature = "osmosis_token_factory")] use white_whale::pool_network::denom_osmosis::{Coin, MsgBurn, MsgMint}; +use white_whale::pool_network::swap; use white_whale::pool_network::trio::{Config, Cw20HookMsg, FeatureToggle, PoolFee, RampAmp}; use crate::error::ContractError; @@ -387,24 +388,16 @@ pub fn swap( let ask_pool: Asset; let offer_pool: Asset; let unswapped_pool: Asset; - let ask_decimal: u8; - let offer_decimal: u8; if ask_asset.equal(&pools[0].info) { if offer_asset.info.equal(&pools[1].info) { ask_pool = pools[0].clone(); offer_pool = pools[1].clone(); unswapped_pool = pools[2].clone(); - - ask_decimal = trio_info.asset_decimals[0]; - offer_decimal = trio_info.asset_decimals[1]; } else if offer_asset.info.equal(&pools[2].info) { ask_pool = pools[0].clone(); offer_pool = pools[2].clone(); unswapped_pool = pools[1].clone(); - - ask_decimal = trio_info.asset_decimals[0]; - offer_decimal = trio_info.asset_decimals[2]; } else { return Err(ContractError::AssetMismatch {}); } @@ -413,16 +406,10 @@ pub fn swap( ask_pool = pools[1].clone(); offer_pool = pools[0].clone(); unswapped_pool = pools[2].clone(); - - ask_decimal = trio_info.asset_decimals[1]; - offer_decimal = trio_info.asset_decimals[0]; } else if offer_asset.info.equal(&pools[2].info) { ask_pool = pools[1].clone(); offer_pool = pools[2].clone(); unswapped_pool = pools[0].clone(); - - ask_decimal = trio_info.asset_decimals[1]; - offer_decimal = trio_info.asset_decimals[2]; } else { return Err(ContractError::AssetMismatch {}); } @@ -431,16 +418,10 @@ pub fn swap( ask_pool = pools[2].clone(); offer_pool = pools[0].clone(); unswapped_pool = pools[1].clone(); - - ask_decimal = trio_info.asset_decimals[2]; - offer_decimal = trio_info.asset_decimals[0]; } else if offer_asset.info.equal(&pools[1].info) { ask_pool = pools[2].clone(); offer_pool = pools[1].clone(); unswapped_pool = pools[0].clone(); - - ask_decimal = trio_info.asset_decimals[2]; - offer_decimal = trio_info.asset_decimals[1]; } else { return Err(ContractError::AssetMismatch {}); } @@ -478,7 +459,7 @@ pub fn swap( .checked_add(swap_computation.burn_fee_amount)?; // check max spread limit if exist - helpers::assert_max_spread( + swap::assert_max_spread( belief_price, max_spread, offer_asset.amount, diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/error.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/error.rs index 6b6e4926..7a93ab0e 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/error.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/error.rs @@ -19,9 +19,6 @@ pub enum ContractError { #[error("Invalid zero amount")] InvalidZeroAmount {}, - #[error("Spread limit exceeded")] - MaxSpreadAssertion {}, - #[error("Slippage tolerance exceeded")] MaxSlippageAssertion {}, diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs index 14643e31..9c4674fa 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs @@ -1,10 +1,7 @@ -use std::cmp::Ordering; -use std::str::FromStr; - use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, Deps, DepsMut, Env, Fraction, ReplyOn, Response, StdError, - StdResult, Storage, SubMsg, Uint128, Uint256, WasmMsg, + to_binary, Decimal, Decimal256, Deps, DepsMut, Env, ReplyOn, Response, StdError, StdResult, + Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; @@ -127,59 +124,6 @@ pub struct OfferAmountComputation { pub protocol_fee_amount: Uint128, pub burn_fee_amount: Uint128, } - -/// Default swap slippage in case max_spread is not specified -pub const DEFAULT_SLIPPAGE: &str = "0.01"; -/// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will -/// be capped to this value. -pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; - -/// If `belief_price` and `max_spread` both are given, -/// we compute new spread else we just use pool network -/// spread to check `max_spread` -pub fn assert_max_spread( - belief_price: Option, - max_spread: Option, - offer_amount: Uint128, - return_amount: Uint128, - spread_amount: Uint128, -) -> Result<(), ContractError> { - println!("assert_max_spread: belief_price: {:?}, max_spread: {:?}, offer_amount: {:?}, return_amount: {:?}, spread_amount: {:?}", belief_price, max_spread, offer_amount, return_amount, spread_amount); - - let max_spread: Decimal256 = max_spread - .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) - .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) - .into(); - - println!("max_spread: {:?}", max_spread); - println!( - "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) {:?}", - Decimal256::from_ratio(spread_amount, return_amount + spread_amount) - ); - println!( - "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread: {:?}", - Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread - ); - - if let Some(belief_price) = belief_price { - let expected_return = offer_amount - * belief_price - .inv() - .ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?; - let spread_amount = expected_return.saturating_sub(return_amount); - - if return_amount < expected_return - && Decimal256::from_ratio(spread_amount, expected_return) > max_spread - { - return Err(ContractError::MaxSpreadAssertion {}); - } - } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { - return Err(ContractError::MaxSpreadAssertion {}); - } - - Ok(()) -} - pub fn assert_slippage_tolerance( slippage_tolerance: &Option, deposits: &[Uint128; 3], diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs index 334fe0ee..6b718104 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs @@ -14,13 +14,14 @@ use white_whale::pool_network::asset::{Asset, AssetInfo, TrioInfo}; #[cfg(feature = "token_factory")] use white_whale::pool_network::denom::MsgCreateDenom; use white_whale::pool_network::mock_querier::mock_dependencies; +use white_whale::pool_network::swap::assert_max_spread; use white_whale::pool_network::token::InstantiateMsg as TokenInstantiateMsg; use white_whale::pool_network::trio::ExecuteMsg::UpdateConfig; use white_whale::pool_network::trio::{Config, InstantiateMsg, MigrateMsg, PoolFee, QueryMsg}; use crate::contract::{execute, instantiate, migrate, query, reply}; use crate::error::ContractError; -use crate::helpers::{assert_max_spread, assert_slippage_tolerance}; +use crate::helpers::assert_slippage_tolerance; use crate::queries::query_trio_info; #[test] diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs index b637ed7d..afb99946 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs @@ -17,7 +17,7 @@ use white_whale::pool_network::denom::{Coin, MsgBurn, MsgMint}; #[cfg(feature = "osmosis_token_factory")] use white_whale::pool_network::denom_osmosis::{Coin, MsgBurn, MsgMint}; use white_whale::pool_network::pair::{Config, Cw20HookMsg, FeatureToggle, PoolFee}; -use white_whale::pool_network::U256; +use white_whale::pool_network::{swap, U256}; use crate::error::ContractError; use crate::helpers; @@ -409,7 +409,7 @@ pub fn swap( .checked_add(swap_computation.burn_fee_amount)?; // check max spread limit if exist - helpers::assert_max_spread( + swap::assert_max_spread( belief_price, max_spread, offer_asset.amount, diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/error.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/error.rs index d6a7ae01..22a97034 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/error.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/error.rs @@ -34,9 +34,6 @@ pub enum ContractError { #[error("Invalid zero amount")] InvalidZeroAmount {}, - #[error("Spread limit exceeded")] - MaxSpreadAssertion {}, - #[error("Slippage tolerance exceeded")] MaxSlippageAssertion {}, diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs index 6092e0d9..81e49aef 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs @@ -1,12 +1,11 @@ use std::ops::Mul; -use std::str::FromStr; use cosmwasm_schema::cw_serde; #[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))] use cosmwasm_std::CosmosMsg; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, DepsMut, Env, Fraction, ReplyOn, Response, StdError, StdResult, - Storage, SubMsg, Uint128, Uint256, WasmMsg, + to_binary, Decimal, Decimal256, DepsMut, Env, ReplyOn, Response, StdError, StdResult, Storage, + SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; @@ -322,58 +321,6 @@ pub struct OfferAmountComputation { pub burn_fee_amount: Uint128, } -/// Default swap slippage in case max_spread is not specified -pub const DEFAULT_SLIPPAGE: &str = "0.01"; -/// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will -/// be capped to this value. -pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; - -/// If `belief_price` and `max_spread` both are given, -/// we compute new spread else we just use pool network -/// spread to check `max_spread` -pub fn assert_max_spread( - belief_price: Option, - max_spread: Option, - offer_amount: Uint128, - return_amount: Uint128, - spread_amount: Uint128, -) -> Result<(), ContractError> { - println!("assert_max_spread: belief_price: {:?}, max_spread: {:?}, offer_amount: {:?}, return_amount: {:?}, spread_amount: {:?}", belief_price, max_spread, offer_amount, return_amount, spread_amount); - - let max_spread: Decimal256 = max_spread - .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) - .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) - .into(); - - println!("max_spread: {:?}", max_spread); - println!( - "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) {:?}", - Decimal256::from_ratio(spread_amount, return_amount + spread_amount) - ); - println!( - "Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread: {:?}", - Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread - ); - - if let Some(belief_price) = belief_price { - let expected_return = offer_amount - * belief_price - .inv() - .ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?; - let spread_amount = expected_return.saturating_sub(return_amount); - - if return_amount < expected_return - && Decimal256::from_ratio(spread_amount, expected_return) > max_spread - { - return Err(ContractError::MaxSpreadAssertion {}); - } - } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { - return Err(ContractError::MaxSpreadAssertion {}); - } - - Ok(()) -} - pub fn assert_slippage_tolerance( slippage_tolerance: &Option, deposits: &[Uint128; 2], diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs index 71fe8723..8efa2aaa 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs @@ -16,11 +16,12 @@ use white_whale::pool_network::denom::MsgCreateDenom; use white_whale::pool_network::mock_querier::mock_dependencies; use white_whale::pool_network::pair::ExecuteMsg::UpdateConfig; use white_whale::pool_network::pair::{Config, InstantiateMsg, PoolFee, QueryMsg}; +use white_whale::pool_network::swap::assert_max_spread; use white_whale::pool_network::token::InstantiateMsg as TokenInstantiateMsg; use crate::contract::{execute, instantiate, query, reply}; use crate::error::ContractError; -use crate::helpers::{assert_max_spread, assert_slippage_tolerance}; +use crate::helpers::assert_slippage_tolerance; use crate::queries::query_pair_info; #[test] diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/schema/raw/execute.json b/contracts/liquidity_hub/pool-network/terraswap_router/schema/raw/execute.json index 591bb572..12765ff3 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/schema/raw/execute.json +++ b/contracts/liquidity_hub/pool-network/terraswap_router/schema/raw/execute.json @@ -27,6 +27,16 @@ "operations" ], "properties": { + "max_spread": { + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + }, "minimum_receive": { "anyOf": [ { @@ -68,6 +78,16 @@ "operation" ], "properties": { + "max_spread": { + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + }, "operation": { "$ref": "#/definitions/SwapOperation" }, @@ -216,6 +236,10 @@ }, "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" + }, "SwapOperation": { "oneOf": [ { diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/schema/terraswap-router.json b/contracts/liquidity_hub/pool-network/terraswap_router/schema/terraswap-router.json index 6c8967b8..6e948653 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/schema/terraswap-router.json +++ b/contracts/liquidity_hub/pool-network/terraswap_router/schema/terraswap-router.json @@ -45,6 +45,16 @@ "operations" ], "properties": { + "max_spread": { + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + }, "minimum_receive": { "anyOf": [ { @@ -86,6 +96,16 @@ "operation" ], "properties": { + "max_spread": { + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + }, "operation": { "$ref": "#/definitions/SwapOperation" }, @@ -234,6 +254,10 @@ }, "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" + }, "SwapOperation": { "oneOf": [ { diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs index 41728fec..8222d7eb 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs @@ -1,7 +1,6 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, coin, from_binary, to_binary, Addr, Coin, CosmosMsg, Decimal, StdError, SubMsg, Uint128, - WasmMsg, + attr, coin, from_binary, to_binary, Addr, Coin, CosmosMsg, StdError, SubMsg, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use white_whale::pool_network; diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/execute.json b/contracts/liquidity_hub/vault-manager/schema/raw/execute.json deleted file mode 100644 index e83e325d..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/execute.json +++ /dev/null @@ -1,1310 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ExecuteMsg", - "description": "The execution messages", - "oneOf": [ - { - "description": "Creates a new vault given the asset info the vault should manage deposits and withdrawals for and the fees", - "type": "object", - "required": [ - "create_vault" - ], - "properties": { - "create_vault": { - "type": "object", - "required": [ - "asset_info", - "fees" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - }, - "fees": { - "$ref": "#/definitions/VaultFee" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Removes a vault given its [AssetInfo]", - "type": "object", - "required": [ - "remove_vault" - ], - "properties": { - "remove_vault": { - "type": "object", - "required": [ - "asset_info" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Updates a vault config", - "type": "object", - "required": [ - "update_vault_fees" - ], - "properties": { - "update_vault_fees": { - "type": "object", - "required": [ - "vault_asset_info", - "vault_fee" - ], - "properties": { - "vault_asset_info": { - "$ref": "#/definitions/AssetInfo" - }, - "vault_fee": { - "$ref": "#/definitions/VaultFee" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Updates the configuration of the vault manager. If a field is not specified, it will not be modified.", - "type": "object", - "required": [ - "update_config" - ], - "properties": { - "update_config": { - "type": "object", - "properties": { - "cw20_lp_code_id": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - }, - "deposit_enabled": { - "type": [ - "boolean", - "null" - ] - }, - "flash_loan_enabled": { - "type": [ - "boolean", - "null" - ] - }, - "vault_creation_fee": { - "anyOf": [ - { - "$ref": "#/definitions/Asset" - }, - { - "type": "null" - } - ] - }, - "whale_lair_addr": { - "type": [ - "string", - "null" - ] - }, - "withdraw_enabled": { - "type": [ - "boolean", - "null" - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Deposits a given asset into the vault manager.", - "type": "object", - "required": [ - "deposit" - ], - "properties": { - "deposit": { - "type": "object", - "required": [ - "asset" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Withdraws from the vault manager. Used when the LP token is a token manager token.", - "type": "object", - "required": [ - "withdraw" - ], - "properties": { - "withdraw": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "receive" - ], - "properties": { - "receive": { - "$ref": "#/definitions/Cw20ReceiveMsg" - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the desired `asset` and runs the `payload`, paying the required amount back to the vault after running the messages in the payload, and returning the profit to the sender.", - "type": "object", - "required": [ - "flash_loan" - ], - "properties": { - "flash_loan": { - "type": "object", - "required": [ - "asset", - "payload" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/CosmosMsg_for_Empty" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Callback message for post-processing flash-loans.", - "type": "object", - "required": [ - "callback" - ], - "properties": { - "callback": { - "$ref": "#/definitions/CallbackMsg" - } - }, - "additionalProperties": false - }, - { - "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", - "type": "object", - "required": [ - "update_ownership" - ], - "properties": { - "update_ownership": { - "$ref": "#/definitions/Action" - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Action": { - "description": "Actions that can be taken to alter the contract's ownership", - "oneOf": [ - { - "description": "Propose to transfer the contract's ownership to another account, optionally with an expiry time.\n\nCan only be called by the contract's current owner.\n\nAny existing pending ownership transfer is overwritten.", - "type": "object", - "required": [ - "transfer_ownership" - ], - "properties": { - "transfer_ownership": { - "type": "object", - "required": [ - "new_owner" - ], - "properties": { - "expiry": { - "anyOf": [ - { - "$ref": "#/definitions/Expiration" - }, - { - "type": "null" - } - ] - }, - "new_owner": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Accept the pending ownership transfer.\n\nCan only be called by the pending owner.", - "type": "string", - "enum": [ - "accept_ownership" - ] - }, - { - "description": "Give up the contract's ownership and the possibility of appointing a new owner.\n\nCan only be invoked by the contract's current owner.\n\nAny existing pending ownership transfer is canceled.", - "type": "string", - "enum": [ - "renounce_ownership" - ] - } - ] - }, - "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" - }, - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "BankMsg": { - "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", - "oneOf": [ - { - "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "send" - ], - "properties": { - "send": { - "type": "object", - "required": [ - "amount", - "to_address" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "to_address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", - "type": "object", - "required": [ - "burn" - ], - "properties": { - "burn": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "CallbackMsg": { - "description": "The callback messages available. Only callable by the vault contract itself.", - "oneOf": [ - { - "type": "object", - "required": [ - "after_flashloan" - ], - "properties": { - "after_flashloan": { - "type": "object", - "required": [ - "loan_asset", - "old_asset_balance", - "sender" - ], - "properties": { - "loan_asset": { - "$ref": "#/definitions/Asset" - }, - "old_asset_balance": { - "$ref": "#/definitions/Uint128" - }, - "sender": { - "$ref": "#/definitions/Addr" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "CosmosMsg_for_Empty": { - "oneOf": [ - { - "type": "object", - "required": [ - "bank" - ], - "properties": { - "bank": { - "$ref": "#/definitions/BankMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "custom" - ], - "properties": { - "custom": { - "$ref": "#/definitions/Empty" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "staking" - ], - "properties": { - "staking": { - "$ref": "#/definitions/StakingMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "distribution" - ], - "properties": { - "distribution": { - "$ref": "#/definitions/DistributionMsg" - } - }, - "additionalProperties": false - }, - { - "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", - "type": "object", - "required": [ - "stargate" - ], - "properties": { - "stargate": { - "type": "object", - "required": [ - "type_url", - "value" - ], - "properties": { - "type_url": { - "type": "string" - }, - "value": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "ibc" - ], - "properties": { - "ibc": { - "$ref": "#/definitions/IbcMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "wasm" - ], - "properties": { - "wasm": { - "$ref": "#/definitions/WasmMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "gov" - ], - "properties": { - "gov": { - "$ref": "#/definitions/GovMsg" - } - }, - "additionalProperties": false - } - ] - }, - "Cw20ReceiveMsg": { - "type": "object", - "required": [ - "amount", - "msg", - "sender" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "sender": { - "type": "string" - } - }, - "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" - }, - "DistributionMsg": { - "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "set_withdraw_address" - ], - "properties": { - "set_withdraw_address": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "description": "The `withdraw_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "withdraw_delegator_reward" - ], - "properties": { - "withdraw_delegator_reward": { - "type": "object", - "required": [ - "validator" - ], - "properties": { - "validator": { - "description": "The `validator_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Empty": { - "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", - "type": "object" - }, - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "GovMsg": { - "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", - "oneOf": [ - { - "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", - "type": "object", - "required": [ - "vote" - ], - "properties": { - "vote": { - "type": "object", - "required": [ - "proposal_id", - "vote" - ], - "properties": { - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "vote": { - "description": "The vote option.\n\nThis should be called \"option\" for consistency with Cosmos SDK. Sorry for that. See .", - "allOf": [ - { - "$ref": "#/definitions/VoteOption" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address.", - "type": "object", - "required": [ - "vote_weighted" - ], - "properties": { - "vote_weighted": { - "type": "object", - "required": [ - "options", - "proposal_id" - ], - "properties": { - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/WeightedVoteOption" - } - }, - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - } - ] - }, - "IbcMsg": { - "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", - "oneOf": [ - { - "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", - "type": "object", - "required": [ - "transfer" - ], - "properties": { - "transfer": { - "type": "object", - "required": [ - "amount", - "channel_id", - "timeout", - "to_address" - ], - "properties": { - "amount": { - "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", - "allOf": [ - { - "$ref": "#/definitions/Coin" - } - ] - }, - "channel_id": { - "description": "exisiting channel to send the tokens over", - "type": "string" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - }, - "to_address": { - "description": "address on the remote chain to receive these tokens", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", - "type": "object", - "required": [ - "send_packet" - ], - "properties": { - "send_packet": { - "type": "object", - "required": [ - "channel_id", - "data", - "timeout" - ], - "properties": { - "channel_id": { - "type": "string" - }, - "data": { - "$ref": "#/definitions/Binary" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", - "type": "object", - "required": [ - "close_channel" - ], - "properties": { - "close_channel": { - "type": "object", - "required": [ - "channel_id" - ], - "properties": { - "channel_id": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "IbcTimeout": { - "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", - "type": "object", - "properties": { - "block": { - "anyOf": [ - { - "$ref": "#/definitions/IbcTimeoutBlock" - }, - { - "type": "null" - } - ] - }, - "timestamp": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - } - } - }, - "IbcTimeoutBlock": { - "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", - "type": "object", - "required": [ - "height", - "revision" - ], - "properties": { - "height": { - "description": "block height after which the packet times out. the height within the given revision", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "revision": { - "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "StakingMsg": { - "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "delegate" - ], - "properties": { - "delegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "undelegate" - ], - "properties": { - "undelegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "redelegate" - ], - "properties": { - "redelegate": { - "type": "object", - "required": [ - "amount", - "dst_validator", - "src_validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "dst_validator": { - "type": "string" - }, - "src_validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "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" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - }, - "VoteOption": { - "type": "string", - "enum": [ - "yes", - "no", - "abstain", - "no_with_veto" - ] - }, - "WasmMsg": { - "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", - "oneOf": [ - { - "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "execute" - ], - "properties": { - "execute": { - "type": "object", - "required": [ - "contract_addr", - "funds", - "msg" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "msg": { - "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "instantiate" - ], - "properties": { - "instantiate": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code using a predictable address derivation algorithm implemented in [`cosmwasm_std::instantiate2_address`].\n\nThis is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). `sender` is automatically filled with the current contract's address. `fix_msg` is automatically set to false.", - "type": "object", - "required": [ - "instantiate2" - ], - "properties": { - "instantiate2": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg", - "salt" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "salt": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "migrate" - ], - "properties": { - "migrate": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "new_code_id" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "new_code_id": { - "description": "the code_id of the new logic to place in the given contract", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "update_admin" - ], - "properties": { - "update_admin": { - "type": "object", - "required": [ - "admin", - "contract_addr" - ], - "properties": { - "admin": { - "type": "string" - }, - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "clear_admin" - ], - "properties": { - "clear_admin": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "WeightedVoteOption": { - "type": "object", - "required": [ - "option", - "weight" - ], - "properties": { - "option": { - "$ref": "#/definitions/VoteOption" - }, - "weight": { - "$ref": "#/definitions/Decimal" - } - } - } - } -} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json b/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json deleted file mode 100644 index 1edb0e51..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/instantiate.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "InstantiateMsg", - "description": "The instantiation message", - "type": "object", - "required": [ - "lp_token_type", - "owner", - "vault_creation_fee", - "whale_lair_addr" - ], - "properties": { - "lp_token_type": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "allOf": [ - { - "$ref": "#/definitions/LpTokenType" - } - ] - }, - "owner": { - "description": "The owner of the contract", - "type": "string" - }, - "vault_creation_fee": { - "description": "The fee to create a vault", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - }, - "whale_lair_addr": { - "description": "The whale lair address, where protocol fees are distributed", - "type": "string" - } - }, - "additionalProperties": false, - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "LpTokenType": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "oneOf": [ - { - "type": "string", - "enum": [ - "token_factory" - ] - }, - { - "type": "object", - "required": [ - "cw20" - ], - "properties": { - "cw20": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "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/liquidity_hub/vault-manager/schema/raw/query.json b/contracts/liquidity_hub/vault-manager/schema/raw/query.json deleted file mode 100644 index 092d439c..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/query.json +++ /dev/null @@ -1,205 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "description": "The query messages", - "oneOf": [ - { - "description": "Retrieves the configuration of the manager.", - "type": "object", - "required": [ - "config" - ], - "properties": { - "config": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves a vault given the asset_info.", - "type": "object", - "required": [ - "vault" - ], - "properties": { - "vault": { - "type": "object", - "required": [ - "asset_info" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the addresses for all the vaults.", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "object", - "properties": { - "limit": { - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - }, - "start_after": { - "type": [ - "array", - "null" - ], - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the share of the assets stored in the vault that a given `lp_share` is entitled to.", - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "type": "object", - "required": [ - "lp_share" - ], - "properties": { - "lp_share": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the [`Uint128`] amount that must be sent back to the contract to pay off a loan taken out.", - "type": "object", - "required": [ - "payback_amount" - ], - "properties": { - "payback_amount": { - "type": "object", - "required": [ - "asset" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Query the contract's ownership information", - "type": "object", - "required": [ - "ownership" - ], - "properties": { - "ownership": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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/liquidity_hub/vault-manager/schema/raw/response_to_config.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json deleted file mode 100644 index dcdbe103..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_config.json +++ /dev/null @@ -1,151 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Config", - "description": "Configuration for the contract (manager)", - "type": "object", - "required": [ - "deposit_enabled", - "flash_loan_enabled", - "lp_token_type", - "vault_creation_fee", - "whale_lair_addr", - "withdraw_enabled" - ], - "properties": { - "deposit_enabled": { - "description": "If deposits are enabled", - "type": "boolean" - }, - "flash_loan_enabled": { - "description": "If flash-loans are enabled", - "type": "boolean" - }, - "lp_token_type": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "allOf": [ - { - "$ref": "#/definitions/LpTokenType" - } - ] - }, - "vault_creation_fee": { - "description": "The fee to create a new vault", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - }, - "whale_lair_addr": { - "description": "The whale lair contract address", - "allOf": [ - { - "$ref": "#/definitions/Addr" - } - ] - }, - "withdraw_enabled": { - "description": "If withdrawals are enabled", - "type": "boolean" - } - }, - "additionalProperties": false, - "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" - }, - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "LpTokenType": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "oneOf": [ - { - "type": "string", - "enum": [ - "token_factory" - ] - }, - { - "type": "object", - "required": [ - "cw20" - ], - "properties": { - "cw20": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "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/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json deleted file mode 100644 index afe1713f..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_ownership.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Ownership_for_String", - "description": "The contract's ownership info", - "type": "object", - "properties": { - "owner": { - "description": "The contract's current owner. `None` if the ownership has been renounced.", - "type": [ - "string", - "null" - ] - }, - "pending_expiry": { - "description": "The deadline for the pending owner to accept the ownership. `None` if there isn't a pending ownership transfer, or if a transfer exists and it doesn't have a deadline.", - "anyOf": [ - { - "$ref": "#/definitions/Expiration" - }, - { - "type": "null" - } - ] - }, - "pending_owner": { - "description": "The account who has been proposed to take over the ownership. `None` if there isn't a pending ownership transfer.", - "type": [ - "string", - "null" - ] - } - }, - "additionalProperties": false, - "definitions": { - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json deleted file mode 100644 index fc7261f2..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_payback_amount.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "PaybackAssetResponse", - "description": "Response for the PaybackAmount query. Contains the amount that must be paid back to the contract if taken a flashloan.", - "type": "object", - "required": [ - "asset_info", - "flash_loan_fee", - "payback_amount", - "protocol_fee" - ], - "properties": { - "asset_info": { - "description": "The asset info of the asset that must be paid back", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "flash_loan_fee": { - "description": "The amount of fee paid to vault holders", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - }, - "payback_amount": { - "description": "The total amount that must be returned. Equivalent to `amount` + `protocol_fee` + `flash_loan_fee`.", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - }, - "protocol_fee": { - "description": "The amount of fee paid to the protocol", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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/liquidity_hub/vault-manager/schema/raw/response_to_share.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json deleted file mode 100644 index 3a5e1183..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_share.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ShareResponse", - "description": "Response for the Share query. Contains the amount of assets that the given `lp_share` is entitled to.", - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "description": "The amount of assets that the given `lp_share` is entitled to.", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - } - }, - "additionalProperties": false, - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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/liquidity_hub/vault-manager/schema/raw/response_to_vault.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json deleted file mode 100644 index b1b0014e..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vault.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "VaultsResponse", - "description": "Response for the vaults query", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "array", - "items": { - "$ref": "#/definitions/Vault" - } - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "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" - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "Vault": { - "description": "Vault representation", - "type": "object", - "required": [ - "asset_info", - "fees", - "lp_asset" - ], - "properties": { - "asset_info": { - "description": "The asset info the vault manages", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "fees": { - "description": "The fees associated with the vault", - "allOf": [ - { - "$ref": "#/definitions/VaultFee" - } - ] - }, - "lp_asset": { - "description": "The LP asset", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - } - }, - "additionalProperties": false - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - } - } -} diff --git a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json b/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json deleted file mode 100644 index b1b0014e..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/raw/response_to_vaults.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "VaultsResponse", - "description": "Response for the vaults query", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "array", - "items": { - "$ref": "#/definitions/Vault" - } - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "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" - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "Vault": { - "description": "Vault representation", - "type": "object", - "required": [ - "asset_info", - "fees", - "lp_asset" - ], - "properties": { - "asset_info": { - "description": "The asset info the vault manages", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "fees": { - "description": "The fees associated with the vault", - "allOf": [ - { - "$ref": "#/definitions/VaultFee" - } - ] - }, - "lp_asset": { - "description": "The LP asset", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - } - }, - "additionalProperties": false - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - } - } -} diff --git a/contracts/liquidity_hub/vault-manager/schema/vault-manager.json b/contracts/liquidity_hub/vault-manager/schema/vault-manager.json deleted file mode 100644 index af50149a..00000000 --- a/contracts/liquidity_hub/vault-manager/schema/vault-manager.json +++ /dev/null @@ -1,2362 +0,0 @@ -{ - "contract_name": "vault-manager", - "contract_version": "0.1.0", - "idl_version": "1.0.0", - "instantiate": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "InstantiateMsg", - "description": "The instantiation message", - "type": "object", - "required": [ - "lp_token_type", - "owner", - "vault_creation_fee", - "whale_lair_addr" - ], - "properties": { - "lp_token_type": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "allOf": [ - { - "$ref": "#/definitions/LpTokenType" - } - ] - }, - "owner": { - "description": "The owner of the contract", - "type": "string" - }, - "vault_creation_fee": { - "description": "The fee to create a vault", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - }, - "whale_lair_addr": { - "description": "The whale lair address, where protocol fees are distributed", - "type": "string" - } - }, - "additionalProperties": false, - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "LpTokenType": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "oneOf": [ - { - "type": "string", - "enum": [ - "token_factory" - ] - }, - { - "type": "object", - "required": [ - "cw20" - ], - "properties": { - "cw20": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "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" - } - } - }, - "execute": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ExecuteMsg", - "description": "The execution messages", - "oneOf": [ - { - "description": "Creates a new vault given the asset info the vault should manage deposits and withdrawals for and the fees", - "type": "object", - "required": [ - "create_vault" - ], - "properties": { - "create_vault": { - "type": "object", - "required": [ - "asset_info", - "fees" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - }, - "fees": { - "$ref": "#/definitions/VaultFee" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Removes a vault given its [AssetInfo]", - "type": "object", - "required": [ - "remove_vault" - ], - "properties": { - "remove_vault": { - "type": "object", - "required": [ - "asset_info" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Updates a vault config", - "type": "object", - "required": [ - "update_vault_fees" - ], - "properties": { - "update_vault_fees": { - "type": "object", - "required": [ - "vault_asset_info", - "vault_fee" - ], - "properties": { - "vault_asset_info": { - "$ref": "#/definitions/AssetInfo" - }, - "vault_fee": { - "$ref": "#/definitions/VaultFee" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Updates the configuration of the vault manager. If a field is not specified, it will not be modified.", - "type": "object", - "required": [ - "update_config" - ], - "properties": { - "update_config": { - "type": "object", - "properties": { - "cw20_lp_code_id": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - }, - "deposit_enabled": { - "type": [ - "boolean", - "null" - ] - }, - "flash_loan_enabled": { - "type": [ - "boolean", - "null" - ] - }, - "vault_creation_fee": { - "anyOf": [ - { - "$ref": "#/definitions/Asset" - }, - { - "type": "null" - } - ] - }, - "whale_lair_addr": { - "type": [ - "string", - "null" - ] - }, - "withdraw_enabled": { - "type": [ - "boolean", - "null" - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Deposits a given asset into the vault manager.", - "type": "object", - "required": [ - "deposit" - ], - "properties": { - "deposit": { - "type": "object", - "required": [ - "asset" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Withdraws from the vault manager. Used when the LP token is a token manager token.", - "type": "object", - "required": [ - "withdraw" - ], - "properties": { - "withdraw": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "receive" - ], - "properties": { - "receive": { - "$ref": "#/definitions/Cw20ReceiveMsg" - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the desired `asset` and runs the `payload`, paying the required amount back to the vault after running the messages in the payload, and returning the profit to the sender.", - "type": "object", - "required": [ - "flash_loan" - ], - "properties": { - "flash_loan": { - "type": "object", - "required": [ - "asset", - "payload" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - }, - "payload": { - "type": "array", - "items": { - "$ref": "#/definitions/CosmosMsg_for_Empty" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Callback message for post-processing flash-loans.", - "type": "object", - "required": [ - "callback" - ], - "properties": { - "callback": { - "$ref": "#/definitions/CallbackMsg" - } - }, - "additionalProperties": false - }, - { - "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", - "type": "object", - "required": [ - "update_ownership" - ], - "properties": { - "update_ownership": { - "$ref": "#/definitions/Action" - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Action": { - "description": "Actions that can be taken to alter the contract's ownership", - "oneOf": [ - { - "description": "Propose to transfer the contract's ownership to another account, optionally with an expiry time.\n\nCan only be called by the contract's current owner.\n\nAny existing pending ownership transfer is overwritten.", - "type": "object", - "required": [ - "transfer_ownership" - ], - "properties": { - "transfer_ownership": { - "type": "object", - "required": [ - "new_owner" - ], - "properties": { - "expiry": { - "anyOf": [ - { - "$ref": "#/definitions/Expiration" - }, - { - "type": "null" - } - ] - }, - "new_owner": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Accept the pending ownership transfer.\n\nCan only be called by the pending owner.", - "type": "string", - "enum": [ - "accept_ownership" - ] - }, - { - "description": "Give up the contract's ownership and the possibility of appointing a new owner.\n\nCan only be invoked by the contract's current owner.\n\nAny existing pending ownership transfer is canceled.", - "type": "string", - "enum": [ - "renounce_ownership" - ] - } - ] - }, - "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" - }, - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "BankMsg": { - "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", - "oneOf": [ - { - "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "send" - ], - "properties": { - "send": { - "type": "object", - "required": [ - "amount", - "to_address" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "to_address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", - "type": "object", - "required": [ - "burn" - ], - "properties": { - "burn": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "CallbackMsg": { - "description": "The callback messages available. Only callable by the vault contract itself.", - "oneOf": [ - { - "type": "object", - "required": [ - "after_flashloan" - ], - "properties": { - "after_flashloan": { - "type": "object", - "required": [ - "loan_asset", - "old_asset_balance", - "sender" - ], - "properties": { - "loan_asset": { - "$ref": "#/definitions/Asset" - }, - "old_asset_balance": { - "$ref": "#/definitions/Uint128" - }, - "sender": { - "$ref": "#/definitions/Addr" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Coin": { - "type": "object", - "required": [ - "amount", - "denom" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "denom": { - "type": "string" - } - } - }, - "CosmosMsg_for_Empty": { - "oneOf": [ - { - "type": "object", - "required": [ - "bank" - ], - "properties": { - "bank": { - "$ref": "#/definitions/BankMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "custom" - ], - "properties": { - "custom": { - "$ref": "#/definitions/Empty" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "staking" - ], - "properties": { - "staking": { - "$ref": "#/definitions/StakingMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "distribution" - ], - "properties": { - "distribution": { - "$ref": "#/definitions/DistributionMsg" - } - }, - "additionalProperties": false - }, - { - "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", - "type": "object", - "required": [ - "stargate" - ], - "properties": { - "stargate": { - "type": "object", - "required": [ - "type_url", - "value" - ], - "properties": { - "type_url": { - "type": "string" - }, - "value": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "ibc" - ], - "properties": { - "ibc": { - "$ref": "#/definitions/IbcMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "wasm" - ], - "properties": { - "wasm": { - "$ref": "#/definitions/WasmMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "gov" - ], - "properties": { - "gov": { - "$ref": "#/definitions/GovMsg" - } - }, - "additionalProperties": false - } - ] - }, - "Cw20ReceiveMsg": { - "type": "object", - "required": [ - "amount", - "msg", - "sender" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "sender": { - "type": "string" - } - }, - "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" - }, - "DistributionMsg": { - "description": "The message types of the distribution module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "set_withdraw_address" - ], - "properties": { - "set_withdraw_address": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "description": "The `withdraw_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [[MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "withdraw_delegator_reward" - ], - "properties": { - "withdraw_delegator_reward": { - "type": "object", - "required": [ - "validator" - ], - "properties": { - "validator": { - "description": "The `validator_address`", - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Empty": { - "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", - "type": "object" - }, - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "GovMsg": { - "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", - "oneOf": [ - { - "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", - "type": "object", - "required": [ - "vote" - ], - "properties": { - "vote": { - "type": "object", - "required": [ - "proposal_id", - "vote" - ], - "properties": { - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "vote": { - "description": "The vote option.\n\nThis should be called \"option\" for consistency with Cosmos SDK. Sorry for that. See .", - "allOf": [ - { - "$ref": "#/definitions/VoteOption" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address.", - "type": "object", - "required": [ - "vote_weighted" - ], - "properties": { - "vote_weighted": { - "type": "object", - "required": [ - "options", - "proposal_id" - ], - "properties": { - "options": { - "type": "array", - "items": { - "$ref": "#/definitions/WeightedVoteOption" - } - }, - "proposal_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - } - ] - }, - "IbcMsg": { - "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", - "oneOf": [ - { - "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", - "type": "object", - "required": [ - "transfer" - ], - "properties": { - "transfer": { - "type": "object", - "required": [ - "amount", - "channel_id", - "timeout", - "to_address" - ], - "properties": { - "amount": { - "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", - "allOf": [ - { - "$ref": "#/definitions/Coin" - } - ] - }, - "channel_id": { - "description": "exisiting channel to send the tokens over", - "type": "string" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - }, - "to_address": { - "description": "address on the remote chain to receive these tokens", - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", - "type": "object", - "required": [ - "send_packet" - ], - "properties": { - "send_packet": { - "type": "object", - "required": [ - "channel_id", - "data", - "timeout" - ], - "properties": { - "channel_id": { - "type": "string" - }, - "data": { - "$ref": "#/definitions/Binary" - }, - "timeout": { - "description": "when packet times out, measured on remote chain", - "allOf": [ - { - "$ref": "#/definitions/IbcTimeout" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", - "type": "object", - "required": [ - "close_channel" - ], - "properties": { - "close_channel": { - "type": "object", - "required": [ - "channel_id" - ], - "properties": { - "channel_id": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "IbcTimeout": { - "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", - "type": "object", - "properties": { - "block": { - "anyOf": [ - { - "$ref": "#/definitions/IbcTimeoutBlock" - }, - { - "type": "null" - } - ] - }, - "timestamp": { - "anyOf": [ - { - "$ref": "#/definitions/Timestamp" - }, - { - "type": "null" - } - ] - } - } - }, - "IbcTimeoutBlock": { - "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", - "type": "object", - "required": [ - "height", - "revision" - ], - "properties": { - "height": { - "description": "block height after which the packet times out. the height within the given revision", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "revision": { - "description": "the version that the client is currently on (eg. after reseting the chain this could increment 1 as height drops to 0)", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - }, - "StakingMsg": { - "description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto", - "oneOf": [ - { - "description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "delegate" - ], - "properties": { - "delegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "undelegate" - ], - "properties": { - "undelegate": { - "type": "object", - "required": [ - "amount", - "validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "redelegate" - ], - "properties": { - "redelegate": { - "type": "object", - "required": [ - "amount", - "dst_validator", - "src_validator" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Coin" - }, - "dst_validator": { - "type": "string" - }, - "src_validator": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "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" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - }, - "VoteOption": { - "type": "string", - "enum": [ - "yes", - "no", - "abstain", - "no_with_veto" - ] - }, - "WasmMsg": { - "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", - "oneOf": [ - { - "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "execute" - ], - "properties": { - "execute": { - "type": "object", - "required": [ - "contract_addr", - "funds", - "msg" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "msg": { - "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "instantiate" - ], - "properties": { - "instantiate": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Instantiates a new contracts from previously uploaded Wasm code using a predictable address derivation algorithm implemented in [`cosmwasm_std::instantiate2_address`].\n\nThis is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). `sender` is automatically filled with the current contract's address. `fix_msg` is automatically set to false.", - "type": "object", - "required": [ - "instantiate2" - ], - "properties": { - "instantiate2": { - "type": "object", - "required": [ - "code_id", - "funds", - "label", - "msg", - "salt" - ], - "properties": { - "admin": { - "type": [ - "string", - "null" - ] - }, - "code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "funds": { - "type": "array", - "items": { - "$ref": "#/definitions/Coin" - } - }, - "label": { - "description": "A human-readbale label for the contract", - "type": "string" - }, - "msg": { - "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "salt": { - "$ref": "#/definitions/Binary" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", - "type": "object", - "required": [ - "migrate" - ], - "properties": { - "migrate": { - "type": "object", - "required": [ - "contract_addr", - "msg", - "new_code_id" - ], - "properties": { - "contract_addr": { - "type": "string" - }, - "msg": { - "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", - "allOf": [ - { - "$ref": "#/definitions/Binary" - } - ] - }, - "new_code_id": { - "description": "the code_id of the new logic to place in the given contract", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "update_admin" - ], - "properties": { - "update_admin": { - "type": "object", - "required": [ - "admin", - "contract_addr" - ], - "properties": { - "admin": { - "type": "string" - }, - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", - "type": "object", - "required": [ - "clear_admin" - ], - "properties": { - "clear_admin": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] - }, - "WeightedVoteOption": { - "type": "object", - "required": [ - "option", - "weight" - ], - "properties": { - "option": { - "$ref": "#/definitions/VoteOption" - }, - "weight": { - "$ref": "#/definitions/Decimal" - } - } - } - } - }, - "query": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "description": "The query messages", - "oneOf": [ - { - "description": "Retrieves the configuration of the manager.", - "type": "object", - "required": [ - "config" - ], - "properties": { - "config": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves a vault given the asset_info.", - "type": "object", - "required": [ - "vault" - ], - "properties": { - "vault": { - "type": "object", - "required": [ - "asset_info" - ], - "properties": { - "asset_info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the addresses for all the vaults.", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "object", - "properties": { - "limit": { - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - }, - "start_after": { - "type": [ - "array", - "null" - ], - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the share of the assets stored in the vault that a given `lp_share` is entitled to.", - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "type": "object", - "required": [ - "lp_share" - ], - "properties": { - "lp_share": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Retrieves the [`Uint128`] amount that must be sent back to the contract to pay off a loan taken out.", - "type": "object", - "required": [ - "payback_amount" - ], - "properties": { - "payback_amount": { - "type": "object", - "required": [ - "asset" - ], - "properties": { - "asset": { - "$ref": "#/definitions/Asset" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "Query the contract's ownership information", - "type": "object", - "required": [ - "ownership" - ], - "properties": { - "ownership": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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" - } - } - }, - "migrate": null, - "sudo": null, - "responses": { - "config": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Config", - "description": "Configuration for the contract (manager)", - "type": "object", - "required": [ - "deposit_enabled", - "flash_loan_enabled", - "lp_token_type", - "vault_creation_fee", - "whale_lair_addr", - "withdraw_enabled" - ], - "properties": { - "deposit_enabled": { - "description": "If deposits are enabled", - "type": "boolean" - }, - "flash_loan_enabled": { - "description": "If flash-loans are enabled", - "type": "boolean" - }, - "lp_token_type": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "allOf": [ - { - "$ref": "#/definitions/LpTokenType" - } - ] - }, - "vault_creation_fee": { - "description": "The fee to create a new vault", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - }, - "whale_lair_addr": { - "description": "The whale lair contract address", - "allOf": [ - { - "$ref": "#/definitions/Addr" - } - ] - }, - "withdraw_enabled": { - "description": "If withdrawals are enabled", - "type": "boolean" - } - }, - "additionalProperties": false, - "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" - }, - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "LpTokenType": { - "description": "The type of LP token to use, whether a cw20 token or a token factory token", - "oneOf": [ - { - "type": "string", - "enum": [ - "token_factory" - ] - }, - { - "type": "object", - "required": [ - "cw20" - ], - "properties": { - "cw20": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "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" - } - } - }, - "ownership": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Ownership_for_String", - "description": "The contract's ownership info", - "type": "object", - "properties": { - "owner": { - "description": "The contract's current owner. `None` if the ownership has been renounced.", - "type": [ - "string", - "null" - ] - }, - "pending_expiry": { - "description": "The deadline for the pending owner to accept the ownership. `None` if there isn't a pending ownership transfer, or if a transfer exists and it doesn't have a deadline.", - "anyOf": [ - { - "$ref": "#/definitions/Expiration" - }, - { - "type": "null" - } - ] - }, - "pending_owner": { - "description": "The account who has been proposed to take over the ownership. `None` if there isn't a pending ownership transfer.", - "type": [ - "string", - "null" - ] - } - }, - "additionalProperties": false, - "definitions": { - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } - }, - "payback_amount": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "PaybackAssetResponse", - "description": "Response for the PaybackAmount query. Contains the amount that must be paid back to the contract if taken a flashloan.", - "type": "object", - "required": [ - "asset_info", - "flash_loan_fee", - "payback_amount", - "protocol_fee" - ], - "properties": { - "asset_info": { - "description": "The asset info of the asset that must be paid back", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "flash_loan_fee": { - "description": "The amount of fee paid to vault holders", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - }, - "payback_amount": { - "description": "The total amount that must be returned. Equivalent to `amount` + `protocol_fee` + `flash_loan_fee`.", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - }, - "protocol_fee": { - "description": "The amount of fee paid to the protocol", - "allOf": [ - { - "$ref": "#/definitions/Uint128" - } - ] - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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" - } - } - }, - "share": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ShareResponse", - "description": "Response for the Share query. Contains the amount of assets that the given `lp_share` is entitled to.", - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "description": "The amount of assets that the given `lp_share` is entitled to.", - "allOf": [ - { - "$ref": "#/definitions/Asset" - } - ] - } - }, - "additionalProperties": false, - "definitions": { - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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" - } - } - }, - "vault": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "VaultsResponse", - "description": "Response for the vaults query", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "array", - "items": { - "$ref": "#/definitions/Vault" - } - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "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" - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "Vault": { - "description": "Vault representation", - "type": "object", - "required": [ - "asset_info", - "fees", - "lp_asset" - ], - "properties": { - "asset_info": { - "description": "The asset info the vault manages", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "fees": { - "description": "The fees associated with the vault", - "allOf": [ - { - "$ref": "#/definitions/VaultFee" - } - ] - }, - "lp_asset": { - "description": "The LP asset", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - } - }, - "additionalProperties": false - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - } - } - }, - "vaults": { - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "VaultsResponse", - "description": "Response for the vaults query", - "type": "object", - "required": [ - "vaults" - ], - "properties": { - "vaults": { - "type": "array", - "items": { - "$ref": "#/definitions/Vault" - } - } - }, - "additionalProperties": false, - "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "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" - }, - "Fee": { - "type": "object", - "required": [ - "share" - ], - "properties": { - "share": { - "$ref": "#/definitions/Decimal" - } - }, - "additionalProperties": false - }, - "Vault": { - "description": "Vault representation", - "type": "object", - "required": [ - "asset_info", - "fees", - "lp_asset" - ], - "properties": { - "asset_info": { - "description": "The asset info the vault manages", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - }, - "fees": { - "description": "The fees associated with the vault", - "allOf": [ - { - "$ref": "#/definitions/VaultFee" - } - ] - }, - "lp_asset": { - "description": "The LP asset", - "allOf": [ - { - "$ref": "#/definitions/AssetInfo" - } - ] - } - }, - "additionalProperties": false - }, - "VaultFee": { - "type": "object", - "required": [ - "flash_loan_fee", - "protocol_fee" - ], - "properties": { - "flash_loan_fee": { - "$ref": "#/definitions/Fee" - }, - "protocol_fee": { - "$ref": "#/definitions/Fee" - } - }, - "additionalProperties": false - } - } - } - } -} diff --git a/packages/white-whale/src/pool_network/mod.rs b/packages/white-whale/src/pool_network/mod.rs index 91f88096..52c2d7fc 100644 --- a/packages/white-whale/src/pool_network/mod.rs +++ b/packages/white-whale/src/pool_network/mod.rs @@ -10,6 +10,7 @@ pub mod incentive_factory; pub mod pair; pub mod querier; pub mod router; +pub mod swap; pub mod token; pub mod trio; diff --git a/packages/white-whale/src/pool_network/swap.rs b/packages/white-whale/src/pool_network/swap.rs new file mode 100644 index 00000000..ef58ce18 --- /dev/null +++ b/packages/white-whale/src/pool_network/swap.rs @@ -0,0 +1,42 @@ +use cosmwasm_std::{Decimal, Decimal256, Fraction, StdError, StdResult, Uint128}; +use std::str::FromStr; + +/// Default swap slippage in case max_spread is not specified +pub const DEFAULT_SLIPPAGE: &str = "0.01"; +/// Cap on the maximum swap slippage that is allowed. If max_spread goes over this limit, it will +/// be capped to this value. +pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5"; + +/// If `belief_price` and `max_spread` both are given, +/// we compute new spread else we just use pool network +/// spread to check `max_spread` +pub fn assert_max_spread( + belief_price: Option, + max_spread: Option, + offer_amount: Uint128, + return_amount: Uint128, + spread_amount: Uint128, +) -> StdResult<()> { + let max_spread: Decimal256 = max_spread + .unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?) + .min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?) + .into(); + + if let Some(belief_price) = belief_price { + let expected_return = offer_amount + * belief_price + .inv() + .ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?; + let spread_amount = expected_return.saturating_sub(return_amount); + + if return_amount < expected_return + && Decimal256::from_ratio(spread_amount, expected_return) > max_spread + { + return Err(StdError::generic_err("Spread limit exceeded")); + } + } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread { + return Err(StdError::generic_err("Spread limit exceeded")); + } + + Ok(()) +} From 5e57ffb2f8cbe8a5201bef1c2d4ad102c59ed26e Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Fri, 20 Oct 2023 12:18:13 +0100 Subject: [PATCH 4/4] test: add missing test to cover for assert_max_spread error --- .../terraswap_pair/src/tests/testing.rs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs index 8efa2aaa..4105cb3d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs @@ -1,14 +1,12 @@ -#[cfg(feature = "token_factory")] -use crate::state::LP_SYMBOL; +use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; #[cfg(feature = "token_factory")] use cosmwasm_std::CosmosMsg; - -use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ from_binary, to_binary, Addr, Decimal, Reply, ReplyOn, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::MinterResponse; + use white_whale::fee::Fee; use white_whale::pool_network::asset::{Asset, AssetInfo, PairInfo, PairType}; #[cfg(feature = "token_factory")] @@ -23,6 +21,8 @@ use crate::contract::{execute, instantiate, query, reply}; use crate::error::ContractError; use crate::helpers::assert_slippage_tolerance; use crate::queries::query_pair_info; +#[cfg(feature = "token_factory")] +use crate::state::LP_SYMBOL; #[test] fn proper_initialization_cw20_lp() { @@ -346,6 +346,7 @@ fn test_initialization_invalid_fees() { _ => panic!("should return StdError::generic_err(Invalid fee)"), } } + #[test] fn test_max_spread() { assert_max_spread( @@ -462,7 +463,26 @@ fn test_max_spread() { Uint128::zero(), ) .unwrap(); + + assert_max_spread( + Some(Decimal::from_ratio(1200_000_000u128, 1_000_000u128)), + Some(Decimal::percent(60)), // this will default to 50% + Uint128::from(1200_000_000u128), + Uint128::from(989_999u128), + Uint128::zero(), + ) + .unwrap(); + + assert_max_spread( + Some(Decimal::zero()), + None, + Uint128::new(100), + Uint128::new(90), + Uint128::new(10), + ) + .unwrap_err(); } + #[test] fn test_update_config_unsuccessful() { let mut deps = mock_dependencies(&[]);