From 014013aa0e11545b86ea2940a8932676fd236915 Mon Sep 17 00:00:00 2001 From: muniz-side <141912162+muniz-side@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:41:35 +0800 Subject: [PATCH] feat: the cosmoswasm contract compiles the ts execution library (#34) * feat: the cosmoswasm contract compiles the ts execution library * feat: codegen dir * build: rm cosmoswasm-codegen * cleanup --------- Co-authored-by: Amit Yadav --- .gitignore | 3 +- README.md | 15 +- codegen/cosmoswasm-codegen/Ics100.client.ts | 310 +++++++++ codegen/cosmoswasm-codegen/Ics100.provider.ts | 18 + .../cosmoswasm-codegen/Ics100.react-query.ts | 294 ++++++++ codegen/cosmoswasm-codegen/Ics100.types.ts | 124 ++++ codegen/cosmoswasm-codegen/Ics101.client.ts | 649 ++++++++++++++++++ codegen/cosmoswasm-codegen/Ics101.provider.ts | 18 + .../cosmoswasm-codegen/Ics101.react-query.ts | 645 +++++++++++++++++ codegen/cosmoswasm-codegen/Ics101.types.ts | 196 ++++++ .../cosmoswasm-codegen/contractContextBase.ts | 97 +++ .../contractContextProviders.ts | 30 + .../cosmoswasm-codegen/contracts-context.tsx | 78 +++ codegen/cosmoswasm-codegen/index.ts | 35 + codegen/index.ts | 51 ++ codegen/package.json | 13 + codegen/tsconfig.json | 109 +++ 17 files changed, 2683 insertions(+), 2 deletions(-) create mode 100644 codegen/cosmoswasm-codegen/Ics100.client.ts create mode 100644 codegen/cosmoswasm-codegen/Ics100.provider.ts create mode 100644 codegen/cosmoswasm-codegen/Ics100.react-query.ts create mode 100644 codegen/cosmoswasm-codegen/Ics100.types.ts create mode 100644 codegen/cosmoswasm-codegen/Ics101.client.ts create mode 100644 codegen/cosmoswasm-codegen/Ics101.provider.ts create mode 100644 codegen/cosmoswasm-codegen/Ics101.react-query.ts create mode 100644 codegen/cosmoswasm-codegen/Ics101.types.ts create mode 100644 codegen/cosmoswasm-codegen/contractContextBase.ts create mode 100644 codegen/cosmoswasm-codegen/contractContextProviders.ts create mode 100644 codegen/cosmoswasm-codegen/contracts-context.tsx create mode 100644 codegen/cosmoswasm-codegen/index.ts create mode 100644 codegen/index.ts create mode 100644 codegen/package.json create mode 100644 codegen/tsconfig.json diff --git a/.gitignore b/.gitignore index 8953165..680a2aa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Cargo.lock /.DS_Store contracts/.DS_Store contracts/ics100/.DS_Store -contracts/ics101/.DS_Store \ No newline at end of file +contracts/ics101/.DS_Store +node_modules diff --git a/README.md b/README.md index bbe9848..2a939db 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,17 @@ ibcswap-wasm is a Cosmwasm implementation of the ICS 100 and ICS 101 specificati # Documentation - [ICS100](./docs/ics100.md) -- [ICS101](./docs/ics101.md) \ No newline at end of file +- [ICS101](./docs/ics101.md) + + + + +# run ts-codegen + +[TS-Codegen](https://github.com/CosmWasm/ts-codegen#readme) + +```bash +cd codegen +yarn +yarn ts-codegen +``` \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics100.client.ts b/codegen/cosmoswasm-codegen/Ics100.client.ts new file mode 100644 index 0000000..b4e0d62 --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics100.client.ts @@ -0,0 +1,310 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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, Status, DetailsResponse, MakeSwapMsg, Coin, Height, TakeSwapMsg, ExecuteMsg, CancelSwapMsg, HeightOutput, InstantiateMsg, ListResponse, AtomicSwapOrder, QueryMsg } from "./Ics100.types"; +export interface Ics100ReadOnlyInterface { + contractAddress: string; + list: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }) => Promise; + listByDesiredTaker: ({ + desiredTaker, + limit, + startAfter + }: { + desiredTaker: string; + limit?: number; + startAfter?: string; + }) => Promise; + listByMaker: ({ + limit, + maker, + startAfter + }: { + limit?: number; + maker: string; + startAfter?: string; + }) => Promise; + listByTaker: ({ + limit, + startAfter, + taker + }: { + limit?: number; + startAfter?: string; + taker: string; + }) => Promise; + details: ({ + id + }: { + id: string; + }) => Promise; +} +export class Ics100QueryClient implements Ics100ReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.list = this.list.bind(this); + this.listByDesiredTaker = this.listByDesiredTaker.bind(this); + this.listByMaker = this.listByMaker.bind(this); + this.listByTaker = this.listByTaker.bind(this); + this.details = this.details.bind(this); + } + + list = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list: { + limit, + start_after: startAfter + } + }); + }; + listByDesiredTaker = async ({ + desiredTaker, + limit, + startAfter + }: { + desiredTaker: string; + limit?: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_by_desired_taker: { + desired_taker: desiredTaker, + limit, + start_after: startAfter + } + }); + }; + listByMaker = async ({ + limit, + maker, + startAfter + }: { + limit?: number; + maker: string; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_by_maker: { + limit, + maker, + start_after: startAfter + } + }); + }; + listByTaker = async ({ + limit, + startAfter, + taker + }: { + limit?: number; + startAfter?: string; + taker: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + list_by_taker: { + limit, + start_after: startAfter, + taker + } + }); + }; + details = async ({ + id + }: { + id: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + details: { + id + } + }); + }; +} +export interface Ics100Interface extends Ics100ReadOnlyInterface { + contractAddress: string; + sender: string; + makeSwap: ({ + buyToken, + createTimestamp, + desiredTaker, + expirationTimestamp, + makerAddress, + makerReceivingAddress, + sellToken, + sourceChannel, + sourcePort, + timeoutHeight, + timeoutTimestamp + }: { + buyToken: Coin; + createTimestamp: number; + desiredTaker: string; + expirationTimestamp: number; + makerAddress: string; + makerReceivingAddress: string; + sellToken: Coin; + sourceChannel: string; + sourcePort: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + takeSwap: ({ + createTimestamp, + orderId, + sellToken, + takerAddress, + takerReceivingAddress, + timeoutHeight, + timeoutTimestamp + }: { + createTimestamp: number; + orderId: string; + sellToken: Coin; + takerAddress: string; + takerReceivingAddress: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + cancelSwap: ({ + createTimestamp, + makerAddress, + orderId, + timeoutHeight, + timeoutTimestamp + }: { + createTimestamp: string; + makerAddress: string; + orderId: string; + timeoutHeight: HeightOutput; + timeoutTimestamp: string; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; +} +export class Ics100Client extends Ics100QueryClient implements Ics100Interface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + super(client, contractAddress); + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.makeSwap = this.makeSwap.bind(this); + this.takeSwap = this.takeSwap.bind(this); + this.cancelSwap = this.cancelSwap.bind(this); + } + + makeSwap = async ({ + buyToken, + createTimestamp, + desiredTaker, + expirationTimestamp, + makerAddress, + makerReceivingAddress, + sellToken, + sourceChannel, + sourcePort, + timeoutHeight, + timeoutTimestamp + }: { + buyToken: Coin; + createTimestamp: number; + desiredTaker: string; + expirationTimestamp: number; + makerAddress: string; + makerReceivingAddress: string; + sellToken: Coin; + sourceChannel: string; + sourcePort: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + MakeSwap: { + buy_token: buyToken, + create_timestamp: createTimestamp, + desired_taker: desiredTaker, + expiration_timestamp: expirationTimestamp, + maker_address: makerAddress, + maker_receiving_address: makerReceivingAddress, + sell_token: sellToken, + source_channel: sourceChannel, + source_port: sourcePort, + timeout_height: timeoutHeight, + timeout_timestamp: timeoutTimestamp + } + }, fee, memo, _funds); + }; + takeSwap = async ({ + createTimestamp, + orderId, + sellToken, + takerAddress, + takerReceivingAddress, + timeoutHeight, + timeoutTimestamp + }: { + createTimestamp: number; + orderId: string; + sellToken: Coin; + takerAddress: string; + takerReceivingAddress: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + TakeSwap: { + create_timestamp: createTimestamp, + order_id: orderId, + sell_token: sellToken, + taker_address: takerAddress, + taker_receiving_address: takerReceivingAddress, + timeout_height: timeoutHeight, + timeout_timestamp: timeoutTimestamp + } + }, fee, memo, _funds); + }; + cancelSwap = async ({ + createTimestamp, + makerAddress, + orderId, + timeoutHeight, + timeoutTimestamp + }: { + createTimestamp: string; + makerAddress: string; + orderId: string; + timeoutHeight: HeightOutput; + timeoutTimestamp: string; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + CancelSwap: { + create_timestamp: createTimestamp, + maker_address: makerAddress, + order_id: orderId, + timeout_height: timeoutHeight, + timeout_timestamp: timeoutTimestamp + } + }, fee, memo, _funds); + }; +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics100.provider.ts b/codegen/cosmoswasm-codegen/Ics100.provider.ts new file mode 100644 index 0000000..01392ed --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics100.provider.ts @@ -0,0 +1,18 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 { ContractBase, IContractConstructor, IEmptyClient } from "./contractContextBase"; +import { Ics100Client, Ics100QueryClient } from "./Ics100.client"; +export class Ics100 extends ContractBase { + constructor({ + address, + cosmWasmClient, + signingCosmWasmClient + }: IContractConstructor) { + super(address, cosmWasmClient, signingCosmWasmClient, Ics100Client, Ics100QueryClient, undefined); + } + +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics100.react-query.ts b/codegen/cosmoswasm-codegen/Ics100.react-query.ts new file mode 100644 index 0000000..9f0465d --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics100.react-query.ts @@ -0,0 +1,294 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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, useMutation, UseMutationOptions } from "@tanstack/react-query"; +import { ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Timestamp, Uint64, Uint128, Status, DetailsResponse, MakeSwapMsg, Coin, Height, TakeSwapMsg, ExecuteMsg, CancelSwapMsg, HeightOutput, InstantiateMsg, ListResponse, AtomicSwapOrder, QueryMsg } from "./Ics100.types"; +import { Ics100QueryClient, Ics100Client } from "./Ics100.client"; +export const ics100QueryKeys = { + contract: ([{ + contract: "ics100" + }] as const), + address: (contractAddress: string | undefined) => ([{ ...ics100QueryKeys.contract[0], + address: contractAddress + }] as const), + list: (contractAddress: string | undefined, args?: Record) => ([{ ...ics100QueryKeys.address(contractAddress)[0], + method: "list", + args + }] as const), + listByDesiredTaker: (contractAddress: string | undefined, args?: Record) => ([{ ...ics100QueryKeys.address(contractAddress)[0], + method: "list_by_desired_taker", + args + }] as const), + listByMaker: (contractAddress: string | undefined, args?: Record) => ([{ ...ics100QueryKeys.address(contractAddress)[0], + method: "list_by_maker", + args + }] as const), + listByTaker: (contractAddress: string | undefined, args?: Record) => ([{ ...ics100QueryKeys.address(contractAddress)[0], + method: "list_by_taker", + args + }] as const), + details: (contractAddress: string | undefined, args?: Record) => ([{ ...ics100QueryKeys.address(contractAddress)[0], + method: "details", + args + }] as const) +}; +export const ics100Queries = { + list: ({ + client, + args, + options + }: Ics100ListQuery): UseQueryOptions => ({ + queryKey: ics100QueryKeys.list(client?.contractAddress, args), + queryFn: () => client ? client.list({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + listByDesiredTaker: ({ + client, + args, + options + }: Ics100ListByDesiredTakerQuery): UseQueryOptions => ({ + queryKey: ics100QueryKeys.listByDesiredTaker(client?.contractAddress, args), + queryFn: () => client ? client.listByDesiredTaker({ + desiredTaker: args.desiredTaker, + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + listByMaker: ({ + client, + args, + options + }: Ics100ListByMakerQuery): UseQueryOptions => ({ + queryKey: ics100QueryKeys.listByMaker(client?.contractAddress, args), + queryFn: () => client ? client.listByMaker({ + limit: args.limit, + maker: args.maker, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + listByTaker: ({ + client, + args, + options + }: Ics100ListByTakerQuery): UseQueryOptions => ({ + queryKey: ics100QueryKeys.listByTaker(client?.contractAddress, args), + queryFn: () => client ? client.listByTaker({ + limit: args.limit, + startAfter: args.startAfter, + taker: args.taker + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + details: ({ + client, + args, + options + }: Ics100DetailsQuery): UseQueryOptions => ({ + queryKey: ics100QueryKeys.details(client?.contractAddress, args), + queryFn: () => client ? client.details({ + id: args.id + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }) +}; +export interface Ics100ReactQuery { + client: Ics100QueryClient | undefined; + options?: Omit, "'queryKey' | 'queryFn' | 'initialData'"> & { + initialData?: undefined; + }; +} +export interface Ics100DetailsQuery extends Ics100ReactQuery { + args: { + id: string; + }; +} +export function useIcs100DetailsQuery({ + client, + args, + options +}: Ics100DetailsQuery) { + return useQuery(ics100QueryKeys.details(client?.contractAddress, args), () => client ? client.details({ + id: args.id + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics100ListByTakerQuery extends Ics100ReactQuery { + args: { + limit?: number; + startAfter?: string; + taker: string; + }; +} +export function useIcs100ListByTakerQuery({ + client, + args, + options +}: Ics100ListByTakerQuery) { + return useQuery(ics100QueryKeys.listByTaker(client?.contractAddress, args), () => client ? client.listByTaker({ + limit: args.limit, + startAfter: args.startAfter, + taker: args.taker + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics100ListByMakerQuery extends Ics100ReactQuery { + args: { + limit?: number; + maker: string; + startAfter?: string; + }; +} +export function useIcs100ListByMakerQuery({ + client, + args, + options +}: Ics100ListByMakerQuery) { + return useQuery(ics100QueryKeys.listByMaker(client?.contractAddress, args), () => client ? client.listByMaker({ + limit: args.limit, + maker: args.maker, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics100ListByDesiredTakerQuery extends Ics100ReactQuery { + args: { + desiredTaker: string; + limit?: number; + startAfter?: string; + }; +} +export function useIcs100ListByDesiredTakerQuery({ + client, + args, + options +}: Ics100ListByDesiredTakerQuery) { + return useQuery(ics100QueryKeys.listByDesiredTaker(client?.contractAddress, args), () => client ? client.listByDesiredTaker({ + desiredTaker: args.desiredTaker, + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics100ListQuery extends Ics100ReactQuery { + args: { + limit?: number; + startAfter?: string; + }; +} +export function useIcs100ListQuery({ + client, + args, + options +}: Ics100ListQuery) { + return useQuery(ics100QueryKeys.list(client?.contractAddress, args), () => client ? client.list({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics100CancelSwapMutation { + client: Ics100Client; + msg: { + createTimestamp: string; + makerAddress: string; + orderId: string; + timeoutHeight: HeightOutput; + timeoutTimestamp: string; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs100CancelSwapMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.cancelSwap(msg, fee, memo, funds), options); +} +export interface Ics100TakeSwapMutation { + client: Ics100Client; + msg: { + createTimestamp: number; + orderId: string; + sellToken: Coin; + takerAddress: string; + takerReceivingAddress: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs100TakeSwapMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.takeSwap(msg, fee, memo, funds), options); +} +export interface Ics100MakeSwapMutation { + client: Ics100Client; + msg: { + buyToken: Coin; + createTimestamp: number; + desiredTaker: string; + expirationTimestamp: number; + makerAddress: string; + makerReceivingAddress: string; + sellToken: Coin; + sourceChannel: string; + sourcePort: string; + timeoutHeight: Height; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs100MakeSwapMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.makeSwap(msg, fee, memo, funds), options); +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics100.types.ts b/codegen/cosmoswasm-codegen/Ics100.types.ts new file mode 100644 index 0000000..0fc1e10 --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics100.types.ts @@ -0,0 +1,124 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 type Status = "INITIAL" | "SYNC" | "CANCEL" | "COMPLETE"; +export interface DetailsResponse { + cancel_timestamp?: Timestamp | null; + complete_timestamp?: Timestamp | null; + id: string; + maker: MakeSwapMsg; + path: string; + status: Status; + taker?: TakeSwapMsg | null; + [k: string]: unknown; +} +export interface MakeSwapMsg { + buy_token: Coin; + create_timestamp: number; + desired_taker: string; + expiration_timestamp: number; + maker_address: string; + maker_receiving_address: string; + sell_token: Coin; + source_channel: string; + source_port: string; + timeout_height: Height; + timeout_timestamp: number; + [k: string]: unknown; +} +export interface Coin { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export interface Height { + revision_height: number; + revision_number: number; + [k: string]: unknown; +} +export interface TakeSwapMsg { + create_timestamp: number; + order_id: string; + sell_token: Coin; + taker_address: string; + taker_receiving_address: string; + timeout_height: Height; + timeout_timestamp: number; + [k: string]: unknown; +} +export type ExecuteMsg = { + MakeSwap: MakeSwapMsg; +} | { + TakeSwap: TakeSwapMsg; +} | { + CancelSwap: CancelSwapMsg; +}; +export interface CancelSwapMsg { + create_timestamp: string; + maker_address: string; + order_id: string; + timeout_height: HeightOutput; + timeout_timestamp: string; + [k: string]: unknown; +} +export interface HeightOutput { + revision_height: string; + revision_number: string; + [k: string]: unknown; +} +export interface InstantiateMsg { + [k: string]: unknown; +} +export interface ListResponse { + swaps: AtomicSwapOrder[]; + [k: string]: unknown; +} +export interface AtomicSwapOrder { + cancel_timestamp?: Timestamp | null; + complete_timestamp?: Timestamp | null; + id: string; + maker: MakeSwapMsg; + path: string; + status: Status; + taker?: TakeSwapMsg | null; + [k: string]: unknown; +} +export type QueryMsg = { + list: { + limit?: number | null; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + list_by_desired_taker: { + desired_taker: string; + limit?: number | null; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + list_by_maker: { + limit?: number | null; + maker: string; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + list_by_taker: { + limit?: number | null; + start_after?: string | null; + taker: string; + [k: string]: unknown; + }; +} | { + details: { + id: string; + [k: string]: unknown; + }; +}; \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics101.client.ts b/codegen/cosmoswasm-codegen/Ics101.client.ts new file mode 100644 index 0000000..fb4844b --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics101.client.ts @@ -0,0 +1,649 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 { ExecuteMsg, Uint128, PoolSide, SwapMsgType, MsgMakePoolRequest, PoolAsset, Coin, MsgTakePoolRequest, MsgCancelPoolRequest, MsgSingleAssetDepositRequest, MsgMakeMultiAssetDepositRequest, DepositAsset, MsgCancelMultiAssetDepositRequest, MsgTakeMultiAssetDepositRequest, MsgMultiAssetWithdrawRequest, MsgSwapRequest, InstantiateMsg, QueryMsg } from "./Ics101.types"; +export interface Ics101ReadOnlyInterface { + contractAddress: string; + orderList: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }) => Promise; + order: ({ + orderId, + poolId + }: { + orderId: string; + poolId: string; + }) => Promise; + config: () => Promise; + poolTokenList: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }) => Promise; + poolAddressByToken: ({ + poolId + }: { + poolId: string; + }) => Promise; + interchainPool: ({ + poolId + }: { + poolId: string; + }) => Promise; + interchainPoolList: ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }) => Promise; + leftSwap: ({ + poolId, + tokenIn, + tokenOut + }: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }) => Promise; + rightSwap: ({ + poolId, + tokenIn, + tokenOut + }: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }) => Promise; + queryActiveOrders: ({ + destinationTaker, + poolId, + sourceMaker + }: { + destinationTaker: string; + poolId: string; + sourceMaker: string; + }) => Promise; + rate: ({ + amount, + poolId + }: { + amount: Uint128; + poolId: string; + }) => Promise; +} +export class Ics101QueryClient implements Ics101ReadOnlyInterface { + client: CosmWasmClient; + contractAddress: string; + + constructor(client: CosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + this.orderList = this.orderList.bind(this); + this.order = this.order.bind(this); + this.config = this.config.bind(this); + this.poolTokenList = this.poolTokenList.bind(this); + this.poolAddressByToken = this.poolAddressByToken.bind(this); + this.interchainPool = this.interchainPool.bind(this); + this.interchainPoolList = this.interchainPoolList.bind(this); + this.leftSwap = this.leftSwap.bind(this); + this.rightSwap = this.rightSwap.bind(this); + this.queryActiveOrders = this.queryActiveOrders.bind(this); + this.rate = this.rate.bind(this); + } + + orderList = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + OrderList: { + limit, + start_after: startAfter + } + }); + }; + order = async ({ + orderId, + poolId + }: { + orderId: string; + poolId: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + Order: { + order_id: orderId, + pool_id: poolId + } + }); + }; + config = async (): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + Config: {} + }); + }; + poolTokenList = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + PoolTokenList: { + limit, + start_after: startAfter + } + }); + }; + poolAddressByToken = async ({ + poolId + }: { + poolId: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + PoolAddressByToken: { + pool_id: poolId + } + }); + }; + interchainPool = async ({ + poolId + }: { + poolId: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + InterchainPool: { + pool_id: poolId + } + }); + }; + interchainPoolList = async ({ + limit, + startAfter + }: { + limit?: number; + startAfter?: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + InterchainPoolList: { + limit, + start_after: startAfter + } + }); + }; + leftSwap = async ({ + poolId, + tokenIn, + tokenOut + }: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + LeftSwap: { + pool_id: poolId, + token_in: tokenIn, + token_out: tokenOut + } + }); + }; + rightSwap = async ({ + poolId, + tokenIn, + tokenOut + }: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + RightSwap: { + pool_id: poolId, + token_in: tokenIn, + token_out: tokenOut + } + }); + }; + queryActiveOrders = async ({ + destinationTaker, + poolId, + sourceMaker + }: { + destinationTaker: string; + poolId: string; + sourceMaker: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + QueryActiveOrders: { + destination_taker: destinationTaker, + pool_id: poolId, + source_maker: sourceMaker + } + }); + }; + rate = async ({ + amount, + poolId + }: { + amount: Uint128; + poolId: string; + }): Promise => { + return this.client.queryContractSmart(this.contractAddress, { + Rate: { + amount, + pool_id: poolId + } + }); + }; +} +export interface Ics101Interface extends Ics101ReadOnlyInterface { + contractAddress: string; + sender: string; + makePool: ({ + counterpartyChannel, + counterpartyCreator, + creator, + destinationChainId, + liquidity, + sourceChainId, + sourceChannel, + sourcePort, + swapFee, + timeoutHeight, + timeoutTimestamp + }: { + counterpartyChannel: string; + counterpartyCreator: string; + creator: string; + destinationChainId: string; + liquidity: PoolAsset[]; + sourceChainId: string; + sourceChannel: string; + sourcePort: string; + swapFee: number; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + takePool: ({ + counterCreator, + creator, + poolId, + timeoutHeight, + timeoutTimestamp + }: { + counterCreator: string; + creator: string; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + cancelPool: ({ + poolId, + timeoutHeight, + timeoutTimestamp + }: { + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + singleAssetDeposit: ({ + poolId, + sender, + timeoutHeight, + timeoutTimestamp, + token + }: { + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + token: Coin; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + makeMultiAssetDeposit: ({ + chainId, + deposits, + poolId, + timeoutHeight, + timeoutTimestamp + }: { + chainId: string; + deposits: DepositAsset[]; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + cancelMultiAssetDeposit: ({ + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + }: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + takeMultiAssetDeposit: ({ + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + }: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + multiAssetWithdraw: ({ + counterpartyReceiver, + poolId, + poolToken, + receiver, + timeoutHeight, + timeoutTimestamp + }: { + counterpartyReceiver: string; + poolId: string; + poolToken: Coin; + receiver: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + swap: ({ + poolId, + recipient, + sender, + slippage, + swapType, + timeoutHeight, + timeoutTimestamp, + tokenIn, + tokenOut + }: { + poolId: string; + recipient: string; + sender: string; + slippage: number; + swapType: SwapMsgType; + timeoutHeight: number; + timeoutTimestamp: number; + tokenIn: Coin; + tokenOut: Coin; + }, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; +} +export class Ics101Client extends Ics101QueryClient implements Ics101Interface { + client: SigningCosmWasmClient; + sender: string; + contractAddress: string; + + constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) { + super(client, contractAddress); + this.client = client; + this.sender = sender; + this.contractAddress = contractAddress; + this.makePool = this.makePool.bind(this); + this.takePool = this.takePool.bind(this); + this.cancelPool = this.cancelPool.bind(this); + this.singleAssetDeposit = this.singleAssetDeposit.bind(this); + this.makeMultiAssetDeposit = this.makeMultiAssetDeposit.bind(this); + this.cancelMultiAssetDeposit = this.cancelMultiAssetDeposit.bind(this); + this.takeMultiAssetDeposit = this.takeMultiAssetDeposit.bind(this); + this.multiAssetWithdraw = this.multiAssetWithdraw.bind(this); + this.swap = this.swap.bind(this); + } + + makePool = async ({ + counterpartyChannel, + counterpartyCreator, + creator, + destinationChainId, + liquidity, + sourceChainId, + sourceChannel, + sourcePort, + swapFee, + timeoutHeight, + timeoutTimestamp + }: { + counterpartyChannel: string; + counterpartyCreator: string; + creator: string; + destinationChainId: string; + liquidity: PoolAsset[]; + sourceChainId: string; + sourceChannel: string; + sourcePort: string; + swapFee: number; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + MakePool: { + counterpartyChannel, + counterpartyCreator, + creator, + destinationChainId, + liquidity, + sourceChainId, + sourceChannel, + sourcePort, + swapFee, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + takePool = async ({ + counterCreator, + creator, + poolId, + timeoutHeight, + timeoutTimestamp + }: { + counterCreator: string; + creator: string; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + TakePool: { + counterCreator, + creator, + poolId, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + cancelPool = async ({ + poolId, + timeoutHeight, + timeoutTimestamp + }: { + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + CancelPool: { + poolId, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + singleAssetDeposit = async ({ + poolId, + sender, + timeoutHeight, + timeoutTimestamp, + token + }: { + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + token: Coin; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + SingleAssetDeposit: { + poolId, + sender, + timeoutHeight, + timeoutTimestamp, + token + } + }, fee, memo, _funds); + }; + makeMultiAssetDeposit = async ({ + chainId, + deposits, + poolId, + timeoutHeight, + timeoutTimestamp + }: { + chainId: string; + deposits: DepositAsset[]; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + MakeMultiAssetDeposit: { + chainId, + deposits, + poolId, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + cancelMultiAssetDeposit = async ({ + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + }: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + CancelMultiAssetDeposit: { + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + takeMultiAssetDeposit = async ({ + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + }: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + TakeMultiAssetDeposit: { + orderId, + poolId, + sender, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + multiAssetWithdraw = async ({ + counterpartyReceiver, + poolId, + poolToken, + receiver, + timeoutHeight, + timeoutTimestamp + }: { + counterpartyReceiver: string; + poolId: string; + poolToken: Coin; + receiver: string; + timeoutHeight: number; + timeoutTimestamp: number; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + MultiAssetWithdraw: { + counterpartyReceiver, + poolId, + poolToken, + receiver, + timeoutHeight, + timeoutTimestamp + } + }, fee, memo, _funds); + }; + swap = async ({ + poolId, + recipient, + sender, + slippage, + swapType, + timeoutHeight, + timeoutTimestamp, + tokenIn, + tokenOut + }: { + poolId: string; + recipient: string; + sender: string; + slippage: number; + swapType: SwapMsgType; + timeoutHeight: number; + timeoutTimestamp: number; + tokenIn: Coin; + tokenOut: Coin; + }, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + return await this.client.execute(this.sender, this.contractAddress, { + Swap: { + poolId, + recipient, + sender, + slippage, + swapType, + timeoutHeight, + timeoutTimestamp, + tokenIn, + tokenOut + } + }, fee, memo, _funds); + }; +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics101.provider.ts b/codegen/cosmoswasm-codegen/Ics101.provider.ts new file mode 100644 index 0000000..dd1c5e8 --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics101.provider.ts @@ -0,0 +1,18 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 { ContractBase, IContractConstructor, IEmptyClient } from "./contractContextBase"; +import { Ics101Client, Ics101QueryClient } from "./Ics101.client"; +export class Ics101 extends ContractBase { + constructor({ + address, + cosmWasmClient, + signingCosmWasmClient + }: IContractConstructor) { + super(address, cosmWasmClient, signingCosmWasmClient, Ics101Client, Ics101QueryClient, undefined); + } + +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics101.react-query.ts b/codegen/cosmoswasm-codegen/Ics101.react-query.ts new file mode 100644 index 0000000..4e26915 --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics101.react-query.ts @@ -0,0 +1,645 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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, useMutation, UseMutationOptions } from "@tanstack/react-query"; +import { ExecuteResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { ExecuteMsg, Uint128, PoolSide, SwapMsgType, MsgMakePoolRequest, PoolAsset, Coin, MsgTakePoolRequest, MsgCancelPoolRequest, MsgSingleAssetDepositRequest, MsgMakeMultiAssetDepositRequest, DepositAsset, MsgCancelMultiAssetDepositRequest, MsgTakeMultiAssetDepositRequest, MsgMultiAssetWithdrawRequest, MsgSwapRequest, InstantiateMsg, QueryMsg } from "./Ics101.types"; +import { Ics101QueryClient, Ics101Client } from "./Ics101.client"; +export const ics101QueryKeys = { + contract: ([{ + contract: "ics101" + }] as const), + address: (contractAddress: string | undefined) => ([{ ...ics101QueryKeys.contract[0], + address: contractAddress + }] as const), + orderList: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "OrderList", + args + }] as const), + order: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "Order", + args + }] as const), + config: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "Config", + args + }] as const), + poolTokenList: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "PoolTokenList", + args + }] as const), + poolAddressByToken: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "PoolAddressByToken", + args + }] as const), + interchainPool: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "InterchainPool", + args + }] as const), + interchainPoolList: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "InterchainPoolList", + args + }] as const), + leftSwap: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "LeftSwap", + args + }] as const), + rightSwap: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "RightSwap", + args + }] as const), + queryActiveOrders: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "QueryActiveOrders", + args + }] as const), + rate: (contractAddress: string | undefined, args?: Record) => ([{ ...ics101QueryKeys.address(contractAddress)[0], + method: "Rate", + args + }] as const) +}; +export const ics101Queries = { + orderList: ({ + client, + args, + options + }: Ics101OrderListQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.orderList(client?.contractAddress, args), + queryFn: () => client ? client.orderList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + order: ({ + client, + args, + options + }: Ics101OrderQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.order(client?.contractAddress, args), + queryFn: () => client ? client.order({ + orderId: args.orderId, + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + config: ({ + client, + options + }: Ics101ConfigQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.config(client?.contractAddress), + queryFn: () => client ? client.config() : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + poolTokenList: ({ + client, + args, + options + }: Ics101PoolTokenListQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.poolTokenList(client?.contractAddress, args), + queryFn: () => client ? client.poolTokenList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + poolAddressByToken: ({ + client, + args, + options + }: Ics101PoolAddressByTokenQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.poolAddressByToken(client?.contractAddress, args), + queryFn: () => client ? client.poolAddressByToken({ + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + interchainPool: ({ + client, + args, + options + }: Ics101InterchainPoolQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.interchainPool(client?.contractAddress, args), + queryFn: () => client ? client.interchainPool({ + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + interchainPoolList: ({ + client, + args, + options + }: Ics101InterchainPoolListQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.interchainPoolList(client?.contractAddress, args), + queryFn: () => client ? client.interchainPoolList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + leftSwap: ({ + client, + args, + options + }: Ics101LeftSwapQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.leftSwap(client?.contractAddress, args), + queryFn: () => client ? client.leftSwap({ + poolId: args.poolId, + tokenIn: args.tokenIn, + tokenOut: args.tokenOut + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + rightSwap: ({ + client, + args, + options + }: Ics101RightSwapQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.rightSwap(client?.contractAddress, args), + queryFn: () => client ? client.rightSwap({ + poolId: args.poolId, + tokenIn: args.tokenIn, + tokenOut: args.tokenOut + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + queryActiveOrders: ({ + client, + args, + options + }: Ics101QueryActiveOrdersQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.queryActiveOrders(client?.contractAddress, args), + queryFn: () => client ? client.queryActiveOrders({ + destinationTaker: args.destinationTaker, + poolId: args.poolId, + sourceMaker: args.sourceMaker + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }), + rate: ({ + client, + args, + options + }: Ics101RateQuery): UseQueryOptions => ({ + queryKey: ics101QueryKeys.rate(client?.contractAddress, args), + queryFn: () => client ? client.rate({ + amount: args.amount, + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), + ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }) +}; +export interface Ics101ReactQuery { + client: Ics101QueryClient | undefined; + options?: Omit, "'queryKey' | 'queryFn' | 'initialData'"> & { + initialData?: undefined; + }; +} +export interface Ics101RateQuery extends Ics101ReactQuery { + args: { + amount: Uint128; + poolId: string; + }; +} +export function useIcs101RateQuery({ + client, + args, + options +}: Ics101RateQuery) { + return useQuery(ics101QueryKeys.rate(client?.contractAddress, args), () => client ? client.rate({ + amount: args.amount, + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101QueryActiveOrdersQuery extends Ics101ReactQuery { + args: { + destinationTaker: string; + poolId: string; + sourceMaker: string; + }; +} +export function useIcs101QueryActiveOrdersQuery({ + client, + args, + options +}: Ics101QueryActiveOrdersQuery) { + return useQuery(ics101QueryKeys.queryActiveOrders(client?.contractAddress, args), () => client ? client.queryActiveOrders({ + destinationTaker: args.destinationTaker, + poolId: args.poolId, + sourceMaker: args.sourceMaker + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101RightSwapQuery extends Ics101ReactQuery { + args: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }; +} +export function useIcs101RightSwapQuery({ + client, + args, + options +}: Ics101RightSwapQuery) { + return useQuery(ics101QueryKeys.rightSwap(client?.contractAddress, args), () => client ? client.rightSwap({ + poolId: args.poolId, + tokenIn: args.tokenIn, + tokenOut: args.tokenOut + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101LeftSwapQuery extends Ics101ReactQuery { + args: { + poolId: string; + tokenIn: Coin; + tokenOut: Coin; + }; +} +export function useIcs101LeftSwapQuery({ + client, + args, + options +}: Ics101LeftSwapQuery) { + return useQuery(ics101QueryKeys.leftSwap(client?.contractAddress, args), () => client ? client.leftSwap({ + poolId: args.poolId, + tokenIn: args.tokenIn, + tokenOut: args.tokenOut + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101InterchainPoolListQuery extends Ics101ReactQuery { + args: { + limit?: number; + startAfter?: string; + }; +} +export function useIcs101InterchainPoolListQuery({ + client, + args, + options +}: Ics101InterchainPoolListQuery) { + return useQuery(ics101QueryKeys.interchainPoolList(client?.contractAddress, args), () => client ? client.interchainPoolList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101InterchainPoolQuery extends Ics101ReactQuery { + args: { + poolId: string; + }; +} +export function useIcs101InterchainPoolQuery({ + client, + args, + options +}: Ics101InterchainPoolQuery) { + return useQuery(ics101QueryKeys.interchainPool(client?.contractAddress, args), () => client ? client.interchainPool({ + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101PoolAddressByTokenQuery extends Ics101ReactQuery { + args: { + poolId: string; + }; +} +export function useIcs101PoolAddressByTokenQuery({ + client, + args, + options +}: Ics101PoolAddressByTokenQuery) { + return useQuery(ics101QueryKeys.poolAddressByToken(client?.contractAddress, args), () => client ? client.poolAddressByToken({ + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101PoolTokenListQuery extends Ics101ReactQuery { + args: { + limit?: number; + startAfter?: string; + }; +} +export function useIcs101PoolTokenListQuery({ + client, + args, + options +}: Ics101PoolTokenListQuery) { + return useQuery(ics101QueryKeys.poolTokenList(client?.contractAddress, args), () => client ? client.poolTokenList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101ConfigQuery extends Ics101ReactQuery {} +export function useIcs101ConfigQuery({ + client, + options +}: Ics101ConfigQuery) { + return useQuery(ics101QueryKeys.config(client?.contractAddress), () => client ? client.config() : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101OrderQuery extends Ics101ReactQuery { + args: { + orderId: string; + poolId: string; + }; +} +export function useIcs101OrderQuery({ + client, + args, + options +}: Ics101OrderQuery) { + return useQuery(ics101QueryKeys.order(client?.contractAddress, args), () => client ? client.order({ + orderId: args.orderId, + poolId: args.poolId + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101OrderListQuery extends Ics101ReactQuery { + args: { + limit?: number; + startAfter?: string; + }; +} +export function useIcs101OrderListQuery({ + client, + args, + options +}: Ics101OrderListQuery) { + return useQuery(ics101QueryKeys.orderList(client?.contractAddress, args), () => client ? client.orderList({ + limit: args.limit, + startAfter: args.startAfter + }) : Promise.reject(new Error("Invalid client")), { ...options, + enabled: !!client && (options?.enabled != undefined ? options.enabled : true) + }); +} +export interface Ics101SwapMutation { + client: Ics101Client; + msg: { + poolId: string; + recipient: string; + sender: string; + slippage: number; + swapType: SwapMsgType; + timeoutHeight: number; + timeoutTimestamp: number; + tokenIn: Coin; + tokenOut: Coin; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101SwapMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.swap(msg, fee, memo, funds), options); +} +export interface Ics101MultiAssetWithdrawMutation { + client: Ics101Client; + msg: { + counterpartyReceiver: string; + poolId: string; + poolToken: Coin; + receiver: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101MultiAssetWithdrawMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.multiAssetWithdraw(msg, fee, memo, funds), options); +} +export interface Ics101TakeMultiAssetDepositMutation { + client: Ics101Client; + msg: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101TakeMultiAssetDepositMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.takeMultiAssetDeposit(msg, fee, memo, funds), options); +} +export interface Ics101CancelMultiAssetDepositMutation { + client: Ics101Client; + msg: { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101CancelMultiAssetDepositMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.cancelMultiAssetDeposit(msg, fee, memo, funds), options); +} +export interface Ics101MakeMultiAssetDepositMutation { + client: Ics101Client; + msg: { + chainId: string; + deposits: DepositAsset[]; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101MakeMultiAssetDepositMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.makeMultiAssetDeposit(msg, fee, memo, funds), options); +} +export interface Ics101SingleAssetDepositMutation { + client: Ics101Client; + msg: { + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + token: Coin; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101SingleAssetDepositMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.singleAssetDeposit(msg, fee, memo, funds), options); +} +export interface Ics101CancelPoolMutation { + client: Ics101Client; + msg: { + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101CancelPoolMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.cancelPool(msg, fee, memo, funds), options); +} +export interface Ics101TakePoolMutation { + client: Ics101Client; + msg: { + counterCreator: string; + creator: string; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101TakePoolMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.takePool(msg, fee, memo, funds), options); +} +export interface Ics101MakePoolMutation { + client: Ics101Client; + msg: { + counterpartyChannel: string; + counterpartyCreator: string; + creator: string; + destinationChainId: string; + liquidity: PoolAsset[]; + sourceChainId: string; + sourceChannel: string; + sourcePort: string; + swapFee: number; + timeoutHeight: number; + timeoutTimestamp: number; + }; + args?: { + fee?: number | StdFee | "auto"; + memo?: string; + funds?: Coin[]; + }; +} +export function useIcs101MakePoolMutation(options?: Omit, "mutationFn">) { + return useMutation(({ + client, + msg, + args: { + fee, + memo, + funds + } = {} + }) => client.makePool(msg, fee, memo, funds), options); +} \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/Ics101.types.ts b/codegen/cosmoswasm-codegen/Ics101.types.ts new file mode 100644 index 0000000..bfcb8c0 --- /dev/null +++ b/codegen/cosmoswasm-codegen/Ics101.types.ts @@ -0,0 +1,196 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 = { + MakePool: MsgMakePoolRequest; +} | { + TakePool: MsgTakePoolRequest; +} | { + CancelPool: MsgCancelPoolRequest; +} | { + SingleAssetDeposit: MsgSingleAssetDepositRequest; +} | { + MakeMultiAssetDeposit: MsgMakeMultiAssetDepositRequest; +} | { + CancelMultiAssetDeposit: MsgCancelMultiAssetDepositRequest; +} | { + TakeMultiAssetDeposit: MsgTakeMultiAssetDepositRequest; +} | { + MultiAssetWithdraw: MsgMultiAssetWithdrawRequest; +} | { + Swap: MsgSwapRequest; +}; +export type Uint128 = string; +export type PoolSide = "SOURCE" | "DESTINATION"; +export type SwapMsgType = "LEFT" | "RIGHT"; +export interface MsgMakePoolRequest { + counterpartyChannel: string; + counterpartyCreator: string; + creator: string; + destinationChainId: string; + liquidity: PoolAsset[]; + sourceChainId: string; + sourceChannel: string; + sourcePort: string; + swapFee: number; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface PoolAsset { + balance: Coin; + decimal: number; + side: PoolSide; + weight: number; + [k: string]: unknown; +} +export interface Coin { + amount: Uint128; + denom: string; + [k: string]: unknown; +} +export interface MsgTakePoolRequest { + counterCreator: string; + creator: string; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface MsgCancelPoolRequest { + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface MsgSingleAssetDepositRequest { + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + token: Coin; + [k: string]: unknown; +} +export interface MsgMakeMultiAssetDepositRequest { + chainId: string; + deposits: DepositAsset[]; + poolId: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface DepositAsset { + balance: Coin; + sender: string; + [k: string]: unknown; +} +export interface MsgCancelMultiAssetDepositRequest { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface MsgTakeMultiAssetDepositRequest { + orderId: string; + poolId: string; + sender: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface MsgMultiAssetWithdrawRequest { + counterpartyReceiver: string; + poolId: string; + poolToken: Coin; + receiver: string; + timeoutHeight: number; + timeoutTimestamp: number; + [k: string]: unknown; +} +export interface MsgSwapRequest { + poolId: string; + recipient: string; + sender: string; + slippage: number; + swapType: SwapMsgType; + timeoutHeight: number; + timeoutTimestamp: number; + tokenIn: Coin; + tokenOut: Coin; + [k: string]: unknown; +} +export interface InstantiateMsg { + token_code_id: number; + [k: string]: unknown; +} +export type QueryMsg = { + OrderList: { + limit?: number | null; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + Order: { + order_id: string; + pool_id: string; + [k: string]: unknown; + }; +} | { + Config: { + [k: string]: unknown; + }; +} | { + PoolTokenList: { + limit?: number | null; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + PoolAddressByToken: { + pool_id: string; + [k: string]: unknown; + }; +} | { + InterchainPool: { + pool_id: string; + [k: string]: unknown; + }; +} | { + InterchainPoolList: { + limit?: number | null; + start_after?: string | null; + [k: string]: unknown; + }; +} | { + LeftSwap: { + pool_id: string; + token_in: Coin; + token_out: Coin; + [k: string]: unknown; + }; +} | { + RightSwap: { + pool_id: string; + token_in: Coin; + token_out: Coin; + [k: string]: unknown; + }; +} | { + QueryActiveOrders: { + destination_taker: string; + pool_id: string; + source_maker: string; + [k: string]: unknown; + }; +} | { + Rate: { + amount: Uint128; + pool_id: string; + [k: string]: unknown; + }; +}; \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/contractContextBase.ts b/codegen/cosmoswasm-codegen/contractContextBase.ts new file mode 100644 index 0000000..f91e877 --- /dev/null +++ b/codegen/cosmoswasm-codegen/contractContextBase.ts @@ -0,0 +1,97 @@ +/** +* This file and any referenced files were automatically generated by @cosmwasm/ts-codegen@0.35.3 +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +import { + CosmWasmClient, + SigningCosmWasmClient, +} from '@cosmjs/cosmwasm-stargate'; + +export interface IContractConstructor { + address: string | undefined; + cosmWasmClient: CosmWasmClient | undefined; + signingCosmWasmClient: SigningCosmWasmClient | undefined; +} + +export const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected'; + +export const NO_COSMWASW_CLIENT_ERROR_MESSAGE = 'cosmWasmClient not connected'; + +export const NO_ADDRESS_ERROR_MESSAGE = "address doesn't exist"; + +export const NO_SIGNING_CLIENT_ERROR_MESSAGE = + 'Signing client is not generated. Please check ts-codegen config'; + +export const NO_QUERY_CLIENT_ERROR_MESSAGE = + 'Query client is not generated. Please check ts-codegen config'; + +export const NO_MESSAGE_COMPOSER_ERROR_MESSAGE = + 'Message composer client is not generated. Please check ts-codegen config'; + +/** + * a placeholder for non-generated classes + */ +export interface IEmptyClient {} + +export interface ISigningClientProvider { + getSigningClient(contractAddr: string): T; +} + +export interface IQueryClientProvider { + getQueryClient(contractAddr: string): T; +} + +export interface IMessageComposerProvider { + getMessageComposer(contractAddr: string): T; +} + +export class ContractBase< + TSign = IEmptyClient, + TQuery = IEmptyClient, + TMsgComposer = IEmptyClient +> { + constructor( + protected address: string | undefined, + protected cosmWasmClient: CosmWasmClient | undefined, + protected signingCosmWasmClient: SigningCosmWasmClient | undefined, + private TSign?: new ( + client: SigningCosmWasmClient, + sender: string, + contractAddress: string + ) => TSign, + private TQuery?: new ( + client: CosmWasmClient, + contractAddress: string + ) => TQuery, + private TMsgComposer?: new ( + sender: string, + contractAddress: string + ) => TMsgComposer + ) {} + + public getSigningClient(contractAddr: string): TSign { + if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE); + if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE); + if (!this.TSign) throw new Error(NO_SIGNING_CLIENT_ERROR_MESSAGE); + return new this.TSign( + this.signingCosmWasmClient, + this.address, + contractAddr + ); + } + + public getQueryClient(contractAddr: string): TQuery { + if (!this.cosmWasmClient) throw new Error(NO_COSMWASW_CLIENT_ERROR_MESSAGE); + if (!this.TQuery) throw new Error(NO_QUERY_CLIENT_ERROR_MESSAGE); + return new this.TQuery(this.cosmWasmClient, contractAddr); + } + + public getMessageComposer(contractAddr: string): TMsgComposer { + if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE); + if (!this.TMsgComposer) throw new Error(NO_MESSAGE_COMPOSER_ERROR_MESSAGE); + return new this.TMsgComposer(this.address, contractAddr); + } +} diff --git a/codegen/cosmoswasm-codegen/contractContextProviders.ts b/codegen/cosmoswasm-codegen/contractContextProviders.ts new file mode 100644 index 0000000..6e9b344 --- /dev/null +++ b/codegen/cosmoswasm-codegen/contractContextProviders.ts @@ -0,0 +1,30 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 } from "@cosmjs/cosmwasm-stargate"; +import { IQueryClientProvider, ISigningClientProvider, IMessageComposerProvider } from "./contractContextBase"; +import { Ics100QueryClient } from "./Ics100.client"; +import { Ics100Client } from "./Ics100.client"; +import { Ics100 } from "./Ics100.provider"; +import { Ics101QueryClient } from "./Ics101.client"; +import { Ics101Client } from "./Ics101.client"; +import { Ics101 } from "./Ics101.provider"; +export interface IContractsContext { + ics100: IQueryClientProvider & ISigningClientProvider; + ics101: IQueryClientProvider & ISigningClientProvider; +} +export const getProviders = (address?: string, cosmWasmClient?: CosmWasmClient, signingCosmWasmClient?: SigningCosmWasmClient) => ({ + ics100: new Ics100({ + address, + cosmWasmClient, + signingCosmWasmClient + }), + ics101: new Ics101({ + address, + cosmWasmClient, + signingCosmWasmClient + }) +}); \ No newline at end of file diff --git a/codegen/cosmoswasm-codegen/contracts-context.tsx b/codegen/cosmoswasm-codegen/contracts-context.tsx new file mode 100644 index 0000000..6cd0153 --- /dev/null +++ b/codegen/cosmoswasm-codegen/contracts-context.tsx @@ -0,0 +1,78 @@ +/** +* This file and any referenced files were automatically generated by @cosmwasm/ts-codegen@0.35.3 +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +import React, { useEffect, useMemo, useRef, useState, useContext } from 'react'; +import { + CosmWasmClient, + SigningCosmWasmClient, +} from '@cosmjs/cosmwasm-stargate'; + +import { IContractsContext, getProviders } from './contractContextProviders'; + +export interface ContractsConfig { + address: string | undefined; + getCosmWasmClient: () => Promise; + getSigningCosmWasmClient: () => Promise; +} + +const ContractsContext = React.createContext(null); + +export const ContractsProvider = ({ + children, + contractsConfig, +}: { + children: React.ReactNode; + contractsConfig: ContractsConfig; +}) => { + const [cosmWasmClient, setCosmWasmClient] = useState(); + const [signingCosmWasmClient, setSigningCosmWasmClient] = + useState(); + + const { address, getCosmWasmClient, getSigningCosmWasmClient } = + contractsConfig; + + const prevAddressRef = useRef(address); + + const contracts: IContractsContext = useMemo(() => { + return getProviders(address, cosmWasmClient, signingCosmWasmClient); + }, [address, cosmWasmClient, signingCosmWasmClient]); + + useEffect(() => { + const connectSigningCwClient = async () => { + if (address && prevAddressRef.current !== address) { + const signingCosmWasmClient = await getSigningCosmWasmClient(); + setSigningCosmWasmClient(signingCosmWasmClient); + } else if (!address) { + setSigningCosmWasmClient(undefined); + } + prevAddressRef.current = address; + }; + connectSigningCwClient(); + }, [address, getSigningCosmWasmClient]); + + useEffect(() => { + const connectCosmWasmClient = async () => { + const cosmWasmClient = await getCosmWasmClient(); + setCosmWasmClient(cosmWasmClient); + }; + connectCosmWasmClient(); + }, [getCosmWasmClient]); + + return ( + + {children} + + ); +}; + +export const useContracts = () => { + const contracts: IContractsContext = useContext(ContractsContext); + if (contracts === null) { + throw new Error('useContracts must be used within a ContractsProvider'); + } + return contracts; +}; diff --git a/codegen/cosmoswasm-codegen/index.ts b/codegen/cosmoswasm-codegen/index.ts new file mode 100644 index 0000000..6fde4d5 --- /dev/null +++ b/codegen/cosmoswasm-codegen/index.ts @@ -0,0 +1,35 @@ +/** +* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3. +* 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 _0 from "./Ics100.types"; +import * as _1 from "./Ics100.client"; +import * as _2 from "./Ics100.react-query"; +import * as _3 from "./Ics100.provider"; +import * as _4 from "./Ics101.types"; +import * as _5 from "./Ics101.client"; +import * as _6 from "./Ics101.react-query"; +import * as _7 from "./Ics101.provider"; +import * as _8 from "./contractContextProviders"; +import * as _9 from "./contractContextBase"; +import * as _10 from "./contracts-context"; +export namespace SideContracts { + export const Ics100 = { ..._0, + ..._1, + ..._2, + ..._3 + }; + export const Ics101 = { ..._4, + ..._5, + ..._6, + ..._7 + }; + export const contractContextProviders = { ..._8 + }; + export const contractContextBase = { ..._9 + }; + export const contractsContext = { ..._10 + }; +} \ No newline at end of file diff --git a/codegen/index.ts b/codegen/index.ts new file mode 100644 index 0000000..e6ed1d4 --- /dev/null +++ b/codegen/index.ts @@ -0,0 +1,51 @@ +import codegen from '@cosmwasm/ts-codegen'; + +codegen({ + contracts: [ + { + name: 'ics100', + dir: '../contracts/ics100/schema' + }, + { + name: 'ics101', + dir: '../contracts/ics101/schema' + } + ], + outPath: './cosmoswasm-codegen', + + // options are completely optional ;) + options: { + bundle: { + bundleFile: 'index.ts', + scope: 'SideContracts' + }, + types: { + enabled: true + }, + client: { + enabled: true + }, + reactQuery: { + enabled: true, + optionalClient: true, + version: 'v4', + mutations: true, + queryKeys: true, + queryFactory: true, + }, + recoil: { + enabled: false + }, + messageComposer: { + enabled: false + }, + messageBuilder: { + enabled: false + }, + useContractsHooks: { + enabled: true + } + } +}).then(() => { + console.log('✨ all done!'); +}); \ No newline at end of file diff --git a/codegen/package.json b/codegen/package.json new file mode 100644 index 0000000..d1c8ec5 --- /dev/null +++ b/codegen/package.json @@ -0,0 +1,13 @@ +{ + "name": "ibcswap-wasm-codegen", + "private": true, + "version": "0.0.0", + "dependencies": { + "@cosmwasm/ts-codegen": "^0.35.3", + "ts-node": "^10.9.1", + "typescript": "^5.1.6" + }, + "scripts": { + "ts-codegen": "yarn ts-node index.ts" + } +} diff --git a/codegen/tsconfig.json b/codegen/tsconfig.json new file mode 100644 index 0000000..dc81d87 --- /dev/null +++ b/codegen/tsconfig.json @@ -0,0 +1,109 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +}