diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.client.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.client.ts new file mode 100644 index 00000000..3194c8c0 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.client.ts @@ -0,0 +1,65 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { Coin, StdFee } from "@cosmjs/amino"; +import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types"; +export interface CwAdminFactoryReadOnlyInterface { + contractAddress: string; +} +export class CwAdminFactoryQueryClient implements CwAdminFactoryReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + } + +} +export interface CwAdminFactoryInterface { + contractAddress: string; + sender: string; + instantiateContractWithSelfAdmin: ({ + codeId, + instantiateMsg, + label + }: { + codeId: number; + instantiateMsg: Binary; + label: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; +} +export class CwAdminFactoryClient implements CwAdminFactoryInterface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.instantiateContractWithSelfAdmin = this.instantiateContractWithSelfAdmin.bind(this); + } + + instantiateContractWithSelfAdmin = async ({ + codeId, + instantiateMsg, + label + }: { + codeId: number; + instantiateMsg: Binary; + label: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + instantiate_contract_with_self_admin: { + code_id: codeId, + instantiate_msg: instantiateMsg, + label + } + }, fee, memo, funds); + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.message-composer.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.message-composer.ts new file mode 100644 index 00000000..6ff9c5fb --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.message-composer.ts @@ -0,0 +1,60 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { Coin } from "@cosmjs/amino"; +import { MsgExecuteContractEncodeObject } from "cosmwasm"; +import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import { toUtf8 } from "@cosmjs/encoding"; +import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types"; +export interface CwAdminFactoryMessage { + contractAddress: string; + sender: string; + instantiateContractWithSelfAdmin: ({ + codeId, + instantiateMsg, + label + }: { + codeId: number; + instantiateMsg: Binary; + label: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; +} +export class CwAdminFactoryMessageComposer implements CwAdminFactoryMessage { + sender: string; + contractAddress: string; + + constructor(sender: string, contractAddress: string) { + this.sender = sender; + this.contractAddress = contractAddress; + this.instantiateContractWithSelfAdmin = this.instantiateContractWithSelfAdmin.bind(this); + } + + instantiateContractWithSelfAdmin = ({ + codeId, + instantiateMsg, + label + }: { + codeId: number; + instantiateMsg: Binary; + label: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + instantiate_contract_with_self_admin: { + code_id: codeId, + instantiate_msg: instantiateMsg, + label + } + })), + funds + }) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.msg-builder.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.msg-builder.ts new file mode 100644 index 00000000..1e03ab7b --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.msg-builder.ts @@ -0,0 +1,25 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types"; +import { CamelCasedProperties } from "type-fest"; +export abstract class CwAdminFactoryExecuteMsgBuilder { + static instantiateContractWithSelfAdmin = ({ + codeId, + instantiateMsg, + label + }: CamelCasedProperties["instantiate_contract_with_self_admin"]>): ExecuteMsg => { + return { + instantiate_contract_with_self_admin: ({ + code_id: codeId, + instantiate_msg: instantiateMsg, + label + } as const) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.react-query.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.react-query.ts new file mode 100644 index 00000000..be2aa1b7 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.react-query.ts @@ -0,0 +1,13 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { UseQueryOptions } from "react-query"; +import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types"; +import { CwAdminFactoryQueryClient } from "./CwAdminFactory.client"; +export interface CwAdminFactoryReactQuery { + client: CwAdminFactoryQueryClient; + options?: UseQueryOptions; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.recoil.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.recoil.ts new file mode 100644 index 00000000..eddb158c --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.recoil.ts @@ -0,0 +1,24 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { selectorFamily } from "recoil"; +import { cosmWasmClient } from "./chain"; +import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types"; +import { CwAdminFactoryQueryClient } from "./CwAdminFactory.client"; +type QueryClientParams = { + contractAddress: string; +}; +export const queryClient = selectorFamily({ + key: "cwAdminFactoryQueryClient", + get: ({ + contractAddress + }) => ({ + get + }) => { + const client = get(cosmWasmClient); + return new CwAdminFactoryQueryClient(client, contractAddress); + } +}); \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwAdminFactory.types.ts b/__output__/builder/bundler_test/contracts/CwAdminFactory.types.ts new file mode 100644 index 00000000..11b47d44 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwAdminFactory.types.ts @@ -0,0 +1,19 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +export type ExecuteMsg = { + instantiate_contract_with_self_admin: { + code_id: number; + instantiate_msg: Binary; + label: string; + [k: string]: unknown; + }; +}; +export type Binary = string; +export interface InstantiateMsg { + [k: string]: unknown; +} +export type QueryMsg = string; \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.client.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.client.ts new file mode 100644 index 00000000..59e6506b --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.client.ts @@ -0,0 +1,251 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { Coin, StdFee } from "@cosmjs/amino"; +import { Addr, PaymentInfo, Uint128, ConfigResponse, ExecuteMsg, Binary, Cw20ReceiveMsg, GetRegistrationResponse, Registration, InfoForCodeIdResponse, InstantiateMsg, ListRegistrationsResponse, QueryMsg, ReceiveMsg } from "./CwCodeIdRegistry.types"; +export interface CwCodeIdRegistryReadOnlyInterface { + contractAddress: string; + config: () => Promise; + getRegistration: ({ + chainId, + name, + version + }: { + chainId: string; + name: string; + version?: string; + }) => Promise; + infoForCodeId: ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }) => Promise; + listRegistrations: ({ + chainId, + name + }: { + chainId: string; + name: string; + }) => Promise; +} +export class CwCodeIdRegistryQueryClient implements CwCodeIdRegistryReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.config = this.config.bind(this); + this.getRegistration = this.getRegistration.bind(this); + this.infoForCodeId = this.infoForCodeId.bind(this); + this.listRegistrations = this.listRegistrations.bind(this); + } + + config = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + config: {} + }); + }; + getRegistration = async ({ + chainId, + name, + version + }: { + chainId: string; + name: string; + version?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + get_registration: { + chain_id: chainId, + name, + version + } + }); + }; + infoForCodeId = async ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + info_for_code_id: { + chain_id: chainId, + code_id: codeId + } + }); + }; + listRegistrations = async ({ + chainId, + name + }: { + chainId: string; + name: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_registrations: { + chain_id: chainId, + name + } + }); + }; +} +export interface CwCodeIdRegistryInterface { + contractAddress: string; + sender: string; + receive: ({ + amount, + msg, + sender + }: { + amount: Uint128; + msg: Binary; + sender: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + register: ({ + chainId, + checksum, + codeId, + name, + version + }: { + chainId: string; + checksum: string; + codeId: number; + name: string; + version: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + setOwner: ({ + chainId, + name, + owner + }: { + chainId: string; + name: string; + owner?: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + unregister: ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateConfig: ({ + admin, + paymentInfo + }: { + admin?: string; + paymentInfo?: PaymentInfo; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; +} +export class CwCodeIdRegistryClient implements CwCodeIdRegistryInterface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.receive = this.receive.bind(this); + this.register = this.register.bind(this); + this.setOwner = this.setOwner.bind(this); + this.unregister = this.unregister.bind(this); + this.updateConfig = this.updateConfig.bind(this); + } + + receive = async ({ + amount, + msg, + sender + }: { + amount: Uint128; + msg: Binary; + sender: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + receive: { + amount, + msg, + sender + } + }, fee, memo, funds); + }; + register = async ({ + chainId, + checksum, + codeId, + name, + version + }: { + chainId: string; + checksum: string; + codeId: number; + name: string; + version: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + register: { + chain_id: chainId, + checksum, + code_id: codeId, + name, + version + } + }, fee, memo, funds); + }; + setOwner = async ({ + chainId, + name, + owner + }: { + chainId: string; + name: string; + owner?: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + set_owner: { + chain_id: chainId, + name, + owner + } + }, fee, memo, funds); + }; + unregister = async ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + unregister: { + chain_id: chainId, + code_id: codeId + } + }, fee, memo, funds); + }; + updateConfig = async ({ + admin, + paymentInfo + }: { + admin?: string; + paymentInfo?: PaymentInfo; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_config: { + admin, + payment_info: paymentInfo + } + }, fee, memo, funds); + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.message-composer.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.message-composer.ts new file mode 100644 index 00000000..2590da00 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.message-composer.ts @@ -0,0 +1,200 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { Coin } from "@cosmjs/amino"; +import { MsgExecuteContractEncodeObject } from "cosmwasm"; +import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import { toUtf8 } from "@cosmjs/encoding"; +import { Addr, PaymentInfo, Uint128, ConfigResponse, ExecuteMsg, Binary, Cw20ReceiveMsg, GetRegistrationResponse, Registration, InfoForCodeIdResponse, InstantiateMsg, ListRegistrationsResponse, QueryMsg, ReceiveMsg } from "./CwCodeIdRegistry.types"; +export interface CwCodeIdRegistryMessage { + contractAddress: string; + sender: string; + receive: ({ + amount, + msg, + sender + }: { + amount: Uint128; + msg: Binary; + sender: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + register: ({ + chainId, + checksum, + codeId, + name, + version + }: { + chainId: string; + checksum: string; + codeId: number; + name: string; + version: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + setOwner: ({ + chainId, + name, + owner + }: { + chainId: string; + name: string; + owner?: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + unregister: ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateConfig: ({ + admin, + paymentInfo + }: { + admin?: string; + paymentInfo?: PaymentInfo; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; +} +export class CwCodeIdRegistryMessageComposer implements CwCodeIdRegistryMessage { + sender: string; + contractAddress: string; + + constructor(sender: string, contractAddress: string) { + this.sender = sender; + this.contractAddress = contractAddress; + this.receive = this.receive.bind(this); + this.register = this.register.bind(this); + this.setOwner = this.setOwner.bind(this); + this.unregister = this.unregister.bind(this); + this.updateConfig = this.updateConfig.bind(this); + } + + receive = ({ + amount, + msg, + sender + }: { + amount: Uint128; + msg: Binary; + sender: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + receive: { + amount, + msg, + sender + } + })), + funds + }) + }; + }; + register = ({ + chainId, + checksum, + codeId, + name, + version + }: { + chainId: string; + checksum: string; + codeId: number; + name: string; + version: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + register: { + chain_id: chainId, + checksum, + code_id: codeId, + name, + version + } + })), + funds + }) + }; + }; + setOwner = ({ + chainId, + name, + owner + }: { + chainId: string; + name: string; + owner?: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + set_owner: { + chain_id: chainId, + name, + owner + } + })), + funds + }) + }; + }; + unregister = ({ + chainId, + codeId + }: { + chainId: string; + codeId: number; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + unregister: { + chain_id: chainId, + code_id: codeId + } + })), + funds + }) + }; + }; + updateConfig = ({ + admin, + paymentInfo + }: { + admin?: string; + paymentInfo?: PaymentInfo; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_config: { + admin, + payment_info: paymentInfo + } + })), + funds + }) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.msg-builder.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.msg-builder.ts new file mode 100644 index 00000000..3e15defb --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.msg-builder.ts @@ -0,0 +1,133 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { Addr, PaymentInfo, Uint128, ConfigResponse, ExecuteMsg, Binary, Cw20ReceiveMsg, GetRegistrationResponse, Registration, InfoForCodeIdResponse, InstantiateMsg, ListRegistrationsResponse, QueryMsg, ReceiveMsg } from "./CwCodeIdRegistry.types"; +import { CamelCasedProperties } from "type-fest"; +export abstract class CwCodeIdRegistryExecuteMsgBuilder { + static receive = ({ + amount, + msg, + sender + }: CamelCasedProperties["receive"]>): ExecuteMsg => { + return { + receive: ({ + amount, + msg, + sender + } as const) + }; + }; + static register = ({ + chainId, + checksum, + codeId, + name, + version + }: CamelCasedProperties["register"]>): ExecuteMsg => { + return { + register: ({ + chain_id: chainId, + checksum, + code_id: codeId, + name, + version + } as const) + }; + }; + static setOwner = ({ + chainId, + name, + owner + }: CamelCasedProperties["set_owner"]>): ExecuteMsg => { + return { + set_owner: ({ + chain_id: chainId, + name, + owner + } as const) + }; + }; + static unregister = ({ + chainId, + codeId + }: CamelCasedProperties["unregister"]>): ExecuteMsg => { + return { + unregister: ({ + chain_id: chainId, + code_id: codeId + } as const) + }; + }; + static updateConfig = ({ + admin, + paymentInfo + }: CamelCasedProperties["update_config"]>): ExecuteMsg => { + return { + update_config: ({ + admin, + payment_info: paymentInfo + } as const) + }; + }; +} +export abstract class CwCodeIdRegistryQueryMsgBuilder { + static config = (): QueryMsg => { + return { + config: ({} as const) + }; + }; + static getRegistration = ({ + chainId, + name, + version + }: CamelCasedProperties["get_registration"]>): QueryMsg => { + return { + get_registration: ({ + chain_id: chainId, + name, + version + } as const) + }; + }; + static infoForCodeId = ({ + chainId, + codeId + }: CamelCasedProperties["info_for_code_id"]>): QueryMsg => { + return { + info_for_code_id: ({ + chain_id: chainId, + code_id: codeId + } as const) + }; + }; + static listRegistrations = ({ + chainId, + name + }: CamelCasedProperties["list_registrations"]>): QueryMsg => { + return { + list_registrations: ({ + chain_id: chainId, + name + } as const) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.react-query.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.react-query.ts new file mode 100644 index 00000000..d2bcdc8f --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.react-query.ts @@ -0,0 +1,70 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { UseQueryOptions, useQuery } from "react-query"; +import { Addr, PaymentInfo, Uint128, ConfigResponse, ExecuteMsg, Binary, Cw20ReceiveMsg, GetRegistrationResponse, Registration, InfoForCodeIdResponse, InstantiateMsg, ListRegistrationsResponse, QueryMsg, ReceiveMsg } from "./CwCodeIdRegistry.types"; +import { CwCodeIdRegistryQueryClient } from "./CwCodeIdRegistry.client"; +export interface CwCodeIdRegistryReactQuery { + client: CwCodeIdRegistryQueryClient; + options?: UseQueryOptions; +} +export interface CwCodeIdRegistryListRegistrationsQuery extends CwCodeIdRegistryReactQuery { + args: { + chainId: string; + name: string; + }; +} +export function useCwCodeIdRegistryListRegistrationsQuery({ + client, + args, + options +}: CwCodeIdRegistryListRegistrationsQuery) { + return useQuery(["cwCodeIdRegistryListRegistrations", client.contractAddress, JSON.stringify(args)], () => client.listRegistrations({ + chainId: args.chainId, + name: args.name + }), options); +} +export interface CwCodeIdRegistryInfoForCodeIdQuery extends CwCodeIdRegistryReactQuery { + args: { + chainId: string; + codeId: number; + }; +} +export function useCwCodeIdRegistryInfoForCodeIdQuery({ + client, + args, + options +}: CwCodeIdRegistryInfoForCodeIdQuery) { + return useQuery(["cwCodeIdRegistryInfoForCodeId", client.contractAddress, JSON.stringify(args)], () => client.infoForCodeId({ + chainId: args.chainId, + codeId: args.codeId + }), options); +} +export interface CwCodeIdRegistryGetRegistrationQuery extends CwCodeIdRegistryReactQuery { + args: { + chainId: string; + name: string; + version?: string; + }; +} +export function useCwCodeIdRegistryGetRegistrationQuery({ + client, + args, + options +}: CwCodeIdRegistryGetRegistrationQuery) { + return useQuery(["cwCodeIdRegistryGetRegistration", client.contractAddress, JSON.stringify(args)], () => client.getRegistration({ + chainId: args.chainId, + name: args.name, + version: args.version + }), options); +} +export interface CwCodeIdRegistryConfigQuery extends CwCodeIdRegistryReactQuery {} +export function useCwCodeIdRegistryConfigQuery({ + client, + options +}: CwCodeIdRegistryConfigQuery) { + return useQuery(["cwCodeIdRegistryConfig", client.contractAddress], () => client.config(), options); +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.recoil.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.recoil.ts new file mode 100644 index 00000000..c76fd755 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.recoil.ts @@ -0,0 +1,80 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { selectorFamily } from "recoil"; +import { cosmWasmClient } from "./chain"; +import { Addr, PaymentInfo, Uint128, ConfigResponse, ExecuteMsg, Binary, Cw20ReceiveMsg, GetRegistrationResponse, Registration, InfoForCodeIdResponse, InstantiateMsg, ListRegistrationsResponse, QueryMsg, ReceiveMsg } from "./CwCodeIdRegistry.types"; +import { CwCodeIdRegistryQueryClient } from "./CwCodeIdRegistry.client"; +type QueryClientParams = { + contractAddress: string; +}; +export const queryClient = selectorFamily({ + key: "cwCodeIdRegistryQueryClient", + get: ({ + contractAddress + }) => ({ + get + }) => { + const client = get(cosmWasmClient); + return new CwCodeIdRegistryQueryClient(client, contractAddress); + } +}); +export const configSelector = selectorFamily; +}>({ + key: "cwCodeIdRegistryConfig", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.config(...params); + } +}); +export const getRegistrationSelector = selectorFamily; +}>({ + key: "cwCodeIdRegistryGetRegistration", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.getRegistration(...params); + } +}); +export const infoForCodeIdSelector = selectorFamily; +}>({ + key: "cwCodeIdRegistryInfoForCodeId", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.infoForCodeId(...params); + } +}); +export const listRegistrationsSelector = selectorFamily; +}>({ + key: "cwCodeIdRegistryListRegistrations", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.listRegistrations(...params); + } +}); \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.types.ts b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.types.ts new file mode 100644 index 00000000..46a8c284 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwCodeIdRegistry.types.ts @@ -0,0 +1,109 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +export type Addr = string; +export type PaymentInfo = { + none: {}; +} | { + native_payment: { + payment_amount: Uint128; + token_denom: string; + }; +} | { + cw20_payment: { + payment_amount: Uint128; + token_address: string; + }; +}; +export type Uint128 = string; +export interface ConfigResponse { + admin: Addr; + payment_info: PaymentInfo; +} +export type ExecuteMsg = { + receive: Cw20ReceiveMsg; +} | { + register: { + chain_id: string; + checksum: string; + code_id: number; + name: string; + version: string; + }; +} | { + set_owner: { + chain_id: string; + name: string; + owner?: string | null; + }; +} | { + unregister: { + chain_id: string; + code_id: number; + }; +} | { + update_config: { + admin?: string | null; + payment_info?: PaymentInfo | null; + }; +}; +export type Binary = string; +export interface Cw20ReceiveMsg { + amount: Uint128; + msg: Binary; + sender: string; + [k: string]: unknown; +} +export interface GetRegistrationResponse { + registration: Registration; +} +export interface Registration { + checksum: string; + code_id: number; + registered_by: Addr; + version: string; +} +export interface InfoForCodeIdResponse { + checksum: string; + name: string; + registered_by: Addr; + version: string; +} +export interface InstantiateMsg { + admin: string; + payment_info: PaymentInfo; +} +export interface ListRegistrationsResponse { + registrations: Registration[]; +} +export type QueryMsg = { + config: {}; +} | { + get_registration: { + chain_id: string; + name: string; + version?: string | null; + }; +} | { + info_for_code_id: { + chain_id: string; + code_id: number; + }; +} | { + list_registrations: { + chain_id: string; + name: string; + }; +}; +export type ReceiveMsg = { + register: { + chain_id: string; + checksum: string; + code_id: number; + name: string; + version: string; + }; +}; \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.client.ts b/__output__/builder/bundler_test/contracts/CwSingle.client.ts new file mode 100644 index 00000000..05c0dc73 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.client.ts @@ -0,0 +1,381 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Addr, Uint128, Duration, Threshold, PercentageThreshold, Decimal, ConfigResponse, CheckedDepositInfo, ExecuteMsg, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, Timestamp, Uint64, WasmMsg, GovMsg, VoteOption, Vote, DepositToken, Coin, Empty, IbcTimeout, IbcTimeoutBlock, DepositInfo, GovernanceModulesResponse, InfoResponse, ContractVersion, InstantiateMsg, Expiration, Status, ListProposalsResponse, ProposalResponse, Proposal, Votes, ListVotesResponse, VoteInfo, MigrateMsg, ProposalCountResponse, ProposalHooksResponse, QueryMsg, ReverseProposalsResponse, VoteHooksResponse, VoteResponse } from "./CwSingle.types"; +export interface CwSingleReadOnlyInterface { + contractAddress: string; + config: () => Promise; + proposal: ({ + proposalId + }: { + proposalId: number; + }) => Promise; + listProposals: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: number; + }) => Promise; + reverseProposals: ({ + limit, + startBefore + }: { + limit?: number; + startBefore?: number; + }) => Promise; + proposalCount: () => Promise; + vote: ({ + proposalId, + voter + }: { + proposalId: number; + voter: string; + }) => Promise; + listVotes: ({ + limit, + proposalId, + startAfter + }: { + limit?: number; + proposalId: number; + startAfter?: string; + }) => Promise; + proposalHooks: () => Promise; + voteHooks: () => Promise; + info: () => Promise; +} +export class CwSingleQueryClient implements CwSingleReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.config = this.config.bind(this); + this.proposal = this.proposal.bind(this); + this.listProposals = this.listProposals.bind(this); + this.reverseProposals = this.reverseProposals.bind(this); + this.proposalCount = this.proposalCount.bind(this); + this.vote = this.vote.bind(this); + this.listVotes = this.listVotes.bind(this); + this.proposalHooks = this.proposalHooks.bind(this); + this.voteHooks = this.voteHooks.bind(this); + this.info = this.info.bind(this); + } + + config = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + config: {} + }); + }; + proposal = async ({ + proposalId + }: { + proposalId: number; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + proposal: { + proposal_id: proposalId + } + }); + }; + listProposals = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: number; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_proposals: { + limit, + start_after: startAfter + } + }); + }; + reverseProposals = async ({ + limit, + startBefore + }: { + limit?: number; + startBefore?: number; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + reverse_proposals: { + limit, + start_before: startBefore + } + }); + }; + proposalCount = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + proposal_count: {} + }); + }; + vote = async ({ + proposalId, + voter + }: { + proposalId: number; + voter: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + vote: { + proposal_id: proposalId, + voter + } + }); + }; + listVotes = async ({ + limit, + proposalId, + startAfter + }: { + limit?: number; + proposalId: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_votes: { + limit, + proposal_id: proposalId, + start_after: startAfter + } + }); + }; + proposalHooks = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + proposal_hooks: {} + }); + }; + voteHooks = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + vote_hooks: {} + }); + }; + info = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + info: {} + }); + }; +} +export interface CwSingleInterface { + contractAddress: string; + sender: string; + propose: ({ + description, + msgs, + title + }: { + description: string; + msgs: CosmosMsgForEmpty[]; + title: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + vote: ({ + proposalId, + vote + }: { + proposalId: number; + vote: Vote; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + execute: ({ + proposalId + }: { + proposalId: number; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + close: ({ + proposalId + }: { + proposalId: number; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateConfig: ({ + allowRevoting, + dao, + depositInfo, + maxVotingPeriod, + minVotingPeriod, + onlyMembersExecute, + threshold + }: { + allowRevoting: boolean; + dao: string; + depositInfo?: DepositInfo; + maxVotingPeriod: Duration; + minVotingPeriod?: Duration; + onlyMembersExecute: boolean; + threshold: Threshold; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + addProposalHook: ({ + address + }: { + address: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + removeProposalHook: ({ + address + }: { + address: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + addVoteHook: ({ + address + }: { + address: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + removeVoteHook: ({ + address + }: { + address: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; +} +export class CwSingleClient implements CwSingleInterface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.propose = this.propose.bind(this); + this.vote = this.vote.bind(this); + this.execute = this.execute.bind(this); + this.close = this.close.bind(this); + this.updateConfig = this.updateConfig.bind(this); + this.addProposalHook = this.addProposalHook.bind(this); + this.removeProposalHook = this.removeProposalHook.bind(this); + this.addVoteHook = this.addVoteHook.bind(this); + this.removeVoteHook = this.removeVoteHook.bind(this); + } + + propose = async ({ + description, + msgs, + title + }: { + description: string; + msgs: CosmosMsgForEmpty[]; + title: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + propose: { + description, + msgs, + title + } + }, fee, memo, funds); + }; + vote = async ({ + proposalId, + vote + }: { + proposalId: number; + vote: Vote; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + vote: { + proposal_id: proposalId, + vote + } + }, fee, memo, funds); + }; + execute = async ({ + proposalId + }: { + proposalId: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + execute: { + proposal_id: proposalId + } + }, fee, memo, funds); + }; + close = async ({ + proposalId + }: { + proposalId: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + close: { + proposal_id: proposalId + } + }, fee, memo, funds); + }; + updateConfig = async ({ + allowRevoting, + dao, + depositInfo, + maxVotingPeriod, + minVotingPeriod, + onlyMembersExecute, + threshold + }: { + allowRevoting: boolean; + dao: string; + depositInfo?: DepositInfo; + maxVotingPeriod: Duration; + minVotingPeriod?: Duration; + onlyMembersExecute: boolean; + threshold: Threshold; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_config: { + allow_revoting: allowRevoting, + dao, + deposit_info: depositInfo, + max_voting_period: maxVotingPeriod, + min_voting_period: minVotingPeriod, + only_members_execute: onlyMembersExecute, + threshold + } + }, fee, memo, funds); + }; + addProposalHook = async ({ + address + }: { + address: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + add_proposal_hook: { + address + } + }, fee, memo, funds); + }; + removeProposalHook = async ({ + address + }: { + address: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + remove_proposal_hook: { + address + } + }, fee, memo, funds); + }; + addVoteHook = async ({ + address + }: { + address: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + add_vote_hook: { + address + } + }, fee, memo, funds); + }; + removeVoteHook = async ({ + address + }: { + address: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + remove_vote_hook: { + address + } + }, fee, memo, funds); + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.message-composer.ts b/__output__/builder/bundler_test/contracts/CwSingle.message-composer.ts new file mode 100644 index 00000000..0a8436fc --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.message-composer.ts @@ -0,0 +1,294 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { MsgExecuteContractEncodeObject } from "cosmwasm"; +import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import { toUtf8 } from "@cosmjs/encoding"; +import { Addr, Uint128, Duration, Threshold, PercentageThreshold, Decimal, ConfigResponse, CheckedDepositInfo, ExecuteMsg, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, Timestamp, Uint64, WasmMsg, GovMsg, VoteOption, Vote, DepositToken, Coin, Empty, IbcTimeout, IbcTimeoutBlock, DepositInfo, GovernanceModulesResponse, InfoResponse, ContractVersion, InstantiateMsg, Expiration, Status, ListProposalsResponse, ProposalResponse, Proposal, Votes, ListVotesResponse, VoteInfo, MigrateMsg, ProposalCountResponse, ProposalHooksResponse, QueryMsg, ReverseProposalsResponse, VoteHooksResponse, VoteResponse } from "./CwSingle.types"; +export interface CwSingleMessage { + contractAddress: string; + sender: string; + propose: ({ + description, + msgs, + title + }: { + description: string; + msgs: CosmosMsgForEmpty[]; + title: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + vote: ({ + proposalId, + vote + }: { + proposalId: number; + vote: Vote; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + execute: ({ + proposalId + }: { + proposalId: number; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + close: ({ + proposalId + }: { + proposalId: number; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateConfig: ({ + allowRevoting, + dao, + depositInfo, + maxVotingPeriod, + minVotingPeriod, + onlyMembersExecute, + threshold + }: { + allowRevoting: boolean; + dao: string; + depositInfo?: DepositInfo; + maxVotingPeriod: Duration; + minVotingPeriod?: Duration; + onlyMembersExecute: boolean; + threshold: Threshold; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + addProposalHook: ({ + address + }: { + address: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + removeProposalHook: ({ + address + }: { + address: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + addVoteHook: ({ + address + }: { + address: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + removeVoteHook: ({ + address + }: { + address: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; +} +export class CwSingleMessageComposer implements CwSingleMessage { + sender: string; + contractAddress: string; + + constructor(sender: string, contractAddress: string) { + this.sender = sender; + this.contractAddress = contractAddress; + this.propose = this.propose.bind(this); + this.vote = this.vote.bind(this); + this.execute = this.execute.bind(this); + this.close = this.close.bind(this); + this.updateConfig = this.updateConfig.bind(this); + this.addProposalHook = this.addProposalHook.bind(this); + this.removeProposalHook = this.removeProposalHook.bind(this); + this.addVoteHook = this.addVoteHook.bind(this); + this.removeVoteHook = this.removeVoteHook.bind(this); + } + + propose = ({ + description, + msgs, + title + }: { + description: string; + msgs: CosmosMsgForEmpty[]; + title: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + propose: { + description, + msgs, + title + } + })), + funds + }) + }; + }; + vote = ({ + proposalId, + vote + }: { + proposalId: number; + vote: Vote; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + vote: { + proposal_id: proposalId, + vote + } + })), + funds + }) + }; + }; + execute = ({ + proposalId + }: { + proposalId: number; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + execute: { + proposal_id: proposalId + } + })), + funds + }) + }; + }; + close = ({ + proposalId + }: { + proposalId: number; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + close: { + proposal_id: proposalId + } + })), + funds + }) + }; + }; + updateConfig = ({ + allowRevoting, + dao, + depositInfo, + maxVotingPeriod, + minVotingPeriod, + onlyMembersExecute, + threshold + }: { + allowRevoting: boolean; + dao: string; + depositInfo?: DepositInfo; + maxVotingPeriod: Duration; + minVotingPeriod?: Duration; + onlyMembersExecute: boolean; + threshold: Threshold; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_config: { + allow_revoting: allowRevoting, + dao, + deposit_info: depositInfo, + max_voting_period: maxVotingPeriod, + min_voting_period: minVotingPeriod, + only_members_execute: onlyMembersExecute, + threshold + } + })), + funds + }) + }; + }; + addProposalHook = ({ + address + }: { + address: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + add_proposal_hook: { + address + } + })), + funds + }) + }; + }; + removeProposalHook = ({ + address + }: { + address: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + remove_proposal_hook: { + address + } + })), + funds + }) + }; + }; + addVoteHook = ({ + address + }: { + address: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + add_vote_hook: { + address + } + })), + funds + }) + }; + }; + removeVoteHook = ({ + address + }: { + address: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + remove_vote_hook: { + address + } + })), + funds + }) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.msg-builder.ts b/__output__/builder/bundler_test/contracts/CwSingle.msg-builder.ts new file mode 100644 index 00000000..1859f108 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.msg-builder.ts @@ -0,0 +1,219 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { Addr, Uint128, Duration, Threshold, PercentageThreshold, Decimal, ConfigResponse, CheckedDepositInfo, ExecuteMsg, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, Timestamp, Uint64, WasmMsg, GovMsg, VoteOption, Vote, DepositToken, Coin, Empty, IbcTimeout, IbcTimeoutBlock, DepositInfo, GovernanceModulesResponse, InfoResponse, ContractVersion, InstantiateMsg, Expiration, Status, ListProposalsResponse, ProposalResponse, Proposal, Votes, ListVotesResponse, VoteInfo, MigrateMsg, ProposalCountResponse, ProposalHooksResponse, QueryMsg, ReverseProposalsResponse, VoteHooksResponse, VoteResponse } from "./CwSingle.types"; +import { CamelCasedProperties } from "type-fest"; +export abstract class CwSingleExecuteMsgBuilder { + static propose = ({ + description, + msgs, + title + }: CamelCasedProperties["propose"]>): ExecuteMsg => { + return { + propose: ({ + description, + msgs, + title + } as const) + }; + }; + static vote = ({ + proposalId, + vote + }: CamelCasedProperties["vote"]>): ExecuteMsg => { + return { + vote: ({ + proposal_id: proposalId, + vote + } as const) + }; + }; + static execute = ({ + proposalId + }: CamelCasedProperties["execute"]>): ExecuteMsg => { + return { + execute: ({ + proposal_id: proposalId + } as const) + }; + }; + static close = ({ + proposalId + }: CamelCasedProperties["close"]>): ExecuteMsg => { + return { + close: ({ + proposal_id: proposalId + } as const) + }; + }; + static updateConfig = ({ + allowRevoting, + dao, + depositInfo, + maxVotingPeriod, + minVotingPeriod, + onlyMembersExecute, + threshold + }: CamelCasedProperties["update_config"]>): ExecuteMsg => { + return { + update_config: ({ + allow_revoting: allowRevoting, + dao, + deposit_info: depositInfo, + max_voting_period: maxVotingPeriod, + min_voting_period: minVotingPeriod, + only_members_execute: onlyMembersExecute, + threshold + } as const) + }; + }; + static addProposalHook = ({ + address + }: CamelCasedProperties["add_proposal_hook"]>): ExecuteMsg => { + return { + add_proposal_hook: ({ + address + } as const) + }; + }; + static removeProposalHook = ({ + address + }: CamelCasedProperties["remove_proposal_hook"]>): ExecuteMsg => { + return { + remove_proposal_hook: ({ + address + } as const) + }; + }; + static addVoteHook = ({ + address + }: CamelCasedProperties["add_vote_hook"]>): ExecuteMsg => { + return { + add_vote_hook: ({ + address + } as const) + }; + }; + static removeVoteHook = ({ + address + }: CamelCasedProperties["remove_vote_hook"]>): ExecuteMsg => { + return { + remove_vote_hook: ({ + address + } as const) + }; + }; +} +export abstract class CwSingleQueryMsgBuilder { + static config = (): QueryMsg => { + return { + config: ({} as const) + }; + }; + static proposal = ({ + proposalId + }: CamelCasedProperties["proposal"]>): QueryMsg => { + return { + proposal: ({ + proposal_id: proposalId + } as const) + }; + }; + static listProposals = ({ + limit, + startAfter + }: CamelCasedProperties["list_proposals"]>): QueryMsg => { + return { + list_proposals: ({ + limit, + start_after: startAfter + } as const) + }; + }; + static reverseProposals = ({ + limit, + startBefore + }: CamelCasedProperties["reverse_proposals"]>): QueryMsg => { + return { + reverse_proposals: ({ + limit, + start_before: startBefore + } as const) + }; + }; + static proposalCount = (): QueryMsg => { + return { + proposal_count: ({} as const) + }; + }; + static vote = ({ + proposalId, + voter + }: CamelCasedProperties["vote"]>): QueryMsg => { + return { + vote: ({ + proposal_id: proposalId, + voter + } as const) + }; + }; + static listVotes = ({ + limit, + proposalId, + startAfter + }: CamelCasedProperties["list_votes"]>): QueryMsg => { + return { + list_votes: ({ + limit, + proposal_id: proposalId, + start_after: startAfter + } as const) + }; + }; + static proposalHooks = (): QueryMsg => { + return { + proposal_hooks: ({} as const) + }; + }; + static voteHooks = (): QueryMsg => { + return { + vote_hooks: ({} as const) + }; + }; + static info = (): QueryMsg => { + return { + info: ({} as const) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.react-query.ts b/__output__/builder/bundler_test/contracts/CwSingle.react-query.ts new file mode 100644 index 00000000..874561b4 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.react-query.ts @@ -0,0 +1,128 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { UseQueryOptions, useQuery } from "react-query"; +import { Addr, Uint128, Duration, Threshold, PercentageThreshold, Decimal, ConfigResponse, CheckedDepositInfo, ExecuteMsg, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, Timestamp, Uint64, WasmMsg, GovMsg, VoteOption, Vote, DepositToken, Coin, Empty, IbcTimeout, IbcTimeoutBlock, DepositInfo, GovernanceModulesResponse, InfoResponse, ContractVersion, InstantiateMsg, Expiration, Status, ListProposalsResponse, ProposalResponse, Proposal, Votes, ListVotesResponse, VoteInfo, MigrateMsg, ProposalCountResponse, ProposalHooksResponse, QueryMsg, ReverseProposalsResponse, VoteHooksResponse, VoteResponse } from "./CwSingle.types"; +import { CwSingleQueryClient } from "./CwSingle.client"; +export interface CwSingleReactQuery { + client: CwSingleQueryClient; + options?: UseQueryOptions; +} +export interface CwSingleInfoQuery extends CwSingleReactQuery {} +export function useCwSingleInfoQuery({ + client, + options +}: CwSingleInfoQuery) { + return useQuery(["cwSingleInfo", client.contractAddress], () => client.info(), options); +} +export interface CwSingleVoteHooksQuery extends CwSingleReactQuery {} +export function useCwSingleVoteHooksQuery({ + client, + options +}: CwSingleVoteHooksQuery) { + return useQuery(["cwSingleVoteHooks", client.contractAddress], () => client.voteHooks(), options); +} +export interface CwSingleProposalHooksQuery extends CwSingleReactQuery {} +export function useCwSingleProposalHooksQuery({ + client, + options +}: CwSingleProposalHooksQuery) { + return useQuery(["cwSingleProposalHooks", client.contractAddress], () => client.proposalHooks(), options); +} +export interface CwSingleListVotesQuery extends CwSingleReactQuery { + args: { + limit?: number; + proposalId: number; + startAfter?: string; + }; +} +export function useCwSingleListVotesQuery({ + client, + args, + options +}: CwSingleListVotesQuery) { + return useQuery(["cwSingleListVotes", client.contractAddress, JSON.stringify(args)], () => client.listVotes({ + limit: args.limit, + proposalId: args.proposalId, + startAfter: args.startAfter + }), options); +} +export interface CwSingleVoteQuery extends CwSingleReactQuery { + args: { + proposalId: number; + voter: string; + }; +} +export function useCwSingleVoteQuery({ + client, + args, + options +}: CwSingleVoteQuery) { + return useQuery(["cwSingleVote", client.contractAddress, JSON.stringify(args)], () => client.vote({ + proposalId: args.proposalId, + voter: args.voter + }), options); +} +export interface CwSingleProposalCountQuery extends CwSingleReactQuery {} +export function useCwSingleProposalCountQuery({ + client, + options +}: CwSingleProposalCountQuery) { + return useQuery(["cwSingleProposalCount", client.contractAddress], () => client.proposalCount(), options); +} +export interface CwSingleReverseProposalsQuery extends CwSingleReactQuery { + args: { + limit?: number; + startBefore?: number; + }; +} +export function useCwSingleReverseProposalsQuery({ + client, + args, + options +}: CwSingleReverseProposalsQuery) { + return useQuery(["cwSingleReverseProposals", client.contractAddress, JSON.stringify(args)], () => client.reverseProposals({ + limit: args.limit, + startBefore: args.startBefore + }), options); +} +export interface CwSingleListProposalsQuery extends CwSingleReactQuery { + args: { + limit?: number; + startAfter?: number; + }; +} +export function useCwSingleListProposalsQuery({ + client, + args, + options +}: CwSingleListProposalsQuery) { + return useQuery(["cwSingleListProposals", client.contractAddress, JSON.stringify(args)], () => client.listProposals({ + limit: args.limit, + startAfter: args.startAfter + }), options); +} +export interface CwSingleProposalQuery extends CwSingleReactQuery { + args: { + proposalId: number; + }; +} +export function useCwSingleProposalQuery({ + client, + args, + options +}: CwSingleProposalQuery) { + return useQuery(["cwSingleProposal", client.contractAddress, JSON.stringify(args)], () => client.proposal({ + proposalId: args.proposalId + }), options); +} +export interface CwSingleConfigQuery extends CwSingleReactQuery {} +export function useCwSingleConfigQuery({ + client, + options +}: CwSingleConfigQuery) { + return useQuery(["cwSingleConfig", client.contractAddress], () => client.config(), options); +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.recoil.ts b/__output__/builder/bundler_test/contracts/CwSingle.recoil.ts new file mode 100644 index 00000000..79b2c1ba --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.recoil.ts @@ -0,0 +1,164 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { selectorFamily } from "recoil"; +import { cosmWasmClient } from "./chain"; +import { Addr, Uint128, Duration, Threshold, PercentageThreshold, Decimal, ConfigResponse, CheckedDepositInfo, ExecuteMsg, CosmosMsgForEmpty, BankMsg, StakingMsg, DistributionMsg, Binary, IbcMsg, Timestamp, Uint64, WasmMsg, GovMsg, VoteOption, Vote, DepositToken, Coin, Empty, IbcTimeout, IbcTimeoutBlock, DepositInfo, GovernanceModulesResponse, InfoResponse, ContractVersion, InstantiateMsg, Expiration, Status, ListProposalsResponse, ProposalResponse, Proposal, Votes, ListVotesResponse, VoteInfo, MigrateMsg, ProposalCountResponse, ProposalHooksResponse, QueryMsg, ReverseProposalsResponse, VoteHooksResponse, VoteResponse } from "./CwSingle.types"; +import { CwSingleQueryClient } from "./CwSingle.client"; +type QueryClientParams = { + contractAddress: string; +}; +export const queryClient = selectorFamily({ + key: "cwSingleQueryClient", + get: ({ + contractAddress + }) => ({ + get + }) => { + const client = get(cosmWasmClient); + return new CwSingleQueryClient(client, contractAddress); + } +}); +export const configSelector = selectorFamily; +}>({ + key: "cwSingleConfig", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.config(...params); + } +}); +export const proposalSelector = selectorFamily; +}>({ + key: "cwSingleProposal", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.proposal(...params); + } +}); +export const listProposalsSelector = selectorFamily; +}>({ + key: "cwSingleListProposals", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.listProposals(...params); + } +}); +export const reverseProposalsSelector = selectorFamily; +}>({ + key: "cwSingleReverseProposals", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.reverseProposals(...params); + } +}); +export const proposalCountSelector = selectorFamily; +}>({ + key: "cwSingleProposalCount", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.proposalCount(...params); + } +}); +export const voteSelector = selectorFamily; +}>({ + key: "cwSingleVote", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.vote(...params); + } +}); +export const listVotesSelector = selectorFamily; +}>({ + key: "cwSingleListVotes", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.listVotes(...params); + } +}); +export const proposalHooksSelector = selectorFamily; +}>({ + key: "cwSingleProposalHooks", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.proposalHooks(...params); + } +}); +export const voteHooksSelector = selectorFamily; +}>({ + key: "cwSingleVoteHooks", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.voteHooks(...params); + } +}); +export const infoSelector = selectorFamily; +}>({ + key: "cwSingleInfo", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.info(...params); + } +}); \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/CwSingle.types.ts b/__output__/builder/bundler_test/contracts/CwSingle.types.ts new file mode 100644 index 00000000..01398dab --- /dev/null +++ b/__output__/builder/bundler_test/contracts/CwSingle.types.ts @@ -0,0 +1,416 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +export type Addr = string; +export type Uint128 = string; +export type Duration = { + height: number; +} | { + time: number; +}; +export type Threshold = { + absolute_percentage: { + percentage: PercentageThreshold; + [k: string]: unknown; + }; +} | { + threshold_quorum: { + quorum: PercentageThreshold; + threshold: PercentageThreshold; + [k: string]: unknown; + }; +} | { + absolute_count: { + threshold: Uint128; + [k: string]: unknown; + }; +}; +export type PercentageThreshold = { + majority: { + [k: string]: unknown; + }; +} | { + percent: Decimal; +}; +export type Decimal = string; +export interface ConfigResponse { + allow_revoting: boolean; + dao: Addr; + deposit_info?: CheckedDepositInfo | null; + max_voting_period: Duration; + min_voting_period?: Duration | null; + only_members_execute: boolean; + threshold: Threshold; + [k: string]: unknown; +} +export interface CheckedDepositInfo { + deposit: Uint128; + refund_failed_proposals: boolean; + token: Addr; + [k: string]: unknown; +} +export type ExecuteMsg = { + propose: { + description: string; + msgs: CosmosMsgForEmpty[]; + title: string; + [k: string]: unknown; + }; +} | { + vote: { + proposal_id: number; + vote: Vote; + [k: string]: unknown; + }; +} | { + execute: { + proposal_id: number; + [k: string]: unknown; + }; +} | { + close: { + proposal_id: number; + [k: string]: unknown; + }; +} | { + update_config: { + allow_revoting: boolean; + dao: string; + deposit_info?: DepositInfo | null; + max_voting_period: Duration; + min_voting_period?: Duration | null; + only_members_execute: boolean; + threshold: Threshold; + [k: string]: unknown; + }; +} | { + add_proposal_hook: { + address: string; + [k: string]: unknown; + }; +} | { + remove_proposal_hook: { + address: string; + [k: string]: unknown; + }; +} | { + add_vote_hook: { + address: string; + [k: string]: unknown; + }; +} | { + remove_vote_hook: { + address: string; + [k: string]: unknown; + }; +}; +export type CosmosMsgForEmpty = { + bank: BankMsg; +} | { + custom: Empty; +} | { + staking: StakingMsg; +} | { + distribution: DistributionMsg; +} | { + stargate: { + type_url: string; + value: Binary; + [k: string]: unknown; + }; +} | { + ibc: IbcMsg; +} | { + wasm: WasmMsg; +} | { + gov: GovMsg; +}; +export type BankMsg = { + send: { + amount: Coin[]; + to_address: string; + [k: string]: unknown; + }; +} | { + burn: { + amount: Coin[]; + [k: string]: unknown; + }; +}; +export type StakingMsg = { + delegate: { + amount: Coin; + validator: string; + [k: string]: unknown; + }; +} | { + undelegate: { + amount: Coin; + validator: string; + [k: string]: unknown; + }; +} | { + redelegate: { + amount: Coin; + dst_validator: string; + src_validator: string; + [k: string]: unknown; + }; +}; +export type DistributionMsg = { + set_withdraw_address: { + address: string; + [k: string]: unknown; + }; +} | { + withdraw_delegator_reward: { + validator: string; + [k: string]: unknown; + }; +}; +export type Binary = string; +export type IbcMsg = { + transfer: { + amount: Coin; + channel_id: string; + timeout: IbcTimeout; + to_address: string; + [k: string]: unknown; + }; +} | { + send_packet: { + channel_id: string; + data: Binary; + timeout: IbcTimeout; + [k: string]: unknown; + }; +} | { + close_channel: { + channel_id: string; + [k: string]: unknown; + }; +}; +export type Timestamp = Uint64; +export type Uint64 = string; +export type WasmMsg = { + execute: { + contract_addr: string; + funds: Coin[]; + msg: Binary; + [k: string]: unknown; + }; +} | { + instantiate: { + admin?: string | null; + code_id: number; + funds: Coin[]; + label: string; + msg: Binary; + [k: string]: unknown; + }; +} | { + migrate: { + contract_addr: string; + msg: Binary; + new_code_id: number; + [k: string]: unknown; + }; +} | { + update_admin: { + admin: string; + contract_addr: string; + [k: string]: unknown; + }; +} | { + clear_admin: { + contract_addr: string; + [k: string]: unknown; + }; +}; +export type GovMsg = { + vote: { + proposal_id: number; + vote: VoteOption; + [k: string]: unknown; + }; +}; +export type VoteOption = "yes" | "no" | "abstain" | "no_with_veto"; +export type Vote = "yes" | "no" | "abstain"; +export type DepositToken = { + token: { + address: string; + [k: string]: unknown; + }; +} | { + voting_module_token: { + [k: string]: unknown; + }; +}; +export interface Coin { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export interface Empty { + [k: string]: unknown; +} +export interface IbcTimeout { + block?: IbcTimeoutBlock | null; + timestamp?: Timestamp | null; + [k: string]: unknown; +} +export interface IbcTimeoutBlock { + height: number; + revision: number; + [k: string]: unknown; +} +export interface DepositInfo { + deposit: Uint128; + refund_failed_proposals: boolean; + token: DepositToken; + [k: string]: unknown; +} +export type GovernanceModulesResponse = Addr[]; +export interface InfoResponse { + info: ContractVersion; + [k: string]: unknown; +} +export interface ContractVersion { + contract: string; + version: string; + [k: string]: unknown; +} +export interface InstantiateMsg { + allow_revoting: boolean; + deposit_info?: DepositInfo | null; + max_voting_period: Duration; + min_voting_period?: Duration | null; + only_members_execute: boolean; + threshold: Threshold; + [k: string]: unknown; +} +export type Expiration = { + at_height: number; +} | { + at_time: Timestamp; +} | { + never: { + [k: string]: unknown; + }; +}; +export type Status = "open" | "rejected" | "passed" | "executed" | "closed"; +export interface ListProposalsResponse { + proposals: ProposalResponse[]; + [k: string]: unknown; +} +export interface ProposalResponse { + id: number; + proposal: Proposal; + [k: string]: unknown; +} +export interface Proposal { + allow_revoting: boolean; + deposit_info?: CheckedDepositInfo | null; + description: string; + expiration: Expiration; + min_voting_period?: Expiration | null; + msgs: CosmosMsgForEmpty[]; + proposer: Addr; + start_height: number; + status: Status; + threshold: Threshold; + title: string; + total_power: Uint128; + votes: Votes; + [k: string]: unknown; +} +export interface Votes { + abstain: Uint128; + no: Uint128; + yes: Uint128; + [k: string]: unknown; +} +export interface ListVotesResponse { + votes: VoteInfo[]; + [k: string]: unknown; +} +export interface VoteInfo { + power: Uint128; + vote: Vote; + voter: Addr; + [k: string]: unknown; +} +export interface MigrateMsg { + [k: string]: unknown; +} +export type ProposalCountResponse = number; +export interface ProposalHooksResponse { + hooks: string[]; + [k: string]: unknown; +} +export type QueryMsg = { + config: { + [k: string]: unknown; + }; +} | { + proposal: { + proposal_id: number; + [k: string]: unknown; + }; +} | { + list_proposals: { + limit?: number | null; + start_after?: number | null; + [k: string]: unknown; + }; +} | { + reverse_proposals: { + limit?: number | null; + start_before?: number | null; + [k: string]: unknown; + }; +} | { + proposal_count: { + [k: string]: unknown; + }; +} | { + vote: { + proposal_id: number; + voter: string; + [k: string]: unknown; + }; +} | { + list_votes: { + limit?: number | null; + proposal_id: number; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + proposal_hooks: { + [k: string]: unknown; + }; +} | { + vote_hooks: { + [k: string]: unknown; + }; +} | { + info: { + [k: string]: unknown; + }; +}; +export interface ReverseProposalsResponse { + proposals: ProposalResponse[]; + [k: string]: unknown; +} +export interface VoteHooksResponse { + hooks: string[]; + [k: string]: unknown; +} +export interface VoteResponse { + vote?: VoteInfo | null; + [k: string]: unknown; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.client.ts b/__output__/builder/bundler_test/contracts/Factory.client.ts new file mode 100644 index 00000000..6e9897d6 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.client.ts @@ -0,0 +1,259 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { AdminAddrResponse, CodeIdResponse, CodeIdType, Uint128, Binary, CreateWalletMsg, Guardians, MultiSig, Coin, Cw20Coin, ExecuteMsg, Addr, ProxyMigrationTxMsg, WalletAddr, CanonicalAddr, RelayTransaction, FeeResponse, GovecAddrResponse, InstantiateMsg, QueryMsg, WalletQueryPrefix, Duration, StakingOptions, WalletInfo, ContractVersion, WalletsOfResponse, WalletsResponse } from "./Factory.types"; +export interface FactoryReadOnlyInterface { + contractAddress: string; + wallets: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: WalletQueryPrefix; + }) => Promise; + walletsOf: ({ + limit, + startAfter, + user + }: { + limit?: number; + startAfter?: string; + user: string; + }) => Promise; + codeId: ({ + ty + }: { + ty: CodeIdType; + }) => Promise; + fee: () => Promise; + govecAddr: () => Promise; + adminAddr: () => Promise; +} +export class FactoryQueryClient implements FactoryReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.wallets = this.wallets.bind(this); + this.walletsOf = this.walletsOf.bind(this); + this.codeId = this.codeId.bind(this); + this.fee = this.fee.bind(this); + this.govecAddr = this.govecAddr.bind(this); + this.adminAddr = this.adminAddr.bind(this); + } + + wallets = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: WalletQueryPrefix; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + wallets: { + limit, + start_after: startAfter + } + }); + }; + walletsOf = async ({ + limit, + startAfter, + user + }: { + limit?: number; + startAfter?: string; + user: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + wallets_of: { + limit, + start_after: startAfter, + user + } + }); + }; + codeId = async ({ + ty + }: { + ty: CodeIdType; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + code_id: { + ty + } + }); + }; + fee = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + fee: {} + }); + }; + govecAddr = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + govec_addr: {} + }); + }; + adminAddr = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + admin_addr: {} + }); + }; +} +export interface FactoryInterface { + contractAddress: string; + sender: string; + createWallet: ({ + createWalletMsg + }: { + createWalletMsg: CreateWalletMsg; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateProxyUser: ({ + newUser, + oldUser + }: { + newUser: Addr; + oldUser: Addr; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + migrateWallet: ({ + migrationMsg, + walletAddress + }: { + migrationMsg: ProxyMigrationTxMsg; + walletAddress: WalletAddr; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateCodeId: ({ + newCodeId, + ty + }: { + newCodeId: number; + ty: CodeIdType; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateWalletFee: ({ + newFee + }: { + newFee: Coin; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateGovecAddr: ({ + addr + }: { + addr: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateAdmin: ({ + addr + }: { + addr: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; +} +export class FactoryClient implements FactoryInterface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.createWallet = this.createWallet.bind(this); + this.updateProxyUser = this.updateProxyUser.bind(this); + this.migrateWallet = this.migrateWallet.bind(this); + this.updateCodeId = this.updateCodeId.bind(this); + this.updateWalletFee = this.updateWalletFee.bind(this); + this.updateGovecAddr = this.updateGovecAddr.bind(this); + this.updateAdmin = this.updateAdmin.bind(this); + } + + createWallet = async ({ + createWalletMsg + }: { + createWalletMsg: CreateWalletMsg; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + create_wallet: { + create_wallet_msg: createWalletMsg + } + }, fee, memo, funds); + }; + updateProxyUser = async ({ + newUser, + oldUser + }: { + newUser: Addr; + oldUser: Addr; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_proxy_user: { + new_user: newUser, + old_user: oldUser + } + }, fee, memo, funds); + }; + migrateWallet = async ({ + migrationMsg, + walletAddress + }: { + migrationMsg: ProxyMigrationTxMsg; + walletAddress: WalletAddr; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + migrate_wallet: { + migration_msg: migrationMsg, + wallet_address: walletAddress + } + }, fee, memo, funds); + }; + updateCodeId = async ({ + newCodeId, + ty + }: { + newCodeId: number; + ty: CodeIdType; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_code_id: { + new_code_id: newCodeId, + ty + } + }, fee, memo, funds); + }; + updateWalletFee = async ({ + newFee + }: { + newFee: Coin; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_wallet_fee: { + new_fee: newFee + } + }, fee, memo, funds); + }; + updateGovecAddr = async ({ + addr + }: { + addr: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_govec_addr: { + addr + } + }, fee, memo, funds); + }; + updateAdmin = async ({ + addr + }: { + addr: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_admin: { + addr + } + }, fee, memo, funds); + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.message-composer.ts b/__output__/builder/bundler_test/contracts/Factory.message-composer.ts new file mode 100644 index 00000000..21e5a2d1 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.message-composer.ts @@ -0,0 +1,214 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { MsgExecuteContractEncodeObject } from "cosmwasm"; +import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import { toUtf8 } from "@cosmjs/encoding"; +import { AdminAddrResponse, CodeIdResponse, CodeIdType, Uint128, Binary, CreateWalletMsg, Guardians, MultiSig, Coin, Cw20Coin, ExecuteMsg, Addr, ProxyMigrationTxMsg, WalletAddr, CanonicalAddr, RelayTransaction, FeeResponse, GovecAddrResponse, InstantiateMsg, QueryMsg, WalletQueryPrefix, Duration, StakingOptions, WalletInfo, ContractVersion, WalletsOfResponse, WalletsResponse } from "./Factory.types"; +export interface FactoryMessage { + contractAddress: string; + sender: string; + createWallet: ({ + createWalletMsg + }: { + createWalletMsg: CreateWalletMsg; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateProxyUser: ({ + newUser, + oldUser + }: { + newUser: Addr; + oldUser: Addr; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + migrateWallet: ({ + migrationMsg, + walletAddress + }: { + migrationMsg: ProxyMigrationTxMsg; + walletAddress: WalletAddr; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateCodeId: ({ + newCodeId, + ty + }: { + newCodeId: number; + ty: CodeIdType; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateWalletFee: ({ + newFee + }: { + newFee: Coin; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateGovecAddr: ({ + addr + }: { + addr: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateAdmin: ({ + addr + }: { + addr: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; +} +export class FactoryMessageComposer implements FactoryMessage { + sender: string; + contractAddress: string; + + constructor(sender: string, contractAddress: string) { + this.sender = sender; + this.contractAddress = contractAddress; + this.createWallet = this.createWallet.bind(this); + this.updateProxyUser = this.updateProxyUser.bind(this); + this.migrateWallet = this.migrateWallet.bind(this); + this.updateCodeId = this.updateCodeId.bind(this); + this.updateWalletFee = this.updateWalletFee.bind(this); + this.updateGovecAddr = this.updateGovecAddr.bind(this); + this.updateAdmin = this.updateAdmin.bind(this); + } + + createWallet = ({ + createWalletMsg + }: { + createWalletMsg: CreateWalletMsg; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + create_wallet: { + create_wallet_msg: createWalletMsg + } + })), + funds + }) + }; + }; + updateProxyUser = ({ + newUser, + oldUser + }: { + newUser: Addr; + oldUser: Addr; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_proxy_user: { + new_user: newUser, + old_user: oldUser + } + })), + funds + }) + }; + }; + migrateWallet = ({ + migrationMsg, + walletAddress + }: { + migrationMsg: ProxyMigrationTxMsg; + walletAddress: WalletAddr; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + migrate_wallet: { + migration_msg: migrationMsg, + wallet_address: walletAddress + } + })), + funds + }) + }; + }; + updateCodeId = ({ + newCodeId, + ty + }: { + newCodeId: number; + ty: CodeIdType; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_code_id: { + new_code_id: newCodeId, + ty + } + })), + funds + }) + }; + }; + updateWalletFee = ({ + newFee + }: { + newFee: Coin; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_wallet_fee: { + new_fee: newFee + } + })), + funds + }) + }; + }; + updateGovecAddr = ({ + addr + }: { + addr: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_govec_addr: { + addr + } + })), + funds + }) + }; + }; + updateAdmin = ({ + addr + }: { + addr: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_admin: { + addr + } + })), + funds + }) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.msg-builder.ts b/__output__/builder/bundler_test/contracts/Factory.msg-builder.ts new file mode 100644 index 00000000..0c662c0a --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.msg-builder.ts @@ -0,0 +1,149 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { AdminAddrResponse, CodeIdResponse, CodeIdType, Uint128, Binary, CreateWalletMsg, Guardians, MultiSig, Coin, Cw20Coin, ExecuteMsg, Addr, ProxyMigrationTxMsg, WalletAddr, CanonicalAddr, RelayTransaction, FeeResponse, GovecAddrResponse, InstantiateMsg, QueryMsg, WalletQueryPrefix, Duration, StakingOptions, WalletInfo, ContractVersion, WalletsOfResponse, WalletsResponse } from "./Factory.types"; +import { CamelCasedProperties } from "type-fest"; +export abstract class FactoryExecuteMsgBuilder { + static createWallet = ({ + createWalletMsg + }: CamelCasedProperties["create_wallet"]>): ExecuteMsg => { + return { + create_wallet: ({ + create_wallet_msg: createWalletMsg + } as const) + }; + }; + static updateProxyUser = ({ + newUser, + oldUser + }: CamelCasedProperties["update_proxy_user"]>): ExecuteMsg => { + return { + update_proxy_user: ({ + new_user: newUser, + old_user: oldUser + } as const) + }; + }; + static migrateWallet = ({ + migrationMsg, + walletAddress + }: CamelCasedProperties["migrate_wallet"]>): ExecuteMsg => { + return { + migrate_wallet: ({ + migration_msg: migrationMsg, + wallet_address: walletAddress + } as const) + }; + }; + static updateCodeId = ({ + newCodeId, + ty + }: CamelCasedProperties["update_code_id"]>): ExecuteMsg => { + return { + update_code_id: ({ + new_code_id: newCodeId, + ty + } as const) + }; + }; + static updateWalletFee = ({ + newFee + }: CamelCasedProperties["update_wallet_fee"]>): ExecuteMsg => { + return { + update_wallet_fee: ({ + new_fee: newFee + } as const) + }; + }; + static updateGovecAddr = ({ + addr + }: CamelCasedProperties["update_govec_addr"]>): ExecuteMsg => { + return { + update_govec_addr: ({ + addr + } as const) + }; + }; + static updateAdmin = ({ + addr + }: CamelCasedProperties["update_admin"]>): ExecuteMsg => { + return { + update_admin: ({ + addr + } as const) + }; + }; +} +export abstract class FactoryQueryMsgBuilder { + static wallets = ({ + limit, + startAfter + }: CamelCasedProperties["wallets"]>): QueryMsg => { + return { + wallets: ({ + limit, + start_after: startAfter + } as const) + }; + }; + static walletsOf = ({ + limit, + startAfter, + user + }: CamelCasedProperties["wallets_of"]>): QueryMsg => { + return { + wallets_of: ({ + limit, + start_after: startAfter, + user + } as const) + }; + }; + static codeId = ({ + ty + }: CamelCasedProperties["code_id"]>): QueryMsg => { + return { + code_id: ({ + ty + } as const) + }; + }; + static fee = (): QueryMsg => { + return { + fee: ({} as const) + }; + }; + static govecAddr = (): QueryMsg => { + return { + govec_addr: ({} as const) + }; + }; + static adminAddr = (): QueryMsg => { + return { + admin_addr: ({} as const) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.react-query.ts b/__output__/builder/bundler_test/contracts/Factory.react-query.ts new file mode 100644 index 00000000..2d40ad5e --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.react-query.ts @@ -0,0 +1,82 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { UseQueryOptions, useQuery } from "react-query"; +import { AdminAddrResponse, CodeIdResponse, CodeIdType, Uint128, Binary, CreateWalletMsg, Guardians, MultiSig, Coin, Cw20Coin, ExecuteMsg, Addr, ProxyMigrationTxMsg, WalletAddr, CanonicalAddr, RelayTransaction, FeeResponse, GovecAddrResponse, InstantiateMsg, QueryMsg, WalletQueryPrefix, Duration, StakingOptions, WalletInfo, ContractVersion, WalletsOfResponse, WalletsResponse } from "./Factory.types"; +import { FactoryQueryClient } from "./Factory.client"; +export interface FactoryReactQuery { + client: FactoryQueryClient; + options?: UseQueryOptions; +} +export interface FactoryAdminAddrQuery extends FactoryReactQuery {} +export function useFactoryAdminAddrQuery({ + client, + options +}: FactoryAdminAddrQuery) { + return useQuery(["factoryAdminAddr", client.contractAddress], () => client.adminAddr(), options); +} +export interface FactoryGovecAddrQuery extends FactoryReactQuery {} +export function useFactoryGovecAddrQuery({ + client, + options +}: FactoryGovecAddrQuery) { + return useQuery(["factoryGovecAddr", client.contractAddress], () => client.govecAddr(), options); +} +export interface FactoryFeeQuery extends FactoryReactQuery {} +export function useFactoryFeeQuery({ + client, + options +}: FactoryFeeQuery) { + return useQuery(["factoryFee", client.contractAddress], () => client.fee(), options); +} +export interface FactoryCodeIdQuery extends FactoryReactQuery { + args: { + ty: CodeIdType; + }; +} +export function useFactoryCodeIdQuery({ + client, + args, + options +}: FactoryCodeIdQuery) { + return useQuery(["factoryCodeId", client.contractAddress, JSON.stringify(args)], () => client.codeId({ + ty: args.ty + }), options); +} +export interface FactoryWalletsOfQuery extends FactoryReactQuery { + args: { + limit?: number; + startAfter?: string; + user: string; + }; +} +export function useFactoryWalletsOfQuery({ + client, + args, + options +}: FactoryWalletsOfQuery) { + return useQuery(["factoryWalletsOf", client.contractAddress, JSON.stringify(args)], () => client.walletsOf({ + limit: args.limit, + startAfter: args.startAfter, + user: args.user + }), options); +} +export interface FactoryWalletsQuery extends FactoryReactQuery { + args: { + limit?: number; + startAfter?: WalletQueryPrefix; + }; +} +export function useFactoryWalletsQuery({ + client, + args, + options +}: FactoryWalletsQuery) { + return useQuery(["factoryWallets", client.contractAddress, JSON.stringify(args)], () => client.wallets({ + limit: args.limit, + startAfter: args.startAfter + }), options); +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.recoil.ts b/__output__/builder/bundler_test/contracts/Factory.recoil.ts new file mode 100644 index 00000000..3e17ff15 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.recoil.ts @@ -0,0 +1,108 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { selectorFamily } from "recoil"; +import { cosmWasmClient } from "./chain"; +import { AdminAddrResponse, CodeIdResponse, CodeIdType, Uint128, Binary, CreateWalletMsg, Guardians, MultiSig, Coin, Cw20Coin, ExecuteMsg, Addr, ProxyMigrationTxMsg, WalletAddr, CanonicalAddr, RelayTransaction, FeeResponse, GovecAddrResponse, InstantiateMsg, QueryMsg, WalletQueryPrefix, Duration, StakingOptions, WalletInfo, ContractVersion, WalletsOfResponse, WalletsResponse } from "./Factory.types"; +import { FactoryQueryClient } from "./Factory.client"; +type QueryClientParams = { + contractAddress: string; +}; +export const queryClient = selectorFamily({ + key: "factoryQueryClient", + get: ({ + contractAddress + }) => ({ + get + }) => { + const client = get(cosmWasmClient); + return new FactoryQueryClient(client, contractAddress); + } +}); +export const walletsSelector = selectorFamily; +}>({ + key: "factoryWallets", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.wallets(...params); + } +}); +export const walletsOfSelector = selectorFamily; +}>({ + key: "factoryWalletsOf", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.walletsOf(...params); + } +}); +export const codeIdSelector = selectorFamily; +}>({ + key: "factoryCodeId", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.codeId(...params); + } +}); +export const feeSelector = selectorFamily; +}>({ + key: "factoryFee", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.fee(...params); + } +}); +export const govecAddrSelector = selectorFamily; +}>({ + key: "factoryGovecAddr", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.govecAddr(...params); + } +}); +export const adminAddrSelector = selectorFamily; +}>({ + key: "factoryAdminAddr", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.adminAddr(...params); + } +}); \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Factory.types.ts b/__output__/builder/bundler_test/contracts/Factory.types.ts new file mode 100644 index 00000000..ddea5192 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Factory.types.ts @@ -0,0 +1,183 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +export type AdminAddrResponse = string; +export type CodeIdResponse = number; +export type CodeIdType = "Proxy" | "Multisig"; +export type Uint128 = string; +export type Binary = string; +export interface CreateWalletMsg { + guardians: Guardians; + label: string; + proxy_initial_funds: Coin[]; + relayers: string[]; + user_pubkey: Binary; + [k: string]: unknown; +} +export interface Guardians { + addresses: string[]; + guardians_multisig?: MultiSig | null; + [k: string]: unknown; +} +export interface MultiSig { + multisig_initial_funds: Coin[]; + threshold_absolute_count: number; + [k: string]: unknown; +} +export interface Coin { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export interface Cw20Coin { + address: string; + amount: Uint128; + [k: string]: unknown; +} +export type ExecuteMsg = { + create_wallet: { + create_wallet_msg: CreateWalletMsg; + [k: string]: unknown; + }; +} | { + update_proxy_user: { + new_user: Addr; + old_user: Addr; + [k: string]: unknown; + }; +} | { + migrate_wallet: { + migration_msg: ProxyMigrationTxMsg; + wallet_address: WalletAddr; + [k: string]: unknown; + }; +} | { + update_code_id: { + new_code_id: number; + ty: CodeIdType; + [k: string]: unknown; + }; +} | { + update_wallet_fee: { + new_fee: Coin; + [k: string]: unknown; + }; +} | { + update_govec_addr: { + addr: string; + [k: string]: unknown; + }; +} | { + update_admin: { + addr: string; + [k: string]: unknown; + }; +}; +export type Addr = string; +export type ProxyMigrationTxMsg = { + RelayTx: RelayTransaction; +} | { + DirectMigrationMsg: Binary; +}; +export type WalletAddr = { + Canonical: CanonicalAddr; +} | { + Addr: Addr; +}; +export type CanonicalAddr = string; +export interface RelayTransaction { + message: Binary; + nonce: number; + signature: Binary; + user_pubkey: Binary; + [k: string]: unknown; +} +export interface FeeResponse { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export type GovecAddrResponse = string; +export interface InstantiateMsg { + addr_prefix: string; + govec?: string | null; + proxy_code_id: number; + proxy_multisig_code_id: number; + wallet_fee: Coin; + [k: string]: unknown; +} +export type QueryMsg = { + wallets: { + limit?: number | null; + start_after?: WalletQueryPrefix | null; + [k: string]: unknown; + }; +} | { + wallets_of: { + limit?: number | null; + start_after?: string | null; + user: string; + [k: string]: unknown; + }; +} | { + code_id: { + ty: CodeIdType; + [k: string]: unknown; + }; +} | { + fee: { + [k: string]: unknown; + }; +} | { + govec_addr: { + [k: string]: unknown; + }; +} | { + admin_addr: { + [k: string]: unknown; + }; +}; +export interface WalletQueryPrefix { + user_addr: string; + wallet_addr: string; + [k: string]: unknown; +} +export type Duration = { + height: number; +} | { + time: number; +}; +export interface StakingOptions { + code_id: number; + duration?: Duration | null; + [k: string]: unknown; +} +export interface WalletInfo { + code_id: number; + guardians: Addr[]; + is_frozen: boolean; + label: string; + multisig_address?: Addr | null; + multisig_code_id: number; + nonce: number; + relayers: Addr[]; + user_addr: Addr; + version: ContractVersion; + [k: string]: unknown; +} +export interface ContractVersion { + contract: string; + version: string; + [k: string]: unknown; +} +export interface WalletsOfResponse { + wallets: Addr[]; + [k: string]: unknown; +} +export interface WalletsResponse { + wallets: Addr[]; + [k: string]: unknown; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.client.ts b/__output__/builder/bundler_test/contracts/Minter.client.ts new file mode 100644 index 00000000..deffa10a --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.client.ts @@ -0,0 +1,177 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Timestamp, Uint64, Uint128, ConfigResponse, Coin, Addr, Config, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, QueryMsg } from "./Minter.types"; +export interface MinterReadOnlyInterface { + contractAddress: string; + config: () => Promise; + mintableNumTokens: () => Promise; + startTime: () => Promise; + mintPrice: () => Promise; + mintCount: ({ + address + }: { + address: string; + }) => Promise; +} +export class MinterQueryClient implements MinterReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.config = this.config.bind(this); + this.mintableNumTokens = this.mintableNumTokens.bind(this); + this.startTime = this.startTime.bind(this); + this.mintPrice = this.mintPrice.bind(this); + this.mintCount = this.mintCount.bind(this); + } + + config = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + config: {} + }); + }; + mintableNumTokens = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + mintable_num_tokens: {} + }); + }; + startTime = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + start_time: {} + }); + }; + mintPrice = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + mint_price: {} + }); + }; + mintCount = async ({ + address + }: { + address: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + mint_count: { + address + } + }); + }; +} +export interface MinterInterface { + contractAddress: string; + sender: string; + mint: (fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + setWhitelist: ({ + whitelist + }: { + whitelist: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updateStartTime: (fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + updatePerAddressLimit: ({ + perAddressLimit + }: { + perAddressLimit: number; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + mintTo: ({ + recipient + }: { + recipient: string; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + mintFor: ({ + recipient, + tokenId + }: { + recipient: string; + tokenId: number; + }, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; + withdraw: (fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise; +} +export class MinterClient implements MinterInterface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.mint = this.mint.bind(this); + this.setWhitelist = this.setWhitelist.bind(this); + this.updateStartTime = this.updateStartTime.bind(this); + this.updatePerAddressLimit = this.updatePerAddressLimit.bind(this); + this.mintTo = this.mintTo.bind(this); + this.mintFor = this.mintFor.bind(this); + this.withdraw = this.withdraw.bind(this); + } + + mint = async (fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + mint: {} + }, fee, memo, funds); + }; + setWhitelist = async ({ + whitelist + }: { + whitelist: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + set_whitelist: { + whitelist + } + }, fee, memo, funds); + }; + updateStartTime = async (fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_start_time: {} + }, fee, memo, funds); + }; + updatePerAddressLimit = async ({ + perAddressLimit + }: { + perAddressLimit: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + update_per_address_limit: { + per_address_limit: perAddressLimit + } + }, fee, memo, funds); + }; + mintTo = async ({ + recipient + }: { + recipient: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + mint_to: { + recipient + } + }, fee, memo, funds); + }; + mintFor = async ({ + recipient, + tokenId + }: { + recipient: string; + tokenId: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + mint_for: { + recipient, + token_id: tokenId + } + }, fee, memo, funds); + }; + withdraw = async (fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + withdraw: {} + }, fee, memo, funds); + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.message-composer.ts b/__output__/builder/bundler_test/contracts/Minter.message-composer.ts new file mode 100644 index 00000000..30a74b8b --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.message-composer.ts @@ -0,0 +1,174 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { MsgExecuteContractEncodeObject } from "cosmwasm"; +import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import { toUtf8 } from "@cosmjs/encoding"; +import { Timestamp, Uint64, Uint128, ConfigResponse, Coin, Addr, Config, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, QueryMsg } from "./Minter.types"; +export interface MinterMessage { + contractAddress: string; + sender: string; + mint: (funds?: Coin[]) => MsgExecuteContractEncodeObject; + setWhitelist: ({ + whitelist + }: { + whitelist: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + updateStartTime: (funds?: Coin[]) => MsgExecuteContractEncodeObject; + updatePerAddressLimit: ({ + perAddressLimit + }: { + perAddressLimit: number; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + mintTo: ({ + recipient + }: { + recipient: string; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + mintFor: ({ + recipient, + tokenId + }: { + recipient: string; + tokenId: number; + }, funds?: Coin[]) => MsgExecuteContractEncodeObject; + withdraw: (funds?: Coin[]) => MsgExecuteContractEncodeObject; +} +export class MinterMessageComposer implements MinterMessage { + sender: string; + contractAddress: string; + + constructor(sender: string, contractAddress: string) { + this.sender = sender; + this.contractAddress = contractAddress; + this.mint = this.mint.bind(this); + this.setWhitelist = this.setWhitelist.bind(this); + this.updateStartTime = this.updateStartTime.bind(this); + this.updatePerAddressLimit = this.updatePerAddressLimit.bind(this); + this.mintTo = this.mintTo.bind(this); + this.mintFor = this.mintFor.bind(this); + this.withdraw = this.withdraw.bind(this); + } + + mint = (funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + mint: {} + })), + funds + }) + }; + }; + setWhitelist = ({ + whitelist + }: { + whitelist: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + set_whitelist: { + whitelist + } + })), + funds + }) + }; + }; + updateStartTime = (funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_start_time: {} + })), + funds + }) + }; + }; + updatePerAddressLimit = ({ + perAddressLimit + }: { + perAddressLimit: number; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + update_per_address_limit: { + per_address_limit: perAddressLimit + } + })), + funds + }) + }; + }; + mintTo = ({ + recipient + }: { + recipient: string; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + mint_to: { + recipient + } + })), + funds + }) + }; + }; + mintFor = ({ + recipient, + tokenId + }: { + recipient: string; + tokenId: number; + }, funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + mint_for: { + recipient, + token_id: tokenId + } + })), + funds + }) + }; + }; + withdraw = (funds?: Coin[]): MsgExecuteContractEncodeObject => { + return { + typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", + value: MsgExecuteContract.fromPartial({ + sender: this.sender, + contract: this.contractAddress, + msg: toUtf8(JSON.stringify({ + withdraw: {} + })), + funds + }) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.msg-builder.ts b/__output__/builder/bundler_test/contracts/Minter.msg-builder.ts new file mode 100644 index 00000000..897f3fa8 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.msg-builder.ts @@ -0,0 +1,104 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { Timestamp, Uint64, Uint128, ConfigResponse, Coin, Addr, Config, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, QueryMsg } from "./Minter.types"; +import { CamelCasedProperties } from "type-fest"; +export abstract class MinterExecuteMsgBuilder { + static mint = (): ExecuteMsg => { + return { + mint: ({} as const) + }; + }; + static setWhitelist = ({ + whitelist + }: CamelCasedProperties["set_whitelist"]>): ExecuteMsg => { + return { + set_whitelist: ({ + whitelist + } as const) + }; + }; + static updateStartTime = (): ExecuteMsg => { + return { + update_start_time: ({} as const) + }; + }; + static updatePerAddressLimit = ({ + perAddressLimit + }: CamelCasedProperties["update_per_address_limit"]>): ExecuteMsg => { + return { + update_per_address_limit: ({ + per_address_limit: perAddressLimit + } as const) + }; + }; + static mintTo = ({ + recipient + }: CamelCasedProperties["mint_to"]>): ExecuteMsg => { + return { + mint_to: ({ + recipient + } as const) + }; + }; + static mintFor = ({ + recipient, + tokenId + }: CamelCasedProperties["mint_for"]>): ExecuteMsg => { + return { + mint_for: ({ + recipient, + token_id: tokenId + } as const) + }; + }; + static withdraw = (): ExecuteMsg => { + return { + withdraw: ({} as const) + }; + }; +} +export abstract class MinterQueryMsgBuilder { + static config = (): QueryMsg => { + return { + config: ({} as const) + }; + }; + static mintableNumTokens = (): QueryMsg => { + return { + mintable_num_tokens: ({} as const) + }; + }; + static startTime = (): QueryMsg => { + return { + start_time: ({} as const) + }; + }; + static mintPrice = (): QueryMsg => { + return { + mint_price: ({} as const) + }; + }; + static mintCount = ({ + address + }: CamelCasedProperties["mint_count"]>): QueryMsg => { + return { + mint_count: ({ + address + } as const) + }; + }; +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.react-query.ts b/__output__/builder/bundler_test/contracts/Minter.react-query.ts new file mode 100644 index 00000000..007bcfd9 --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.react-query.ts @@ -0,0 +1,55 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { UseQueryOptions, useQuery } from "react-query"; +import { Timestamp, Uint64, Uint128, ConfigResponse, Coin, Addr, Config, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, QueryMsg } from "./Minter.types"; +import { MinterQueryClient } from "./Minter.client"; +export interface MinterReactQuery { + client: MinterQueryClient; + options?: UseQueryOptions; +} +export interface MinterMintCountQuery extends MinterReactQuery { + args: { + address: string; + }; +} +export function useMinterMintCountQuery({ + client, + args, + options +}: MinterMintCountQuery) { + return useQuery(["minterMintCount", client.contractAddress, JSON.stringify(args)], () => client.mintCount({ + address: args.address + }), options); +} +export interface MinterMintPriceQuery extends MinterReactQuery {} +export function useMinterMintPriceQuery({ + client, + options +}: MinterMintPriceQuery) { + return useQuery(["minterMintPrice", client.contractAddress], () => client.mintPrice(), options); +} +export interface MinterStartTimeQuery extends MinterReactQuery {} +export function useMinterStartTimeQuery({ + client, + options +}: MinterStartTimeQuery) { + return useQuery(["minterStartTime", client.contractAddress], () => client.startTime(), options); +} +export interface MinterMintableNumTokensQuery extends MinterReactQuery {} +export function useMinterMintableNumTokensQuery({ + client, + options +}: MinterMintableNumTokensQuery) { + return useQuery(["minterMintableNumTokens", client.contractAddress], () => client.mintableNumTokens(), options); +} +export interface MinterConfigQuery extends MinterReactQuery {} +export function useMinterConfigQuery({ + client, + options +}: MinterConfigQuery) { + return useQuery(["minterConfig", client.contractAddress], () => client.config(), options); +} \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.recoil.ts b/__output__/builder/bundler_test/contracts/Minter.recoil.ts new file mode 100644 index 00000000..826fb57c --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.recoil.ts @@ -0,0 +1,94 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import { selectorFamily } from "recoil"; +import { cosmWasmClient } from "./chain"; +import { Timestamp, Uint64, Uint128, ConfigResponse, Coin, Addr, Config, ExecuteMsg, Decimal, InstantiateMsg, InstantiateMsg1, CollectionInfoForRoyaltyInfoResponse, RoyaltyInfoResponse, QueryMsg } from "./Minter.types"; +import { MinterQueryClient } from "./Minter.client"; +type QueryClientParams = { + contractAddress: string; +}; +export const queryClient = selectorFamily({ + key: "minterQueryClient", + get: ({ + contractAddress + }) => ({ + get + }) => { + const client = get(cosmWasmClient); + return new MinterQueryClient(client, contractAddress); + } +}); +export const configSelector = selectorFamily; +}>({ + key: "minterConfig", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.config(...params); + } +}); +export const mintableNumTokensSelector = selectorFamily; +}>({ + key: "minterMintableNumTokens", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.mintableNumTokens(...params); + } +}); +export const startTimeSelector = selectorFamily; +}>({ + key: "minterStartTime", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.startTime(...params); + } +}); +export const mintPriceSelector = selectorFamily; +}>({ + key: "minterMintPrice", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.mintPrice(...params); + } +}); +export const mintCountSelector = selectorFamily; +}>({ + key: "minterMintCount", + get: ({ + params, + ...queryClientParams + }) => async ({ + get + }) => { + const client = get(queryClient(queryClientParams)); + return await client.mintCount(...params); + } +}); \ No newline at end of file diff --git a/__output__/builder/bundler_test/contracts/Minter.types.ts b/__output__/builder/bundler_test/contracts/Minter.types.ts new file mode 100644 index 00000000..55999b8d --- /dev/null +++ b/__output__/builder/bundler_test/contracts/Minter.types.ts @@ -0,0 +1,124 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +export type Timestamp = Uint64; +export type Uint64 = string; +export type Uint128 = string; +export interface ConfigResponse { + admin: string; + base_token_uri: string; + num_tokens: number; + per_address_limit: number; + sg721_address: string; + sg721_code_id: number; + start_time: Timestamp; + unit_price: Coin; + whitelist?: string | null; + [k: string]: unknown; +} +export interface Coin { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export type Addr = string; +export interface Config { + admin: Addr; + base_token_uri: string; + num_tokens: number; + per_address_limit: number; + sg721_code_id: number; + start_time: Timestamp; + unit_price: Coin; + whitelist?: Addr | null; + [k: string]: unknown; +} +export type ExecuteMsg = { + mint: { + [k: string]: unknown; + }; +} | { + set_whitelist: { + whitelist: string; + [k: string]: unknown; + }; +} | { + update_start_time: Timestamp; +} | { + update_per_address_limit: { + per_address_limit: number; + [k: string]: unknown; + }; +} | { + mint_to: { + recipient: string; + [k: string]: unknown; + }; +} | { + mint_for: { + recipient: string; + token_id: number; + [k: string]: unknown; + }; +} | { + withdraw: { + [k: string]: unknown; + }; +}; +export type Decimal = string; +export interface InstantiateMsg { + base_token_uri: string; + num_tokens: number; + per_address_limit: number; + sg721_code_id: number; + sg721_instantiate_msg: InstantiateMsg1; + start_time: Timestamp; + unit_price: Coin; + whitelist?: string | null; + [k: string]: unknown; +} +export interface InstantiateMsg1 { + collection_info: CollectionInfoForRoyaltyInfoResponse; + minter: string; + name: string; + symbol: string; + [k: string]: unknown; +} +export interface CollectionInfoForRoyaltyInfoResponse { + creator: string; + description: string; + external_link?: string | null; + image: string; + royalty_info?: RoyaltyInfoResponse | null; + [k: string]: unknown; +} +export interface RoyaltyInfoResponse { + payment_address: string; + share: Decimal; + [k: string]: unknown; +} +export type QueryMsg = { + config: { + [k: string]: unknown; + }; +} | { + mintable_num_tokens: { + [k: string]: unknown; + }; +} | { + start_time: { + [k: string]: unknown; + }; +} | { + mint_price: { + [k: string]: unknown; + }; +} | { + mint_count: { + address: string; + [k: string]: unknown; + }; +}; \ No newline at end of file diff --git a/__output__/builder/bundler_test/index.ts b/__output__/builder/bundler_test/index.ts new file mode 100644 index 00000000..8dedea79 --- /dev/null +++ b/__output__/builder/bundler_test/index.ts @@ -0,0 +1,65 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@latest. +* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, +* and run the @cosmwasm/ts-codegen generate command to regenerate this file. +*/ + +import * as _75 from "./contracts/Factory.types"; +import * as _76 from "./contracts/Factory.client"; +import * as _77 from "./contracts/Factory.message-composer"; +import * as _78 from "./contracts/Factory.react-query"; +import * as _79 from "./contracts/Factory.recoil"; +import * as _80 from "./contracts/Minter.types"; +import * as _81 from "./contracts/Minter.client"; +import * as _82 from "./contracts/Minter.message-composer"; +import * as _83 from "./contracts/Minter.react-query"; +import * as _84 from "./contracts/Minter.recoil"; +import * as _85 from "./contracts/CwAdminFactory.types"; +import * as _86 from "./contracts/CwAdminFactory.client"; +import * as _87 from "./contracts/CwAdminFactory.message-composer"; +import * as _88 from "./contracts/CwAdminFactory.react-query"; +import * as _89 from "./contracts/CwAdminFactory.recoil"; +import * as _90 from "./contracts/CwCodeIdRegistry.types"; +import * as _91 from "./contracts/CwCodeIdRegistry.client"; +import * as _92 from "./contracts/CwCodeIdRegistry.message-composer"; +import * as _93 from "./contracts/CwCodeIdRegistry.react-query"; +import * as _94 from "./contracts/CwCodeIdRegistry.recoil"; +import * as _95 from "./contracts/CwSingle.types"; +import * as _96 from "./contracts/CwSingle.client"; +import * as _97 from "./contracts/CwSingle.message-composer"; +import * as _98 from "./contracts/CwSingle.react-query"; +import * as _99 from "./contracts/CwSingle.recoil"; +export namespace smart { + export namespace contracts { + export const Factory = { ..._75, + ..._76, + ..._77, + ..._78, + ..._79 + }; + export const Minter = { ..._80, + ..._81, + ..._82, + ..._83, + ..._84 + }; + export const CwAdminFactory = { ..._85, + ..._86, + ..._87, + ..._88, + ..._89 + }; + export const CwCodeIdRegistry = { ..._90, + ..._91, + ..._92, + ..._93, + ..._94 + }; + export const CwSingle = { ..._95, + ..._96, + ..._97, + ..._98, + ..._99 + }; + } +} \ No newline at end of file diff --git a/__output__/builder/default/index.ts b/__output__/builder/default/index.ts index 7b947b6b..d991e94c 100644 --- a/__output__/builder/default/index.ts +++ b/__output__/builder/default/index.ts @@ -7,33 +7,33 @@ import * as _15 from "./Factory.types"; import * as _16 from "./Factory.client"; import * as _17 from "./Factory.message-composer"; -import * as _18 from "./Factory.msg-builder"; -import * as _19 from "./Factory.react-query"; -import * as _20 from "./Factory.recoil"; +import * as _18 from "./Factory.react-query"; +import * as _19 from "./Factory.recoil"; +import * as _20 from "./Factory.msg-builder"; import * as _21 from "./Minter.types"; import * as _22 from "./Minter.client"; import * as _23 from "./Minter.message-composer"; -import * as _24 from "./Minter.msg-builder"; -import * as _25 from "./Minter.react-query"; -import * as _26 from "./Minter.recoil"; +import * as _24 from "./Minter.react-query"; +import * as _25 from "./Minter.recoil"; +import * as _26 from "./Minter.msg-builder"; import * as _27 from "./CwAdminFactory.types"; import * as _28 from "./CwAdminFactory.client"; import * as _29 from "./CwAdminFactory.message-composer"; -import * as _30 from "./CwAdminFactory.msg-builder"; -import * as _31 from "./CwAdminFactory.react-query"; -import * as _32 from "./CwAdminFactory.recoil"; +import * as _30 from "./CwAdminFactory.react-query"; +import * as _31 from "./CwAdminFactory.recoil"; +import * as _32 from "./CwAdminFactory.msg-builder"; import * as _33 from "./CwCodeIdRegistry.types"; import * as _34 from "./CwCodeIdRegistry.client"; import * as _35 from "./CwCodeIdRegistry.message-composer"; -import * as _36 from "./CwCodeIdRegistry.msg-builder"; -import * as _37 from "./CwCodeIdRegistry.react-query"; -import * as _38 from "./CwCodeIdRegistry.recoil"; +import * as _36 from "./CwCodeIdRegistry.react-query"; +import * as _37 from "./CwCodeIdRegistry.recoil"; +import * as _38 from "./CwCodeIdRegistry.msg-builder"; import * as _39 from "./CwSingle.types"; import * as _40 from "./CwSingle.client"; import * as _41 from "./CwSingle.message-composer"; -import * as _42 from "./CwSingle.msg-builder"; -import * as _43 from "./CwSingle.react-query"; -import * as _44 from "./CwSingle.recoil"; +import * as _42 from "./CwSingle.react-query"; +import * as _43 from "./CwSingle.recoil"; +import * as _44 from "./CwSingle.msg-builder"; export namespace smart { export namespace contracts { export const Factory = { ..._15, diff --git a/__output__/builder/no-extends/index.ts b/__output__/builder/no-extends/index.ts index 6a2abe65..2c07b1e3 100644 --- a/__output__/builder/no-extends/index.ts +++ b/__output__/builder/no-extends/index.ts @@ -7,33 +7,33 @@ import * as _45 from "./Factory.types"; import * as _46 from "./Factory.client"; import * as _47 from "./Factory.message-composer"; -import * as _48 from "./Factory.msg-builder"; -import * as _49 from "./Factory.react-query"; -import * as _50 from "./Factory.recoil"; +import * as _48 from "./Factory.react-query"; +import * as _49 from "./Factory.recoil"; +import * as _50 from "./Factory.msg-builder"; import * as _51 from "./Minter.types"; import * as _52 from "./Minter.client"; import * as _53 from "./Minter.message-composer"; -import * as _54 from "./Minter.msg-builder"; -import * as _55 from "./Minter.react-query"; -import * as _56 from "./Minter.recoil"; +import * as _54 from "./Minter.react-query"; +import * as _55 from "./Minter.recoil"; +import * as _56 from "./Minter.msg-builder"; import * as _57 from "./CwAdminFactory.types"; import * as _58 from "./CwAdminFactory.client"; import * as _59 from "./CwAdminFactory.message-composer"; -import * as _60 from "./CwAdminFactory.msg-builder"; -import * as _61 from "./CwAdminFactory.react-query"; -import * as _62 from "./CwAdminFactory.recoil"; +import * as _60 from "./CwAdminFactory.react-query"; +import * as _61 from "./CwAdminFactory.recoil"; +import * as _62 from "./CwAdminFactory.msg-builder"; import * as _63 from "./CwCodeIdRegistry.types"; import * as _64 from "./CwCodeIdRegistry.client"; import * as _65 from "./CwCodeIdRegistry.message-composer"; -import * as _66 from "./CwCodeIdRegistry.msg-builder"; -import * as _67 from "./CwCodeIdRegistry.react-query"; -import * as _68 from "./CwCodeIdRegistry.recoil"; +import * as _66 from "./CwCodeIdRegistry.react-query"; +import * as _67 from "./CwCodeIdRegistry.recoil"; +import * as _68 from "./CwCodeIdRegistry.msg-builder"; import * as _69 from "./CwSingle.types"; import * as _70 from "./CwSingle.client"; import * as _71 from "./CwSingle.message-composer"; -import * as _72 from "./CwSingle.msg-builder"; -import * as _73 from "./CwSingle.react-query"; -import * as _74 from "./CwSingle.recoil"; +import * as _72 from "./CwSingle.react-query"; +import * as _73 from "./CwSingle.recoil"; +import * as _74 from "./CwSingle.msg-builder"; export namespace smart { export namespace contracts { export const Factory = { ..._45, diff --git a/packages/ts-codegen/__tests__/__snapshots__/builder.test.ts.snap b/packages/ts-codegen/__tests__/__snapshots__/builder.test.ts.snap index a765e207..21f9e9a1 100644 --- a/packages/ts-codegen/__tests__/__snapshots__/builder.test.ts.snap +++ b/packages/ts-codegen/__tests__/__snapshots__/builder.test.ts.snap @@ -14,6 +14,7 @@ TSBuilder { "execExtendsQuery": true, "noImplicitOverride": false, }, + "enabled": true, "messageComposer": Object { "enabled": false, }, @@ -36,6 +37,232 @@ TSBuilder { "enabled": true, }, }, + "plugins": Array [ + TypesPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ClientPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + MessageComposerPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ReactQueryPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + RecoilPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": Object { + "selectorFamily": "recoil", + }, + }, + MsgBuilderPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": true, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ], } `; @@ -53,6 +280,7 @@ TSBuilder { "execExtendsQuery": true, "noImplicitOverride": false, }, + "enabled": true, "messageComposer": Object { "enabled": false, }, @@ -75,5 +303,231 @@ TSBuilder { "enabled": true, }, }, + "plugins": Array [ + TypesPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ClientPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + MessageComposerPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ReactQueryPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + RecoilPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": Object { + "selectorFamily": "recoil", + }, + }, + MsgBuilderPlugin { + "option": Object { + "bundle": Object { + "bundleFile": "bundle.ts", + "enabled": true, + "scope": "contracts", + }, + "client": Object { + "enabled": true, + "execExtendsQuery": true, + "noImplicitOverride": false, + }, + "enabled": true, + "messageComposer": Object { + "enabled": false, + }, + "msgBuilder": Object { + "enabled": false, + }, + "reactQuery": Object { + "camelize": true, + "enabled": false, + "mutations": false, + "optionalClient": false, + "queryKeys": false, + "version": "v3", + }, + "recoil": Object { + "enabled": false, + }, + "types": Object { + "aliasExecuteMsg": false, + "enabled": true, + }, + }, + "utils": undefined, + }, + ], } `; diff --git a/packages/ts-codegen/__tests__/builder.test.ts b/packages/ts-codegen/__tests__/builder.test.ts index f8424330..29603e2b 100644 --- a/packages/ts-codegen/__tests__/builder.test.ts +++ b/packages/ts-codegen/__tests__/builder.test.ts @@ -159,3 +159,46 @@ it('builder no extends', async () => { } }); }); + +it('builder set bundler path', async () => { + const outPath = OUTPUT_DIR + '/bundler_test/contracts'; + const bundlerPath = OUTPUT_DIR + '/bundler_test/'; + const s = (str) => FIXTURE_DIR + str; + await codegen({ + contracts: [ + s('/vectis/factory'), + s('/minter'), + s('/daodao/cw-admin-factory'), + s('/daodao/cw-code-id-registry'), + { + name: 'CwSingle', + dir: s('/daodao/cw-proposal-single') + } + ], + outPath, + options: { + bundle: { + bundlePath: bundlerPath, + bundleFile: 'index.ts', + scope: 'smart.contracts' + }, + types: { + enabled: true + }, + client: { + enabled: true, + execExtendsQuery: false + }, + reactQuery: { + enabled: true + }, + recoil: { + enabled: true + }, + messageComposer: { + enabled: true + } + } + }); +}); + diff --git a/packages/ts-codegen/src/builder/builder.ts b/packages/ts-codegen/src/builder/builder.ts index 7bbaaebc..b17ac22c 100644 --- a/packages/ts-codegen/src/builder/builder.ts +++ b/packages/ts-codegen/src/builder/builder.ts @@ -1,19 +1,13 @@ -import { RenderOptions, defaultOptions } from "wasm-ast-types"; +import { RenderOptions, defaultOptions, RenderContext, ContractInfo, MessageComposerOptions} from "wasm-ast-types"; import { header } from '../utils/header'; import { join } from "path"; import { writeFileSync } from 'fs'; import { sync as mkdirp } from "mkdirp"; -import generateMessageComposer from '../generators/message-composer'; -import generateMsgBuilder from '../generators/msg-builder'; -import generateTypes from '../generators/types'; -import generateReactQuery from '../generators/react-query'; -import generateRecoil from '../generators/recoil'; -import generateClient from '../generators/client'; - import { basename } from 'path'; import { readSchemas } from '../utils'; +import { IBuilderPlugin } from '../plugins'; import deepmerge from 'deepmerge'; import { pascal } from "case"; @@ -21,6 +15,12 @@ import { createFileBundle, recursiveModuleBundle } from "../bundler"; import generate from '@babel/generator'; import * as t from '@babel/types'; +import { ReactQueryPlugin } from "../plugins/react-query"; +import { RecoilPlugin } from "../plugins/recoil"; +import { MsgBuilderPlugin } from "../plugins/msg-builder"; +import { MessageComposerPlugin } from "../plugins/message-composer"; +import { ClientPlugin } from "../plugins/client"; +import { TypesPlugin } from "../plugins/types"; const defaultOpts: TSBuilderOptions = { bundle: { @@ -34,20 +34,25 @@ export interface TSBuilderInput { contracts: Array; outPath: string; options?: TSBuilderOptions; + plugins?: IBuilderPlugin[]; }; export interface BundleOptions { enabled?: boolean; scope?: string; bundleFile?: string; + bundlePath?: string; }; export type TSBuilderOptions = { bundle?: BundleOptions; } & RenderOptions; +export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin'; + export interface BuilderFile { - type: 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder'; + type: BuilderFileType; + pluginType?: string; contract: string; localname: string; filename: string; @@ -57,14 +62,42 @@ export interface ContractFile { name: string; dir: string; } + +function getContract(contractOpt): ContractFile { + if (typeof contractOpt === 'string') { + const name = basename(contractOpt); + const contractName = pascal(name); + return { + name: contractName, + dir: contractOpt + } + } + return { + name: pascal(contractOpt.name), + dir: contractOpt.dir + }; +} + export class TSBuilder { contracts: Array; outPath: string; options?: TSBuilderOptions; + plugins: IBuilderPlugin[] = []; protected files: BuilderFile[] = []; - constructor({ contracts, outPath, options }: TSBuilderInput) { + loadDefaultPlugins() { + [].push.apply(this.plugins, [ + new TypesPlugin(this.options), + new ClientPlugin(this.options), + new MessageComposerPlugin(this.options), + new ReactQueryPlugin(this.options), + new RecoilPlugin(this.options), + new MsgBuilderPlugin(this.options), + ]); + } + + constructor({ contracts, outPath, options, plugins }: TSBuilderInput) { this.contracts = contracts; this.outPath = outPath; this.options = deepmerge( @@ -74,96 +107,43 @@ export class TSBuilder { ), options ?? {} ); - } - getContracts(): ContractFile[] { - return this.contracts.map(contractOpt => { - if (typeof contractOpt === 'string') { - const name = basename(contractOpt); - const contractName = pascal(name); - return { - name: contractName, - dir: contractOpt - } - } - return { - name: pascal(contractOpt.name), - dir: contractOpt.dir - }; - }); - } - - async renderTypes(contract: ContractFile) { - const { enabled, ...options } = this.options.types; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateTypes(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); - } + this.loadDefaultPlugins(); - async renderClient(contract: ContractFile) { - const { enabled, ...options } = this.options.client; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateClient(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); - } - - async renderRecoil(contract: ContractFile) { - const { enabled, ...options } = this.options.recoil; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateRecoil(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); + if (plugins && plugins.length) { + [].push.apply(this.plugins, plugins); + } } - async renderReactQuery(contract: ContractFile) { - const { enabled, ...options } = this.options.reactQuery; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateReactQuery(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); + async build() { + await this.process(); + await this.after(); } - async renderMessageComposer(contract: ContractFile) { - const { enabled, ...options } = this.options.messageComposer; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateMessageComposer(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); + // lifecycle functions + private async process(){ + for (const contractOpt of this.contracts) { + const contract = getContract(contractOpt); + //resolve contract schema. + const contractInfo = await readSchemas({ + schemaDir: contract.dir + }); + + //lifecycle and plugins. + await this.render(contract.name, contractInfo); + } } - async renderMsgBuilder(contract: ContractFile) { - const { enabled, ...options } = this.options.messageComposer; - if (!enabled) return; - const contractInfo = await readSchemas({ - schemaDir: contract.dir - }); - const files = await generateMsgBuilder(contract.name, contractInfo, this.outPath, options); - [].push.apply(this.files, files); + private async render(name: string, contractInfo: ContractInfo){ + for (const plugin of this.plugins) { + let files = await plugin.render(name, contractInfo, this.outPath); + if(files && files.length){ + [].push.apply(this.files, files); + } + } } - async build() { - const contracts = this.getContracts(); - for (let c = 0; c < contracts.length; c++) { - const contract = contracts[c]; - await this.renderTypes(contract); - await this.renderClient(contract); - await this.renderMessageComposer(contract); - await this.renderMsgBuilder(contract); - await this.renderReactQuery(contract); - await this.renderRecoil(contract); - } + private async after(){ if (this.options.bundle.enabled) { this.bundle(); } @@ -174,14 +154,18 @@ export class TSBuilder { const allFiles = this.files; const bundleFile = this.options.bundle.bundleFile; + const bundlePath = join( + this.options?.bundle?.bundlePath ?? this.outPath, + bundleFile + ); const bundleVariables = {}; const importPaths = []; allFiles.forEach(file => { createFileBundle( `${this.options.bundle.scope}.${file.contract}`, - file.localname, - bundleFile, + file.filename, + bundlePath, importPaths, bundleVariables ); @@ -196,11 +180,15 @@ export class TSBuilder { ] )).code; + if(this.options?.bundle?.bundlePath){ + mkdirp(this.options?.bundle?.bundlePath); + } + mkdirp(this.outPath); if (code.trim() === '') code = 'export {};' - writeFileSync(join(this.outPath, bundleFile), header + code); + writeFileSync(bundlePath, header + code); } } diff --git a/packages/ts-codegen/src/index.ts b/packages/ts-codegen/src/index.ts index 472d70fe..f037df7b 100644 --- a/packages/ts-codegen/src/index.ts +++ b/packages/ts-codegen/src/index.ts @@ -9,6 +9,7 @@ export { default as generateRecoil } from './generators/recoil'; export * from './utils'; export * from './builder'; export * from './bundler'; +export * from './plugins'; export default async (input: TSBuilderInput) => { const builder = new TSBuilder(input); diff --git a/packages/ts-codegen/src/plugins/client.ts b/packages/ts-codegen/src/plugins/client.ts new file mode 100644 index 00000000..049e6702 --- /dev/null +++ b/packages/ts-codegen/src/plugins/client.ts @@ -0,0 +1,108 @@ +import { pascal } from 'case'; +import * as w from 'wasm-ast-types'; +import { findExecuteMsg, findAndParseTypes, findQueryMsg } from '../utils'; +import { + RenderContext, + ContractInfo, + RenderContextBase, + getMessageProperties, + RenderOptions +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class ClientPlugin extends BuilderPluginBase { + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const { enabled } = this.option.client; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + + const localname = pascal(name) + '.client.ts'; + const TypesFile = pascal(name) + '.types'; + const QueryMsg = findQueryMsg(schemas); + const ExecuteMsg = findExecuteMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + let Client = null; + let Instance = null; + let QueryClient = null; + let ReadOnlyInstance = null; + + const body = []; + + body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`)); + + // query messages + if (QueryMsg) { + QueryClient = pascal(`${name}QueryClient`); + ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`); + + body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg)); + body.push( + w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg) + ); + } + + // execute messages + if (ExecuteMsg) { + const children = getMessageProperties(ExecuteMsg); + if (children.length > 0) { + Client = pascal(`${name}Client`); + Instance = pascal(`${name}Interface`); + + body.push( + w.createExecuteInterface( + context, + Instance, + this.option.client.execExtendsQuery ? ReadOnlyInstance : null, + ExecuteMsg + ) + ); + + body.push( + w.createExecuteClass( + context, + Client, + Instance, + this.option.client.execExtendsQuery ? QueryClient : null, + ExecuteMsg + ) + ); + } + } + + if (typeHash.hasOwnProperty('Coin')) { + // @ts-ignore + delete context.utils.Coin; + } + + return [ + { + type: 'client', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/src/plugins/index.ts b/packages/ts-codegen/src/plugins/index.ts new file mode 100644 index 00000000..58f95815 --- /dev/null +++ b/packages/ts-codegen/src/plugins/index.ts @@ -0,0 +1 @@ +export * from "./plugin-base" \ No newline at end of file diff --git a/packages/ts-codegen/src/plugins/message-composer.ts b/packages/ts-codegen/src/plugins/message-composer.ts new file mode 100644 index 00000000..6c6caa40 --- /dev/null +++ b/packages/ts-codegen/src/plugins/message-composer.ts @@ -0,0 +1,80 @@ +import { pascal } from 'case'; +import * as w from 'wasm-ast-types'; +import { findAndParseTypes, findExecuteMsg } from '../utils'; +import { + MessageComposerOptions, + getMessageProperties, + ContractInfo, + RenderContextBase, + RenderContext, + RenderOptions +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class MessageComposerPlugin extends BuilderPluginBase { + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const { enabled } = this.option.messageComposer; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + + const localname = pascal(name) + '.message-composer.ts'; + const TypesFile = pascal(name) + '.types'; + const ExecuteMsg = findExecuteMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + const body = []; + + body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`)); + + // execute messages + if (ExecuteMsg) { + const children = getMessageProperties(ExecuteMsg); + if (children.length > 0) { + const TheClass = pascal(`${name}MessageComposer`); + const Interface = pascal(`${name}Message`); + + body.push( + w.createMessageComposerInterface(context, Interface, ExecuteMsg) + ); + body.push( + w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg) + ); + } + } + + if (typeHash.hasOwnProperty('Coin')) { + // @ts-ignore + delete context.utils.Coin; + } + + return [ + { + type: 'message-composer', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/src/plugins/msg-builder.ts b/packages/ts-codegen/src/plugins/msg-builder.ts new file mode 100644 index 00000000..918a3ad3 --- /dev/null +++ b/packages/ts-codegen/src/plugins/msg-builder.ts @@ -0,0 +1,85 @@ +import { pascal } from 'case'; +import * as w from 'wasm-ast-types'; +import { findAndParseTypes, findQueryMsg, findExecuteMsg } from '../utils'; +import { + getMessageProperties, + RenderContext, + RenderContextBase, + ContractInfo, + RenderOptions +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class MsgBuilderPlugin extends BuilderPluginBase { + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const { enabled } = this.option.msgBuilder; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + + const localname = pascal(name) + '.msg-builder.ts'; + const TypesFile = pascal(name) + '.types'; + const ExecuteMsg = findExecuteMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + const body = []; + + body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`)); + body.push(w.importStmt(['CamelCasedProperties'], 'type-fest')); + + // execute messages + if (ExecuteMsg) { + const children = getMessageProperties(ExecuteMsg); + if (children.length > 0) { + const className = pascal(`${name}ExecuteMsgBuilder`); + + body.push(w.createMsgBuilderClass(context, className, ExecuteMsg)); + } + } + + const QueryMsg = findQueryMsg(schemas); + // query messages + if (QueryMsg) { + const children = getMessageProperties(QueryMsg); + if (children.length > 0) { + const className = pascal(`${name}QueryMsgBuilder`); + + body.push(w.createMsgBuilderClass(context, className, QueryMsg)); + } + } + + if (typeHash.hasOwnProperty('Coin')) { + // @ts-ignore + delete context.utils.Coin; + } + + return [ + { + type: 'msg-builder', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/src/plugins/plugin-base.ts b/packages/ts-codegen/src/plugins/plugin-base.ts new file mode 100644 index 00000000..c1dd4e58 --- /dev/null +++ b/packages/ts-codegen/src/plugins/plugin-base.ts @@ -0,0 +1,112 @@ +import { sync as mkdirp } from 'mkdirp'; +import { join } from 'path'; +import { writeFileSync } from 'fs'; +import { header } from '../utils/header'; +import { + ContractInfo, + UtilMapping, + IContext +} from 'wasm-ast-types'; +import generate from '@babel/generator'; +import * as t from '@babel/types'; +import { BuilderFile, BuilderFileType, TSBuilderOptions } from '../builder'; + +/** + * IBuilderPlugin is a common plugin that render generated code. + */ +export interface IBuilderPlugin { + /** + * a mapping of utils will be used in generated code. + */ + utils: UtilMapping; + + /** + * render generated cdoe. + * @param name the name of contract + * @param contractInfo contract + * @param outPath the path of generated code. + * @returns info of generated files. + */ + render( + name: string, + contractInfo: ContractInfo, + outPath: string, + ): Promise; +} + +/** + * BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions. + */ +export abstract class BuilderPluginBase implements IBuilderPlugin { + option: TOpt; + utils: UtilMapping; + + constructor(opt: TOpt) { + this.option = opt; + } + + async render( + name: string, + contractInfo: ContractInfo, + outPath: string + ): Promise { + const { enabled } = this.option; + + if (!enabled) { + return; + } + + const context = this.initContext(contractInfo, this.option); + + const results = await this.doRender(name, context); + + if (!results || !results.length) { + return []; + } + + return results.map((result) => { + const imports = context.getImports(this.utils); + const code = + header + generate(t.program([...imports, ...result.body])).code; + + mkdirp(outPath); + const filename = join(outPath, result.localname); + writeFileSync(filename, code); + + return { + type: result.type, + pluginType: result.pluginType, + contract: name, + localname: result.localname, + filename + }; + }); + } + + /** + * init context here + * @param contract + * @param options + */ + abstract initContext( + contract: ContractInfo, + options?: TOpt + ): IContext; + + /** + * render generated code here. + * @param name + * @param context + */ + abstract doRender( + name: string, + context: IContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + >; +} diff --git a/packages/ts-codegen/src/plugins/react-query.ts b/packages/ts-codegen/src/plugins/react-query.ts new file mode 100644 index 00000000..67585351 --- /dev/null +++ b/packages/ts-codegen/src/plugins/react-query.ts @@ -0,0 +1,115 @@ +import { pascal } from 'case'; +import * as w from 'wasm-ast-types'; +import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils'; +import { + getMessageProperties, + ContractInfo, + RenderOptions, + RenderContextBase, + RenderContext +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class ReactQueryPlugin extends BuilderPluginBase { + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const options = this.option.reactQuery; + + const { enabled } = options; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + + const localname = pascal(`${name}`) + '.react-query.ts'; + const ContractFile = pascal(`${name}`) + '.client'; + const TypesFile = pascal(`${name}`) + '.types'; + + const QueryMsg = findQueryMsg(schemas); + const ExecuteMsg = findExecuteMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + const ExecuteClient = pascal(`${name}Client`); + const QueryClient = pascal(`${name}QueryClient`); + + const body = []; + + const clientImports = []; + + QueryMsg && clientImports.push(QueryClient); + + // check that there are commands within the exec msg + const shouldGenerateMutationHooks = + ExecuteMsg && + options?.version === 'v4' && + options?.mutations && + getMessageProperties(ExecuteMsg).length > 0; + + if (shouldGenerateMutationHooks) { + clientImports.push(ExecuteClient); + } + + // general contract imports + body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`)); + + // client imports + body.push(w.importStmt(clientImports, `./${ContractFile}`)); + + // query messages + if (QueryMsg) { + [].push.apply( + body, + w.createReactQueryHooks({ + context, + queryMsg: QueryMsg, + contractName: name, + QueryClient + }) + ); + } + + if (shouldGenerateMutationHooks) { + [].push.apply( + body, + w.createReactQueryMutationHooks({ + context, + execMsg: ExecuteMsg, + contractName: name, + ExecuteClient + }) + ); + } + + if (typeHash.hasOwnProperty('Coin')) { + // @ts-ignore + delete context.utils.Coin; + } + + return [ + { + type: 'react-query', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/src/plugins/recoil.ts b/packages/ts-codegen/src/plugins/recoil.ts new file mode 100644 index 00000000..cb1803fa --- /dev/null +++ b/packages/ts-codegen/src/plugins/recoil.ts @@ -0,0 +1,89 @@ +import { pascal } from 'case'; +import * as w from 'wasm-ast-types'; +import { findAndParseTypes, findQueryMsg } from '../utils'; +import { + ContractInfo, + RenderContext, + RenderContextBase, + UtilMapping, + RenderOptions +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class RecoilPlugin extends BuilderPluginBase { + utils: UtilMapping = { + selectorFamily: 'recoil', + }; + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const { enabled } = this.option.recoil; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + + const localname = pascal(name) + '.recoil.ts'; + const ContractFile = pascal(name) + '.client'; + const TypesFile = pascal(name) + '.types'; + + const QueryMsg = findQueryMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + let QueryClient = null; + let ReadOnlyInstance = null; + + const body = []; + + body.push(w.importStmt(['cosmWasmClient'], './chain')); + + body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`)); + + // query messages + if (QueryMsg) { + QueryClient = pascal(`${name}QueryClient`); + ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`); + + body.push(w.importStmt([QueryClient], `./${ContractFile}`)); + + body.push(w.createRecoilQueryClientType()); + body.push(w.createRecoilQueryClient(context, name, QueryClient)); + + [].push.apply( + body, + w.createRecoilSelectors(context, name, QueryClient, QueryMsg) + ); + } + + if (typeHash.hasOwnProperty('Coin')) { + // @ts-ignore + delete context.utils.Coin; + } + + return [ + { + type: 'recoil', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/src/plugins/types.ts b/packages/ts-codegen/src/plugins/types.ts new file mode 100644 index 00000000..cfb74844 --- /dev/null +++ b/packages/ts-codegen/src/plugins/types.ts @@ -0,0 +1,74 @@ +import * as t from '@babel/types'; +import { clean } from '../utils/clean'; +import { pascal } from 'case'; +import { findExecuteMsg, findAndParseTypes, findQueryMsg } from '../utils'; +import { + ContractInfo, + RenderContext, + RenderContextBase, + RenderOptions +} from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; + +export class TypesPlugin extends BuilderPluginBase { + initContext( + contract: ContractInfo, + options?: RenderOptions + ): RenderContextBase { + return new RenderContext(contract, options); + } + + async doRender( + name: string, + context: RenderContext + ): Promise< + { + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[] + > { + const { enabled } = this.option.types; + + if (!enabled) { + return; + } + + const { schemas } = context.contract; + const options = this.option.types; + + const localname = pascal(name) + '.types.ts'; + const ExecuteMsg = findExecuteMsg(schemas); + const typeHash = await findAndParseTypes(schemas); + + const body = []; + + // TYPES + Object.values(typeHash).forEach((type: t.Node) => { + body.push(clean(type)); + }); + + // alias the ExecuteMsg + if (options.aliasExecuteMsg && ExecuteMsg) { + body.push( + t.exportNamedDeclaration( + t.tsTypeAliasDeclaration( + t.identifier(`${name}ExecuteMsg`), + null, + t.tsTypeReference(t.identifier('ExecuteMsg')) + ) + ) + ); + } + + return [ + { + type: 'type', + localname, + body + } + ]; + } +} diff --git a/packages/ts-codegen/types/src/builder/builder.d.ts b/packages/ts-codegen/types/src/builder/builder.d.ts index 7bf170f9..fd4d598d 100644 --- a/packages/ts-codegen/types/src/builder/builder.d.ts +++ b/packages/ts-codegen/types/src/builder/builder.d.ts @@ -1,19 +1,24 @@ import { RenderOptions } from "wasm-ast-types"; +import { IBuilderPlugin } from '../plugins'; export interface TSBuilderInput { contracts: Array; outPath: string; options?: TSBuilderOptions; + plugins?: IBuilderPlugin[]; } export interface BundleOptions { enabled?: boolean; scope?: string; bundleFile?: string; + bundlePath?: string; } -export declare type TSBuilderOptions = { +export type TSBuilderOptions = { bundle?: BundleOptions; } & RenderOptions; +export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin'; export interface BuilderFile { - type: 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder'; + type: BuilderFileType; + pluginType?: string; contract: string; localname: string; filename: string; @@ -26,15 +31,13 @@ export declare class TSBuilder { contracts: Array; outPath: string; options?: TSBuilderOptions; + plugins: IBuilderPlugin[]; protected files: BuilderFile[]; - constructor({ contracts, outPath, options }: TSBuilderInput); - getContracts(): ContractFile[]; - renderTypes(contract: ContractFile): Promise; - renderClient(contract: ContractFile): Promise; - renderRecoil(contract: ContractFile): Promise; - renderReactQuery(contract: ContractFile): Promise; - renderMessageComposer(contract: ContractFile): Promise; - renderMsgBuilder(contract: ContractFile): Promise; + loadDefaultPlugins(): void; + constructor({ contracts, outPath, options, plugins }: TSBuilderInput); build(): Promise; + private process; + private render; + private after; bundle(): Promise; } diff --git a/packages/ts-codegen/types/src/generators/msg-builder.d.ts b/packages/ts-codegen/types/src/generators/msg-builder.d.ts new file mode 100644 index 00000000..26b45bbe --- /dev/null +++ b/packages/ts-codegen/types/src/generators/msg-builder.d.ts @@ -0,0 +1,5 @@ +import { ContractInfo } from "wasm-ast-types"; +import { MsgBuilderOptions } from 'wasm-ast-types'; +import { BuilderFile } from "../builder"; +declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, msgBuilderOptions?: MsgBuilderOptions) => Promise; +export default _default; diff --git a/packages/ts-codegen/types/src/index.d.ts b/packages/ts-codegen/types/src/index.d.ts index 871f47de..e53bb80f 100644 --- a/packages/ts-codegen/types/src/index.d.ts +++ b/packages/ts-codegen/types/src/index.d.ts @@ -7,5 +7,6 @@ export { default as generateRecoil } from './generators/recoil'; export * from './utils'; export * from './builder'; export * from './bundler'; +export * from './plugins'; declare const _default: (input: TSBuilderInput) => Promise; export default _default; diff --git a/packages/ts-codegen/types/src/plugins/client.d.ts b/packages/ts-codegen/types/src/plugins/client.d.ts new file mode 100644 index 00000000..43e278b5 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/client.d.ts @@ -0,0 +1,12 @@ +import { RenderContext, ContractInfo, RenderContextBase, RenderOptions } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class ClientPlugin extends BuilderPluginBase { + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/index.d.ts b/packages/ts-codegen/types/src/plugins/index.d.ts new file mode 100644 index 00000000..b6bdd472 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/index.d.ts @@ -0,0 +1 @@ +export * from "./plugin-base"; diff --git a/packages/ts-codegen/types/src/plugins/message-composer.d.ts b/packages/ts-codegen/types/src/plugins/message-composer.d.ts new file mode 100644 index 00000000..80f98965 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/message-composer.d.ts @@ -0,0 +1,12 @@ +import { ContractInfo, RenderContextBase, RenderContext, RenderOptions } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class MessageComposerPlugin extends BuilderPluginBase { + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/msg-builder.d.ts b/packages/ts-codegen/types/src/plugins/msg-builder.d.ts new file mode 100644 index 00000000..bd5e0467 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/msg-builder.d.ts @@ -0,0 +1,12 @@ +import { RenderContext, RenderContextBase, ContractInfo, RenderOptions } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class MsgBuilderPlugin extends BuilderPluginBase { + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/plugin-base.d.ts b/packages/ts-codegen/types/src/plugins/plugin-base.d.ts new file mode 100644 index 00000000..efa14960 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/plugin-base.d.ts @@ -0,0 +1,47 @@ +import { ContractInfo, UtilMapping, IContext } from 'wasm-ast-types'; +import { BuilderFile, BuilderFileType } from '../builder'; +/** + * IBuilderPlugin is a common plugin that render generated code. + */ +export interface IBuilderPlugin { + /** + * a mapping of utils will be used in generated code. + */ + utils: UtilMapping; + /** + * render generated cdoe. + * @param name the name of contract + * @param contractInfo contract + * @param outPath the path of generated code. + * @returns info of generated files. + */ + render(name: string, contractInfo: ContractInfo, outPath: string): Promise; +} +/** + * BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions. + */ +export declare abstract class BuilderPluginBase implements IBuilderPlugin { + option: TOpt; + utils: UtilMapping; + constructor(opt: TOpt); + render(name: string, contractInfo: ContractInfo, outPath: string): Promise; + /** + * init context here + * @param contract + * @param options + */ + abstract initContext(contract: ContractInfo, options?: TOpt): IContext; + /** + * render generated code here. + * @param name + * @param context + */ + abstract doRender(name: string, context: IContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/react-query.d.ts b/packages/ts-codegen/types/src/plugins/react-query.d.ts new file mode 100644 index 00000000..ff34e39a --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/react-query.d.ts @@ -0,0 +1,12 @@ +import { ContractInfo, RenderOptions, RenderContextBase, RenderContext } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class ReactQueryPlugin extends BuilderPluginBase { + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/recoil.d.ts b/packages/ts-codegen/types/src/plugins/recoil.d.ts new file mode 100644 index 00000000..16c70a39 --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/recoil.d.ts @@ -0,0 +1,13 @@ +import { ContractInfo, RenderContext, RenderContextBase, UtilMapping, RenderOptions } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class RecoilPlugin extends BuilderPluginBase { + utils: UtilMapping; + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/ts-codegen/types/src/plugins/types.d.ts b/packages/ts-codegen/types/src/plugins/types.d.ts new file mode 100644 index 00000000..b45d780c --- /dev/null +++ b/packages/ts-codegen/types/src/plugins/types.d.ts @@ -0,0 +1,12 @@ +import { ContractInfo, RenderContext, RenderContextBase, RenderOptions } from 'wasm-ast-types'; +import { BuilderFileType } from '../builder'; +import { BuilderPluginBase } from './plugin-base'; +export declare class TypesPlugin extends BuilderPluginBase { + initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase; + doRender(name: string, context: RenderContext): Promise<{ + type: BuilderFileType; + pluginType?: string; + localname: string; + body: any[]; + }[]>; +} diff --git a/packages/wasm-ast-types/src/context/context.ts b/packages/wasm-ast-types/src/context/context.ts index b93ac877..2b325705 100644 --- a/packages/wasm-ast-types/src/context/context.ts +++ b/packages/wasm-ast-types/src/context/context.ts @@ -1,5 +1,5 @@ import { JSONSchema } from "../types"; -import { convertUtilsToImportList, getImportStatements } from "./imports"; +import { convertUtilsToImportList, getImportStatements, UtilMapping } from "./imports"; import deepmerge from "deepmerge"; /// Plugin Types @@ -55,6 +55,7 @@ export interface ContractInfo { idlObject?: IDLObject; }; export interface RenderOptions { + enabled?: boolean; types?: TSTypesOptions; recoil?: RecoilOptions; messageComposer?: MessageComposerOptions; @@ -63,12 +64,20 @@ export interface RenderOptions { reactQuery?: ReactQueryOptions; } -export interface RenderContext { + +export interface IContext { + refLookup($ref: string); + addUtil(util: string); + getImports(registeredUtils?: UtilMapping); +} + +export interface IRenderContext extends IContext { contract: ContractInfo; - options: RenderOptions; + options: TOpt; } export const defaultOptions: RenderOptions = { + enabled: true, types: { enabled: true, aliasExecuteMsg: false @@ -114,18 +123,30 @@ export const getDefinitionSchema = (schemas: JSONSchema[]): JSONSchema => { return aggregateSchema; }; -export class RenderContext implements RenderContext { + +/** + * context object for generating code. + * only mergeDefaultOpt needs to implementing for combine options and default options. + * @param TOpt option type + */ +export abstract class RenderContextBase implements IRenderContext { contract: ContractInfo; utils: string[] = []; schema: JSONSchema; + options: TOpt; constructor( contract: ContractInfo, - options?: RenderOptions + options?: TOpt ) { this.contract = contract; this.schema = getDefinitionSchema(contract.schemas); - this.options = deepmerge(defaultOptions, options ?? {}); + this.options = this.mergeDefaultOpt(options); } + /** + * merge options and default options + * @param options + */ + abstract mergeDefaultOpt(options: TOpt): TOpt; refLookup($ref: string) { const refName = $ref.replace('#/definitions/', '') return this.schema.definitions?.[refName]; @@ -133,12 +154,19 @@ export class RenderContext implements RenderContext { addUtil(util: string) { this.utils[util] = true; } - getImports() { + getImports(registeredUtils?: UtilMapping) { return getImportStatements( convertUtilsToImportList( this, - Object.keys(this.utils) + Object.keys(this.utils), + registeredUtils, ) ); } } + +export class RenderContext extends RenderContextBase{ + mergeDefaultOpt(options: RenderOptions): RenderOptions { + return deepmerge(defaultOptions, options ?? {}); + } +} diff --git a/packages/wasm-ast-types/src/context/imports.ts b/packages/wasm-ast-types/src/context/imports.ts index dcecdd29..8669b81a 100644 --- a/packages/wasm-ast-types/src/context/imports.ts +++ b/packages/wasm-ast-types/src/context/imports.ts @@ -2,6 +2,7 @@ import * as t from '@babel/types'; import { importAs, importStmt } from "../utils"; import { RenderContext } from './context'; + export interface ImportObj { type: 'import' | 'default' | 'namespace'; name: string; @@ -9,6 +10,14 @@ export interface ImportObj { importAs?: string; } +export type GetUtilFn = ((...args: any[]) => (context: TContext) => ImportObj); +export type UtilMapping = { + [key: string]: + | ImportObj + | string + | GetUtilFn +}; + const makeReactQuerySwitch = (varName) => { return (context: RenderContext) => { switch (context.options.reactQuery.version) { @@ -30,11 +39,11 @@ const makeReactQuerySwitch = (varName) => { } export const UTILS = { + selectorFamily: 'recoil', MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx', MsgExecuteContractEncodeObject: 'cosmwasm', Coin: '@cosmjs/amino', toUtf8: '@cosmjs/encoding', - selectorFamily: 'recoil', StdFee: '@cosmjs/amino', CosmWasmClient: '@cosmjs/cosmwasm-stargate', ExecuteResult: '@cosmjs/cosmwasm-stargate', @@ -50,23 +59,48 @@ export const UTILS = { export const convertUtilsToImportList = ( context: RenderContext, - utils: string[] + utils: string[], + registeredUtils?: UtilMapping ): ImportObj[] => { - return utils.map(util => { - if (!UTILS.hasOwnProperty(util)) throw new Error(`missing Util! ::[${util}]`); - if (typeof UTILS[util] === 'string') { - return { - type: 'import', - path: UTILS[util], - name: util - }; - } else if (typeof UTILS[util] === 'function') { - return UTILS[util](context); - } else { - UTILS[util]; + return utils.map((util) => { + let result = null; + + if(registeredUtils){ + result = convertUtil(context, util, registeredUtils); + + if (result) { + return result; + } } + + result = convertUtil(context, util, UTILS); + + if (result) { + return result; + } + + throw new Error(`missing Util! ::[${util}]`); }); -} +}; + +export const convertUtil = ( + context: RenderContext, + util: string, + registeredUtils: object +): ImportObj => { + if (!registeredUtils.hasOwnProperty(util)) return null; + if (typeof registeredUtils[util] === 'string') { + return { + type: 'import', + path: registeredUtils[util], + name: util + }; + } else if (typeof registeredUtils[util] === 'function') { + return registeredUtils[util](context); + } else { + return registeredUtils[util]; + } +}; export const getImportStatements = (list: ImportObj[]) => { const imports = list.reduce((m, obj) => { diff --git a/packages/wasm-ast-types/src/react-query/react-query.ts b/packages/wasm-ast-types/src/react-query/react-query.ts index 6a6a50a5..29ddc4cb 100644 --- a/packages/wasm-ast-types/src/react-query/react-query.ts +++ b/packages/wasm-ast-types/src/react-query/react-query.ts @@ -432,7 +432,7 @@ export const createReactQueryMutationArgsInterface = ({ // @ts-ignore:next-line param.typeAnnotation, param.optional - ) + ) as t.TSTypeElement ) ) ) diff --git a/packages/wasm-ast-types/types/context/context.d.ts b/packages/wasm-ast-types/types/context/context.d.ts index a5a006ab..073ca6cd 100644 --- a/packages/wasm-ast-types/types/context/context.d.ts +++ b/packages/wasm-ast-types/types/context/context.d.ts @@ -1,4 +1,5 @@ import { JSONSchema } from "../types"; +import { UtilMapping } from "./imports"; export interface ReactQueryOptions { enabled?: boolean; optionalClient?: boolean; @@ -46,6 +47,7 @@ export interface ContractInfo { idlObject?: IDLObject; } export interface RenderOptions { + enabled?: boolean; types?: TSTypesOptions; recoil?: RecoilOptions; messageComposer?: MessageComposerOptions; @@ -53,19 +55,38 @@ export interface RenderOptions { client?: TSClientOptions; reactQuery?: ReactQueryOptions; } -export interface RenderContext { +export interface IContext { + refLookup($ref: string): any; + addUtil(util: string): any; + getImports(registeredUtils?: UtilMapping): any; +} +export interface IRenderContext extends IContext { contract: ContractInfo; - options: RenderOptions; + options: TOpt; } export declare const defaultOptions: RenderOptions; export declare const getDefinitionSchema: (schemas: JSONSchema[]) => JSONSchema; -export declare class RenderContext implements RenderContext { +/** + * context object for generating code. + * only mergeDefaultOpt needs to implementing for combine options and default options. + * @param TOpt option type + */ +export declare abstract class RenderContextBase implements IRenderContext { contract: ContractInfo; utils: string[]; schema: JSONSchema; - constructor(contract: ContractInfo, options?: RenderOptions); + options: TOpt; + constructor(contract: ContractInfo, options?: TOpt); + /** + * merge options and default options + * @param options + */ + abstract mergeDefaultOpt(options: TOpt): TOpt; refLookup($ref: string): JSONSchema; addUtil(util: string): void; - getImports(): any[]; + getImports(registeredUtils?: UtilMapping): any; +} +export declare class RenderContext extends RenderContextBase { + mergeDefaultOpt(options: RenderOptions): RenderOptions; } export {}; diff --git a/packages/wasm-ast-types/types/context/imports.d.ts b/packages/wasm-ast-types/types/context/imports.d.ts index c7b0ac7a..d88549ce 100644 --- a/packages/wasm-ast-types/types/context/imports.d.ts +++ b/packages/wasm-ast-types/types/context/imports.d.ts @@ -5,12 +5,16 @@ export interface ImportObj { path: string; importAs?: string; } +export type GetUtilFn = ((...args: any[]) => (context: TContext) => ImportObj); +export type UtilMapping = { + [key: string]: ImportObj | string | GetUtilFn; +}; export declare const UTILS: { + selectorFamily: string; MsgExecuteContract: string; MsgExecuteContractEncodeObject: string; Coin: string; toUtf8: string; - selectorFamily: string; StdFee: string; CosmWasmClient: string; ExecuteResult: string; @@ -36,5 +40,6 @@ export declare const UTILS: { name: any; }; }; -export declare const convertUtilsToImportList: (context: RenderContext, utils: string[]) => ImportObj[]; +export declare const convertUtilsToImportList: (context: RenderContext, utils: string[], registeredUtils?: UtilMapping) => ImportObj[]; +export declare const convertUtil: (context: RenderContext, util: string, registeredUtils: object) => ImportObj; export declare const getImportStatements: (list: ImportObj[]) => any[]; diff --git a/packages/wasm-ast-types/types/index.d.ts b/packages/wasm-ast-types/types/index.d.ts index f92ecfa2..9c493b78 100644 --- a/packages/wasm-ast-types/types/index.d.ts +++ b/packages/wasm-ast-types/types/index.d.ts @@ -3,6 +3,6 @@ export * from './client'; export * from './context'; export * from './recoil'; export * from './message-composer'; -export * from './msg-builder'; export * from './react-query'; export * from './types'; +export * from './msg-builder'; diff --git a/packages/wasm-ast-types/types/msg-builder/msg-builder.d.ts b/packages/wasm-ast-types/types/msg-builder/msg-builder.d.ts index 4a3f0edb..26f00fc8 100644 --- a/packages/wasm-ast-types/types/msg-builder/msg-builder.d.ts +++ b/packages/wasm-ast-types/types/msg-builder/msg-builder.d.ts @@ -1,4 +1,4 @@ -import * as t from '@babel/types'; -import { ExecuteMsg, QueryMsg } from '../types'; -import { RenderContext } from '../context'; +import * as t from "@babel/types"; +import { ExecuteMsg, QueryMsg } from "../types"; +import { RenderContext } from "../context"; export declare const createMsgBuilderClass: (context: RenderContext, className: string, msg: ExecuteMsg | QueryMsg) => t.ExportNamedDeclaration; diff --git a/packages/wasm-ast-types/types/react-query/react-query.d.ts b/packages/wasm-ast-types/types/react-query/react-query.d.ts index 697ff0d7..0684ece4 100644 --- a/packages/wasm-ast-types/types/react-query/react-query.d.ts +++ b/packages/wasm-ast-types/types/react-query/react-query.d.ts @@ -30,16 +30,17 @@ interface ReactQueryMutationHookInterface { /** * Example: ``` -export interface Cw4UpdateMembersMutation { - client: Cw4GroupClient - args: { - tokenId: string - remove: string[] - } - options?: Omit< - UseMutationOptions>, - 'mutationFn' - > + export interface Cw721RevokeMutation { + client: Cw721Client; + msg: { + spender: string; + tokenId: string; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; } ``` */ diff --git a/packages/wasm-ast-types/types/utils/babel.d.ts b/packages/wasm-ast-types/types/utils/babel.d.ts index 2a86d792..9147f72e 100644 --- a/packages/wasm-ast-types/types/utils/babel.d.ts +++ b/packages/wasm-ast-types/types/utils/babel.d.ts @@ -16,6 +16,7 @@ export declare const callExpression: (callee: t.Expression | t.V8IntrinsicIdenti export declare const bindMethod: (name: string) => t.ExpressionStatement; export declare const typedIdentifier: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.Identifier; export declare const promiseTypeAnnotation: (name: any) => t.TSTypeAnnotation; +export declare const abstractClassDeclaration: (name: string, body: any[], implementsExressions?: TSExpressionWithTypeArguments[], superClass?: t.Identifier) => t.ClassDeclaration; export declare const classDeclaration: (name: string, body: any[], implementsExressions?: TSExpressionWithTypeArguments[], superClass?: t.Identifier) => t.ClassDeclaration; export declare const classProperty: (name: string, typeAnnotation?: TSTypeAnnotation, isReadonly?: boolean, isStatic?: boolean, noImplicitOverride?: boolean) => t.ClassProperty; export declare const arrowFunctionExpression: (params: (t.Identifier | t.Pattern | t.RestElement)[], body: t.BlockStatement, returnType: t.TSTypeAnnotation, isAsync?: boolean) => t.ArrowFunctionExpression;