diff --git a/cosmwasm/Cargo.lock b/cosmwasm/Cargo.lock index 2c3fc20235..ecb0a9adae 100644 --- a/cosmwasm/Cargo.lock +++ b/cosmwasm/Cargo.lock @@ -611,6 +611,7 @@ dependencies = [ name = "cw20-wrapped-2" version = "0.1.0" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "cw2 0.13.4", @@ -1244,6 +1245,7 @@ dependencies = [ name = "mock-bridge-integration-2" version = "0.1.0" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "cosmwasm-vm", @@ -1976,6 +1978,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" name = "token-bridge-cosmwasm" version = "0.1.0" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "cw20", @@ -2624,6 +2627,7 @@ dependencies = [ name = "wormhole-cosmwasm" version = "0.1.0" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "generic-array", diff --git a/cosmwasm/contracts/cw20-wrapped/Cargo.toml b/cosmwasm/contracts/cw20-wrapped/Cargo.toml index e7dcf4a51d..13ec0b6321 100644 --- a/cosmwasm/contracts/cw20-wrapped/Cargo.toml +++ b/cosmwasm/contracts/cw20-wrapped/Cargo.toml @@ -16,6 +16,7 @@ library = [] [dependencies] cosmwasm-std = { version = "1.0.0" } cosmwasm-storage = { version = "1.0.0" } +cosmwasm-schema = { version = "1.0.0" } schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } cw2 = { version = "0.13.2" } diff --git a/cosmwasm/contracts/cw20-wrapped/src/examples/cw20_wrapped_schema.rs b/cosmwasm/contracts/cw20-wrapped/src/examples/cw20_wrapped_schema.rs new file mode 100644 index 0000000000..799b182c87 --- /dev/null +++ b/cosmwasm/contracts/cw20-wrapped/src/examples/cw20_wrapped_schema.rs @@ -0,0 +1,10 @@ +use cosmwasm_schema::write_api; +use cw20_wrapped_2::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } +} \ No newline at end of file diff --git a/cosmwasm/contracts/cw20-wrapped/src/msg.rs b/cosmwasm/contracts/cw20-wrapped/src/msg.rs index 2c82c4e4c9..eab21ba694 100644 --- a/cosmwasm/contracts/cw20-wrapped/src/msg.rs +++ b/cosmwasm/contracts/cw20-wrapped/src/msg.rs @@ -1,13 +1,12 @@ #![allow(clippy::field_reassign_with_default)] -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Binary, Uint128}; -use cw20::Expiration; +use cw20::{AllowanceResponse, BalanceResponse, Expiration, TokenInfoResponse}; type HumanAddr = String; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InstantiateMsg { pub name: String, pub symbol: String, @@ -18,24 +17,22 @@ pub struct InstantiateMsg { pub init_hook: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InitHook { pub msg: Binary, pub contract_addr: HumanAddr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InitMint { pub recipient: HumanAddr, pub amount: Uint128, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct MigrateMsg {} -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum ExecuteMsg { /// Implements CW20. Transfer is a base message to move tokens to another account without triggering actions Transfer { @@ -94,17 +91,22 @@ pub enum ExecuteMsg { UpdateMetadata { name: String, symbol: String }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] +#[derive(QueryResponses)] pub enum QueryMsg { - // Generic information about the wrapped asset + #[returns(WrappedAssetInfoResponse)] + /// Generic information about the wrapped asset WrappedAssetInfo {}, + + #[returns(BalanceResponse)] /// Implements CW20. Returns the current balance of the given address, 0 if unset. - Balance { - address: HumanAddr, - }, + Balance { address: HumanAddr }, + + #[returns(TokenInfoResponse)] /// Implements CW20. Returns metadata on the contract - name, decimals, supply, etc. TokenInfo {}, + + #[returns(AllowanceResponse)] /// Implements CW20 "allowance" extension. /// Returns how much spender can use from owner account, 0 if unset. Allowance { @@ -113,7 +115,7 @@ pub enum QueryMsg { }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct WrappedAssetInfoResponse { pub asset_chain: u16, // Asset chain id pub asset_address: Binary, // Asset smart contract address in the original chain diff --git a/cosmwasm/contracts/ibc-translator/src/examples/ibc_translator_schema.rs b/cosmwasm/contracts/ibc-translator/src/examples/ibc_translator_schema.rs new file mode 100644 index 0000000000..ea88b77f6c --- /dev/null +++ b/cosmwasm/contracts/ibc-translator/src/examples/ibc_translator_schema.rs @@ -0,0 +1,10 @@ +use cosmwasm_schema::write_api; +use ibc_translator::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } +} \ No newline at end of file diff --git a/cosmwasm/contracts/mock-bridge-integration/Cargo.toml b/cosmwasm/contracts/mock-bridge-integration/Cargo.toml index 1c8226c77e..d5ec88fcd3 100644 --- a/cosmwasm/contracts/mock-bridge-integration/Cargo.toml +++ b/cosmwasm/contracts/mock-bridge-integration/Cargo.toml @@ -15,6 +15,7 @@ library = [] [dependencies] cosmwasm-std = { version = "1.0.0" } cosmwasm-storage = { version = "1.0.0" } +cosmwasm-schema = { version = "1.0.0" } schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } diff --git a/cosmwasm/contracts/mock-bridge-integration/src/msg.rs b/cosmwasm/contracts/mock-bridge-integration/src/msg.rs index 8970a8f1fd..b86acc6794 100644 --- a/cosmwasm/contracts/mock-bridge-integration/src/msg.rs +++ b/cosmwasm/contracts/mock-bridge-integration/src/msg.rs @@ -1,26 +1,24 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::Binary; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; type HumanAddr = String; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InstantiateMsg { pub token_bridge_contract: HumanAddr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum ExecuteMsg { CompleteTransferWithPayload { data: Binary }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct MigrateMsg {} -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] +#[derive(QueryResponses)] pub enum QueryMsg { + #[returns(())] WrappedRegistry { chain: u16, address: Binary }, } diff --git a/cosmwasm/contracts/token-bridge/Cargo.toml b/cosmwasm/contracts/token-bridge/Cargo.toml index 67c72f44d8..05b9275ea6 100644 --- a/cosmwasm/contracts/token-bridge/Cargo.toml +++ b/cosmwasm/contracts/token-bridge/Cargo.toml @@ -21,6 +21,7 @@ default = ["full"] [dependencies] cosmwasm-std = { version = "1.0.0" } cosmwasm-storage = { version = "1.0.0" } +cosmwasm-schema = { version = "1.0.0" } schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } cw20 = "0.13.2" diff --git a/cosmwasm/contracts/token-bridge/src/msg.rs b/cosmwasm/contracts/token-bridge/src/msg.rs index e0a78bdf9a..1bc28b5e5a 100644 --- a/cosmwasm/contracts/token-bridge/src/msg.rs +++ b/cosmwasm/contracts/token-bridge/src/msg.rs @@ -1,6 +1,5 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Binary, Uint128}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; use crate::token_address::{ExternalTokenId, TokenId}; @@ -8,7 +7,7 @@ type HumanAddr = String; /// The instantiation parameters of the token bridge contract. See /// [`crate::state::ConfigInfo`] for more details on what these fields mean. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InstantiateMsg { pub gov_chain: u16, pub gov_address: Binary, @@ -22,8 +21,7 @@ pub struct InstantiateMsg { pub native_decimals: u8, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum ExecuteMsg { RegisterAssetHook { chain: u16, @@ -67,28 +65,30 @@ pub enum ExecuteMsg { }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct MigrateMsg {} -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] +#[derive(QueryResponses)] pub enum QueryMsg { + #[returns(WrappedRegistryResponse)] WrappedRegistry { chain: u16, address: Binary }, + #[returns(TransferInfoResponse)] TransferInfo { vaa: Binary }, + #[returns(ExternalIdResponse)] ExternalId { external_id: Binary }, + #[returns(IsVaaRedeemedResponse)] IsVaaRedeemed { vaa: Binary }, + #[returns(ChainRegistrationResponse)] ChainRegistration { chain: u16 }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct WrappedRegistryResponse { pub address: HumanAddr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct TransferInfoResponse { pub amount: Uint128, pub token_address: [u8; 32], @@ -99,26 +99,22 @@ pub struct TransferInfoResponse { pub payload: Vec, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct ExternalIdResponse { pub token_id: TokenId, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct IsVaaRedeemedResponse { pub is_redeemed: bool, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct ChainRegistrationResponse { pub address: Binary, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct CompleteTransferResponse { // All addresses are bech32-encoded strings. @@ -132,7 +128,7 @@ pub struct CompleteTransferResponse { pub fee: Uint128, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[cw_serde] pub struct Asset { pub info: AssetInfo, pub amount: Uint128, @@ -140,8 +136,7 @@ pub struct Asset { /// AssetInfo contract_addr is usually passed from the cw20 hook /// so we can trust the contract_addr is properly validated. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum AssetInfo { Token { contract_addr: String }, NativeToken { denom: String }, diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/examples/wormchain_ibc_receiver_schema.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/examples/wormchain_ibc_receiver_schema.rs new file mode 100644 index 0000000000..5547fe0c24 --- /dev/null +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/examples/wormchain_ibc_receiver_schema.rs @@ -0,0 +1,11 @@ +use cosmwasm_schema::write_api; +use cosmwasm_std::Empty; +use wormchain_ibc_receiver::msg::{ExecuteMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: Empty, + execute: ExecuteMsg, + query: QueryMsg, + } +} \ No newline at end of file diff --git a/cosmwasm/contracts/wormhole-ibc/src/examples/wormhole_ibc_schema.rs b/cosmwasm/contracts/wormhole-ibc/src/examples/wormhole_ibc_schema.rs new file mode 100644 index 0000000000..07965c550b --- /dev/null +++ b/cosmwasm/contracts/wormhole-ibc/src/examples/wormhole_ibc_schema.rs @@ -0,0 +1,11 @@ +use cosmwasm_schema::write_api; +use cw_wormhole::msg::{InstantiateMsg, QueryMsg}; +use wormhole_ibc::msg::ExecuteMsg; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } +} \ No newline at end of file diff --git a/cosmwasm/contracts/wormhole/Cargo.toml b/cosmwasm/contracts/wormhole/Cargo.toml index 5c1dc2405a..2d5fdd9b96 100644 --- a/cosmwasm/contracts/wormhole/Cargo.toml +++ b/cosmwasm/contracts/wormhole/Cargo.toml @@ -21,6 +21,7 @@ default = ["full"] [dependencies] cosmwasm-std = { version = "1.0.0" } cosmwasm-storage = { version = "1.0.0" } +cosmwasm-schema = { version = "1.0.0" } schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } thiserror = { version = "1.0.31" } diff --git a/cosmwasm/contracts/wormhole/src/examples/wormhole_schema.rs b/cosmwasm/contracts/wormhole/src/examples/wormhole_schema.rs new file mode 100644 index 0000000000..c3a87e0017 --- /dev/null +++ b/cosmwasm/contracts/wormhole/src/examples/wormhole_schema.rs @@ -0,0 +1,10 @@ +use cosmwasm_schema::write_api; +use cw_wormhole::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } +} \ No newline at end of file diff --git a/cosmwasm/contracts/wormhole/src/msg.rs b/cosmwasm/contracts/wormhole/src/msg.rs index 8f9941cd9c..b2356d3a12 100644 --- a/cosmwasm/contracts/wormhole/src/msg.rs +++ b/cosmwasm/contracts/wormhole/src/msg.rs @@ -1,14 +1,13 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Binary, Coin}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use crate::state::{GuardianAddress, GuardianSetInfo}; +use crate::state::{GuardianAddress, GuardianSetInfo, ParsedVAA}; type HumanAddr = String; /// The instantiation parameters of the core bridge contract. See /// [`crate::state::ConfigInfo`] for more details on what these fields mean. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InstantiateMsg { pub gov_chain: u16, pub gov_address: Binary, @@ -21,47 +20,45 @@ pub struct InstantiateMsg { pub fee_denom: String, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum ExecuteMsg { SubmitVAA { vaa: Binary }, PostMessage { message: Binary, nonce: u32 }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct MigrateMsg {} -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] +#[derive(QueryResponses)] pub enum QueryMsg { + #[returns(GuardianSetInfoResponse)] GuardianSetInfo {}, + #[returns(ParsedVAA)] VerifyVAA { vaa: Binary, block_time: u64 }, + #[returns(GetStateResponse)] GetState {}, + #[returns(GetAddressHexResponse)] QueryAddressHex { address: HumanAddr }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct GuardianSetInfoResponse { pub guardian_set_index: u32, // Current guardian set index pub addresses: Vec, // List of querdian addresses } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct WrappedRegistryResponse { pub address: HumanAddr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct GetStateResponse { pub fee: Coin, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub struct GetAddressHexResponse { pub hex: String, }