Skip to content

Commit

Permalink
Merge pull request #62 from apollodao/dev/0.4.x
Browse files Browse the repository at this point in the history
Release 0.4.1
  • Loading branch information
apollo-sturdy authored Aug 28, 2024
2 parents 6239fdd + 1f42643 commit 944d784
Show file tree
Hide file tree
Showing 14 changed files with 720 additions and 412 deletions.
958 changes: 581 additions & 377 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ resolver = "2"

[workspace.package]
edition = "2021"
authors = ["Sturdy <[email protected]>"]
authors = ["Sturdy <[email protected]>", "Pacman <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/apollodao/cw-vault-standard/"
repository = "https://github.com/apollodao/cw-vault-standard/"
keywords = ["cosmos", "cosmwasm"]

[workspace.dependencies]
cosmwasm-std = "1.5.4"
cosmwasm-std = "1.5.5"
schemars = "0.8.11"
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
cosmwasm-schema = "1.2.1"
Expand All @@ -24,8 +24,8 @@ cw-storage-plus = "1.1.0"
cw2 = "1.1.0"
mars-owner = "2.0.0"
osmosis-std = "0.16.1"
cw-vault-standard = { version = "0.3.3", path = "./cw-vault-standard" }
cw-vault-standard-test-helpers = { version = "0.3.3", path = "./test-helpers" }
cw-vault-standard = { version = "0.4.1", path = "./cw-vault-standard" }
cw-vault-standard-test-helpers = { version = "0.5.0", path = "./test-helpers" }

# dev dependencies
proptest = "1.2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ This repo also contains some test helpers in the `packages/test-helpers` directo

| cw-vault-standard | test-helpers |
|-------------------|---------------|
| v0.3.3 | v0.3.3 |
| v0.4.0 | v0.3.3-v0.4.0 |
| v0.3.3 | v0.3.3-0.4.1 |
| v0.4.1 | v0.5.0 |
16 changes: 16 additions & 0 deletions cw-vault-standard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.1] - 2024-08-28

### Added
- Added `base_token` and `vault_token` fields to `VaultContract` helper struct.
- Added `VaultStandardQueryMsg::VaultTokenExchangeRate` query message.

### Changed

- Changes type of `VaultStandardInfoResponse::version` from `u16` to `String`
- Remove faulty usage of `to_binary` in `VaultContract` query helper functions.
- Replace usage of deprecated `to_binary` with `to_json_binary`.
- Deprecated `VaultStandardQueryMsg::PreviewDeposit` and `VaultStandardQueryMsg::PreviewRedeem`.
- There queries turned out to be too difficult to implement in most cases. We recommend to use transaction simulation from non-contract clients such as frontends. These queries will be removed in the next major version.
- Deprecated CW4626 Extension now that TokenFactory module is standard across all major Cosmos chains. The extension will be removed in the next major version.
- Deprecated `amount` fields in `VaultStandardExecuteMsg::Deposit` and `VaultStandardExecuteMsg::Redeem` as well as in `LockupExecuteMsg::Unlock` and `ForceUnlockExecuteMsg::ForceRedeem`. These fields will be removed in a future version and the amount from the sent funds will be used instead.

## [0.3.3] - 2023-09-27

### Added
Expand Down
2 changes: 1 addition & 1 deletion cw-vault-standard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-vault-standard"
version = "0.3.3"
version = "0.4.1"
description = "A standard interface for tokenized vaults written in CosmWasm"
documentation = "https://docs.rs/cw-vault-standard"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions cw-vault-standard/src/extensions/cw4626.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::msg::{
ExtensionExecuteMsg, ExtensionQueryMsg, VaultInfoResponse, VaultStandardInfoResponse,
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{to_binary, Binary, Coin, CosmosMsg, Empty, StdResult, Uint128, WasmMsg};
use cosmwasm_std::{to_json_binary, Binary, Coin, CosmosMsg, Empty, StdResult, Uint128, WasmMsg};
use cw20::{
AllAccountsResponse, AllAllowancesResponse, AllowanceResponse, BalanceResponse,
DownloadLogoResponse, MarketingInfoResponse, TokenInfoResponse,
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Cw4626ExecuteMsg {
pub fn into_cosmos_msg(self, contract_addr: String, funds: Vec<Coin>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::Execute {
contract_addr,
msg: to_binary(&self)?,
msg: to_json_binary(&self)?,
funds,
}
.into())
Expand Down
9 changes: 7 additions & 2 deletions cw-vault-standard/src/extensions/force_unlock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Coin, CosmosMsg, StdResult, Uint128, WasmMsg};
use cosmwasm_std::{to_json_binary, Coin, CosmosMsg, StdResult, Uint128, WasmMsg};

use crate::{ExtensionExecuteMsg, VaultStandardExecuteMsg};

Expand All @@ -16,6 +16,11 @@ pub enum ForceUnlockExecuteMsg {
/// the caller address will be used instead.
recipient: Option<String>,
/// The amount of vault tokens to force redeem.
#[deprecated(
since = "0.4.1",
note = "This field will be removed in the next version. The amount \
of vault tokens should instead be read from the actual amount of sent vault tokens."
)]
amount: Uint128,
},

