Skip to content

Commit

Permalink
Switch to using cosmwasm-typescript-gen (#347)
Browse files Browse the repository at this point in the history
* Add latest ts types

* Remove old generated ts files

* Use cosmwasm-typescript-gen + Add ProposalModulesResponse to cw_core schema

* Remove tsconfig files

* Switch to cosmwasm-typescript-gen v 0.2.15

* Add ci step

* Fix ci step to use proper dir

* remove legacy ts files

* Upgrade cosmwasm-typescript-gen to 0.3.4 and fix more yarn build errors

* Fix missing schema exports

* Generate ts changes for latest main changes

* Regenerate types after rebasing main
  • Loading branch information
de-husk committed Jun 24, 2022
1 parent f38e1f3 commit a6da405
Show file tree
Hide file tree
Showing 129 changed files with 6,327 additions and 3,760 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ts_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

on: [push, pull_request]

name: Typescript Codegen

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Yarn install
run: yarn --cwd ./types install
- name: Yarn build
run: yarn --cwd ./types build
- name: Yarn codegen
run: yarn --cwd ./types codegen
- name: Check for ts changes
# fails if any changes not committed
run: git diff --exit-code .

3 changes: 2 additions & 1 deletion contracts/cw-core/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
export_schema(&schema_for!(AdminNominationResponse), &out_dir);

// Auto TS code generation expects the query return type as QueryNameResponse
// Here we map query resonses to the correct name
// Here we map query responses to the correct name
export_schema_with_title(&schema_for!(Option<Addr>), &out_dir, "AdminResponse");
export_schema_with_title(&schema_for!(Config), &out_dir, "ConfigResponse");
export_schema_with_title(
Expand All @@ -52,4 +52,5 @@ fn main() {
);
export_schema_with_title(&schema_for!(Vec<String>), &out_dir, "ListItemsResponse");
export_schema_with_title(&schema_for!(Addr), &out_dir, "VotingModuleResponse");
export_schema_with_title(&schema_for!(Vec<Addr>), &out_dir, "ProposalModulesResponse");
}
14 changes: 14 additions & 0 deletions contracts/cw-core/schema/proposal_modules_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ProposalModulesResponse",
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
},
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
}
}
}
5 changes: 3 additions & 2 deletions contracts/cw-named-groups/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::fs::create_dir_all;
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use cw_named_groups::msg::{
DumpResponse, ExecuteMsg, Group, InstantiateMsg, ListAddressesResponse, ListGroupsResponse,
QueryMsg,
DumpResponse, ExecuteMsg, Group, InstantiateMsg, IsAddressInGroupResponse,
ListAddressesResponse, ListGroupsResponse, QueryMsg,
};

fn main() {
Expand All @@ -24,4 +24,5 @@ fn main() {
export_schema(&schema_for!(DumpResponse), &out_dir);
export_schema(&schema_for!(ListGroupsResponse), &out_dir);
export_schema(&schema_for!(ListAddressesResponse), &out_dir);
export_schema(&schema_for!(IsAddressInGroupResponse), &out_dir);
}
13 changes: 13 additions & 0 deletions contracts/cw-named-groups/schema/is_address_in_group_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "IsAddressInGroupResponse",
"type": "object",
"required": [
"is_in_group"
],
"properties": {
"is_in_group": {
"type": "boolean"
}
}
}
7 changes: 6 additions & 1 deletion contracts/cw-names-registry/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};

use cw_names_registry::msg::{
ExecuteMsg, InstantiateMsg, IsNameAvailableToRegisterResponse, LookUpDaoByNameResponse,
LookUpNameByDaoResponse, QueryMsg,
};
use cw_names_registry::state::Config;

