Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmwasm: add support for json schemas for all contracts #4118

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cosmwasm/Cargo.lock

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

1 change: 1 addition & 0 deletions cosmwasm/contracts/cw20-wrapped/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
36 changes: 19 additions & 17 deletions cosmwasm/contracts/cw20-wrapped/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,24 +17,22 @@ pub struct InstantiateMsg {
pub init_hook: Option<InitHook>,
}

#[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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
1 change: 1 addition & 0 deletions cosmwasm/contracts/mock-bridge-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
16 changes: 7 additions & 9 deletions cosmwasm/contracts/mock-bridge-integration/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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 },
}
1 change: 1 addition & 0 deletions cosmwasm/contracts/token-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 19 additions & 24 deletions cosmwasm/contracts/token-bridge/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, Uint128};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::token_address::{ExternalTokenId, TokenId};

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,
Expand All @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -99,26 +99,22 @@ pub struct TransferInfoResponse {
pub payload: Vec<u8>,
}

#[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.

Expand All @@ -132,16 +128,15 @@ pub struct CompleteTransferResponse {
pub fee: Uint128,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[cw_serde]
pub struct Asset {
pub info: AssetInfo,
pub amount: Uint128,
}

/// 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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
Original file line number Diff line number Diff line change
@@ -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,
}
}
1 change: 1 addition & 0 deletions cosmwasm/contracts/wormhole/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 10 additions & 0 deletions cosmwasm/contracts/wormhole/src/examples/wormhole_schema.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
Loading