Expand Down Expand Up @@ -47,7 +52,7 @@ impl ForceUnlockExecuteMsg {
pub fn into_cosmos_msg(self, contract_addr: String, funds: Vec<Coin>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::Execute {
contract_addr,
msg: to_binary(&VaultStandardExecuteMsg::VaultExtension(
msg: to_json_binary(&VaultStandardExecuteMsg::VaultExtension(
ExtensionExecuteMsg::ForceUnlock(self),
))?,
funds,
Expand Down
4 changes: 2 additions & 2 deletions cw-vault-standard/src/extensions/keeper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{to_binary, Addr, Coin, CosmosMsg, StdResult, WasmMsg};
use cosmwasm_std::{to_json_binary, Addr, Coin, CosmosMsg, StdResult, WasmMsg};

use crate::{ExtensionExecuteMsg, VaultStandardExecuteMsg};

Expand Down Expand Up @@ -46,7 +46,7 @@ impl KeeperExecuteMsg {
pub fn into_cosmos_msg(self, contract_addr: String, funds: Vec<Coin>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::Execute {
contract_addr,
msg: to_binary(&VaultStandardExecuteMsg::VaultExtension(
msg: to_json_binary(&VaultStandardExecuteMsg::VaultExtension(
ExtensionExecuteMsg::Keeper(self),
))?,
funds,
Expand Down
9 changes: 7 additions & 2 deletions cw-vault-standard/src/extensions/lockup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{to_binary, Addr, Coin, CosmosMsg, StdResult, Uint128, WasmMsg};
use cosmwasm_std::{to_json_binary, Addr, Coin, CosmosMsg, StdResult, Uint128, WasmMsg};
use cw_utils::{Duration, Expiration};

use crate::{ExtensionExecuteMsg, VaultStandardExecuteMsg};
Expand All @@ -24,6 +24,11 @@ pub enum LockupExecuteMsg {
/// CW4626 and native tokens.
Unlock {
/// The amount of vault tokens to unlock.
#[deprecated(
since = "0.4.1",
note = "This field will be removed in the next version. The amount \
of vault tokens should instead be read from the actual amount of sent vault tokens."
)]
amount: Uint128,
},

Expand Down Expand Up @@ -54,7 +59,7 @@ impl LockupExecuteMsg {
pub fn into_cosmos_msg(self, contract_addr: String, funds: Vec<Coin>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::Execute {
contract_addr,
msg: to_binary(&VaultStandardExecuteMsg::VaultExtension(
msg: to_json_binary(&VaultStandardExecuteMsg::VaultExtension(
ExtensionExecuteMsg::Lockup(self),
))?,
funds,
Expand Down
5 changes: 5 additions & 0 deletions cw-vault-standard/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ pub mod keeper;
/// therefore not issue a Cosmos native token as the vault token.
#[cfg(feature = "cw4626")]
#[cfg_attr(docsrs, doc(cfg(feature = "cw4626")))]
#[deprecated(
since = "0.4.1",
note = "The CW4626 extension is deprecated and will be removed in a future release. \
Please use TokenFactory to create vault tokens instead."
)]
pub mod cw4626;
61 changes: 48 additions & 13 deletions cw-vault-standard/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::marker::PhantomData;

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
coin, to_binary, Addr, Api, CosmosMsg, QuerierWrapper, StdResult, Uint128, WasmMsg,
coin, to_json_binary, Addr, CosmosMsg, Decimal, Deps, QuerierWrapper, StdResult, Uint128,
WasmMsg,
};
use schemars::JsonSchema;
use serde::Serialize;
Expand Down Expand Up @@ -39,8 +40,8 @@ where

/// Check the address against the api and return a checked version of the
/// struct.
pub fn check(&self, api: &dyn Api) -> StdResult<VaultContract<E, Q>> {
Ok(VaultContract::new(&api.addr_validate(&self.addr)?))
pub fn check(&self, deps: Deps) -> StdResult<VaultContract<E, Q>> {
VaultContract::new(&deps.querier, &deps.api.addr_validate(&self.addr)?)
}
}

Expand All @@ -50,6 +51,10 @@ where
pub struct VaultContract<E = ExtensionExecuteMsg, Q = ExtensionQueryMsg> {
/// The address of the vault contract.
pub addr: Addr,
/// The base token of the vault contract.
pub base_token: String,
/// The vault token denom of the vault contract.
pub vault_token: String,
/// The extension enum for ExecuteMsg variants.
execute_msg_extension: PhantomData<E>,
/// The extension enum for QueryMsg variants.
Expand All @@ -62,27 +67,35 @@ where
Q: Serialize + JsonSchema,
{
/// Create a new VaultContract instance.
pub fn new(addr: &Addr) -> Self {
Self {
pub fn new(querier: &QuerierWrapper, addr: &Addr) -> StdResult<Self> {
// Query vault info
let vault_info: VaultInfoResponse =
querier.query_wasm_smart(addr, &VaultStandardQueryMsg::<Q>::Info {})?;

Ok(Self {
addr: addr.clone(),
base_token: vault_info.base_token,
vault_token: vault_info.vault_token,
execute_msg_extension: PhantomData,
query_msg_extension: PhantomData,
}
})
}

/// Returns a CosmosMsg to deposit base tokens into the vault.
pub fn deposit(
&self,
amount: impl Into<Uint128>,
base_denom: &str,
recipient: Option<String>,
) -> StdResult<CosmosMsg> {
let amount = amount.into();

Ok(WasmMsg::Execute {
contract_addr: self.addr.to_string(),
msg: to_binary(&VaultStandardExecuteMsg::<E>::Deposit { amount, recipient })?,
funds: vec![coin(amount.u128(), base_denom)],
msg: to_json_binary(&VaultStandardExecuteMsg::<E>::Deposit {
amount: amount.clone(),
recipient,
})?,
funds: vec![coin(amount.u128(), &self.base_token)],
}
.into())
}
Expand All @@ -93,7 +106,7 @@ where
pub fn deposit_cw20(&self, amount: Uint128, recipient: Option<String>) -> StdResult<CosmosMsg> {
Ok(WasmMsg::Execute {
contract_addr: self.addr.to_string(),
msg: to_binary(&VaultStandardExecuteMsg::<E>::Deposit { amount, recipient })?,
msg: to_json_binary(&VaultStandardExecuteMsg::<E>::Deposit { amount, recipient })?,
funds: vec![],
}
.into())
Expand All @@ -103,14 +116,16 @@ where
pub fn redeem(
&self,
amount: impl Into<Uint128>,
vault_token_denom: &str,
recipient: Option<String>,
) -> StdResult<CosmosMsg> {
let amount = amount.into();
Ok(WasmMsg::Execute {
contract_addr: self.addr.to_string(),
msg: to_binary(&VaultStandardExecuteMsg::<E>::Redeem { amount, recipient })?,
funds: vec![coin(amount.u128(), vault_token_denom)],
msg: to_json_binary(&VaultStandardExecuteMsg::<E>::Redeem {
amount: amount.clone(),
recipient,
})?,
funds: vec![coin(amount.u128(), &self.vault_token)],
}
.into())
}
Expand All @@ -131,6 +146,10 @@ where
querier.query_wasm_smart(&self.addr, &VaultStandardQueryMsg::<Q>::Info {})
}

#[deprecated(
since = "0.4.1",
note = "PreviewDeposit and PreviewRedeem turned out to be too difficult to implement in most cases. We recommend to use transaction simulation from non-contract clients such as frontends."
)]
/// Queries the vault for a preview of a deposit
pub fn query_preview_deposit(
&self,
Expand All @@ -145,6 +164,10 @@ where
)
}

#[deprecated(
since = "0.4.1",
note = "PreviewDeposit and PreviewRedeem turned out to be too difficult to implement in most cases. We recommend to use transaction simulation from non-contract clients such as frontends."
)]
/// Queries the vault for a preview of a redeem
pub fn query_preview_redeem(
&self,
Expand Down Expand Up @@ -172,6 +195,18 @@ where
)
}

/// Queries the vault for the vault token exchange rate
pub fn query_vault_token_exchange_rate(
&self,
quote_denom: String,
querier: &QuerierWrapper,
) -> StdResult<Decimal> {
querier.query_wasm_smart(
&self.addr,
&VaultStandardQueryMsg::<Q>::VaultTokenExchangeRate { quote_denom },
)
}

/// Queries the vault to convert an amount of vault tokens to base tokens
pub fn query_convert_to_shares(
&self,
Expand Down
Loading

0 comments on commit 944d784

Please sign in to comment.