fn main() {
let mut out_dir = current_dir().unwrap();
Expand All @@ -20,4 +21,8 @@ fn main() {
export_schema(&schema_for!(IsNameAvailableToRegisterResponse), &out_dir);
export_schema(&schema_for!(LookUpDaoByNameResponse), &out_dir);
export_schema(&schema_for!(LookUpNameByDaoResponse), &out_dir);

// Auto TS code generation expects the query return type as QueryNameResponse
// Here we map query responses to the correct name
export_schema_with_title(&schema_for!(Config), &out_dir, "ConfigResponse");
}
79 changes: 79 additions & 0 deletions contracts/cw-names-registry/schema/config_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ConfigResponse",
"type": "object",
"required": [
"admin",
"payment_info"
],
"properties": {
"admin": {
"$ref": "#/definitions/Addr"
},
"payment_info": {
"$ref": "#/definitions/PaymentInfo"
}
},
"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"
},
"PaymentInfo": {
"oneOf": [
{
"type": "object",
"required": [
"native_payment"
],
"properties": {
"native_payment": {
"type": "object",
"required": [
"payment_amount",
"token_denom"
],
"properties": {
"payment_amount": {
"$ref": "#/definitions/Uint128"
},
"token_denom": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"cw20_payment"
],
"properties": {
"cw20_payment": {
"type": "object",
"required": [
"payment_amount",
"token_address"
],
"properties": {
"payment_amount": {
"$ref": "#/definitions/Uint128"
},
"token_address": {
"type": "string"
}
}
}
},
"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"
}
}
}
10 changes: 9 additions & 1 deletion contracts/cw20-stake-external-rewards/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};

use stake_cw20_external_rewards::msg::{
ExecuteMsg, InfoResponse, InstantiateMsg, PendingRewardsResponse, QueryMsg,
Expand All @@ -18,4 +18,12 @@ fn main() {
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(InfoResponse), &out_dir);
export_schema(&schema_for!(PendingRewardsResponse), &out_dir);

// Auto TS code generation expects the query return type as QueryNameResponse
// Here we map query resonses to the correct name
export_schema_with_title(
&schema_for!(PendingRewardsResponse),
&out_dir,
"GetPendingRewardsResponse",
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GetPendingRewardsResponse",
"type": "object",
"required": [
"address",
"denom",
"last_update_block",
"pending_rewards"
],
"properties": {
"address": {
"type": "string"
},
"denom": {
"$ref": "#/definitions/Denom"
},
"last_update_block": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"pending_rewards": {
"$ref": "#/definitions/Uint128"
}
},
"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"
},
"Denom": {
"oneOf": [
{
"type": "object",
"required": [
"native"
],
"properties": {
"native": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"cw20"
],
"properties": {
"cw20": {
"$ref": "#/definitions/Addr"
}
},
"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"
}
}
}
3 changes: 2 additions & 1 deletion contracts/cw20-stake-reward-distributor/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use stake_cw20_reward_distributor::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use stake_cw20_reward_distributor::msg::{ExecuteMsg, InfoResponse, InstantiateMsg, QueryMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
Expand All @@ -13,4 +13,5 @@ fn main() {
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(InfoResponse), &out_dir);
}
56 changes: 56 additions & 0 deletions contracts/cw20-stake-reward-distributor/schema/info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InfoResponse",
"type": "object",
"required": [
"balance",
"config",
"last_payment_block"
],
"properties": {
"balance": {
"$ref": "#/definitions/Uint128"
},
"config": {
"$ref": "#/definitions/Config"
},
"last_payment_block": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"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"
},
"Config": {
"type": "object",
"required": [
"owner",
"reward_rate",
"reward_token",
"staking_addr"
],
"properties": {
"owner": {
"$ref": "#/definitions/Addr"
},
"reward_rate": {
"$ref": "#/definitions/Uint128"
},
"reward_token": {
"$ref": "#/definitions/Addr"
},
"staking_addr": {
"$ref": "#/definitions/Addr"
}
}
},
"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"
}
}
}
8 changes: 6 additions & 2 deletions contracts/cw20-staked-balance-voting/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};
use cosmwasm_std::Addr;
use cw20_staked_balance_voting::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use cw20_staked_balance_voting::msg::{
ActiveThresholdResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg,
};
use cw_core_interface::voting::{
InfoResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
InfoResponse, IsActiveResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
};

fn main() {
Expand All @@ -22,6 +24,8 @@ fn main() {
export_schema(&schema_for!(InfoResponse), &out_dir);
export_schema(&schema_for!(TotalPowerAtHeightResponse), &out_dir);
export_schema(&schema_for!(VotingPowerAtHeightResponse), &out_dir);
export_schema(&schema_for!(ActiveThresholdResponse), &out_dir);
export_schema(&schema_for!(IsActiveResponse), &out_dir);

// Auto TS code generation expects the query return type as QueryNameResponse
// Here we map query resonses to the correct name
Expand Down

0 comments on commit a6da405

Please sign in to comment.