From 0a989165f54d15e7270017b7447a4e321367fb0c Mon Sep 17 00:00:00 2001 From: Sergey Ratiashvili Date: Wed, 13 Dec 2023 21:29:51 +0100 Subject: [PATCH] feat: ts clients --- .../src/generated/contractLib/index.ts | 38 ++++--- .../src/generated/contractLib/lidoCore.ts | 101 ++++++++++++++++++ .../src/generated/contractLib/lidoFactory.ts | 57 ++++++++++ .../src/generated/contractLib/lidoToken.ts | 4 +- 4 files changed, 182 insertions(+), 18 deletions(-) create mode 100644 integration_tests/src/generated/contractLib/lidoCore.ts create mode 100644 integration_tests/src/generated/contractLib/lidoFactory.ts diff --git a/integration_tests/src/generated/contractLib/index.ts b/integration_tests/src/generated/contractLib/index.ts index 8072cc2d..2e9dd14d 100644 --- a/integration_tests/src/generated/contractLib/index.ts +++ b/integration_tests/src/generated/contractLib/index.ts @@ -1,23 +1,29 @@ -import * as _0 from './lidoDistribution'; -export const LidoDistribution = _0; +import * as _0 from './lidoCore'; +export const LidoCore = _0; -import * as _1 from './lidoInterchainInterceptorAuthz'; -export const LidoInterchainInterceptorAuthz = _1; +import * as _1 from './lidoDistribution'; +export const LidoDistribution = _1; -import * as _2 from './lidoInterchainInterceptor'; -export const LidoInterchainInterceptor = _2; +import * as _2 from './lidoFactory'; +export const LidoFactory = _2; -import * as _3 from './lidoStargatePoc'; -export const LidoStargatePoc = _3; +import * as _3 from './lidoInterchainInterceptorAuthz'; +export const LidoInterchainInterceptorAuthz = _3; -import * as _4 from './lidoStrategy'; -export const LidoStrategy = _4; +import * as _4 from './lidoInterchainInterceptor'; +export const LidoInterchainInterceptor = _4; -import * as _5 from './lidoToken'; -export const LidoToken = _5; +import * as _5 from './lidoStargatePoc'; +export const LidoStargatePoc = _5; -import * as _6 from './lidoValidatorsSet'; -export const LidoValidatorsSet = _6; +import * as _6 from './lidoStrategy'; +export const LidoStrategy = _6; -import * as _7 from './lidoValidatorsStats'; -export const LidoValidatorsStats = _7; +import * as _7 from './lidoToken'; +export const LidoToken = _7; + +import * as _8 from './lidoValidatorsSet'; +export const LidoValidatorsSet = _8; + +import * as _9 from './lidoValidatorsStats'; +export const LidoValidatorsStats = _9; diff --git a/integration_tests/src/generated/contractLib/lidoCore.ts b/integration_tests/src/generated/contractLib/lidoCore.ts new file mode 100644 index 00000000..1fa073fa --- /dev/null +++ b/integration_tests/src/generated/contractLib/lidoCore.ts @@ -0,0 +1,101 @@ +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult, InstantiateResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Coin } from "@cosmjs/amino"; +export interface InstantiateMsg { + owner: string; + puppeteer_contract: string; + strategy_contract: string; + token_contract: string; +} +/** + * A fixed-point decimal value with 18 fractional digits, i.e. Decimal256(1_000_000_000_000_000_000) == 1.0 + * + * The greatest possible value that can be represented is 115792089237316195423570985008687907853269984665640564039457.584007913129639935 (which is (2^256 - 1) / 10^18) + */ +export type Decimal256 = string; +/** + * A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq. + * + * # Examples + * + * Use `from` to create instances of this and `u128` to get the value out: + * + * ``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123); + * + * let b = Uint128::from(42u64); assert_eq!(b.u128(), 42); + * + * let c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ``` + */ +export type Uint128 = string; + +export interface LidoCoreSchema { + responses: Config | Decimal256; + execute: UnbondArgs | UpdateConfigArgs; + [k: string]: unknown; +} +export interface Config { + owner: string; + puppeteer_contract: string; + strategy_contract: string; + token_contract: string; +} +export interface UnbondArgs { + amount: Uint128; +} +export interface UpdateConfigArgs { + owner?: string | null; + puppeteer_contract?: string | null; + strategy_contract?: string | null; + token_contract?: string | null; +} + + +function isSigningCosmWasmClient( + client: CosmWasmClient | SigningCosmWasmClient +): client is SigningCosmWasmClient { + return 'execute' in client; +} + +export class Client { + private readonly client: CosmWasmClient | SigningCosmWasmClient; + contractAddress: string; + constructor(client: CosmWasmClient | SigningCosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + } + mustBeSigningClient() { + return new Error("This client is not a SigningCosmWasmClient"); + } + static async instantiate( + client: SigningCosmWasmClient, + sender: string, + codeId: number, + initMsg: InstantiateMsg, + label: string, + initCoins?: readonly Coin[], + fees?: StdFee | 'auto' | number, + ): Promise { + const res = await client.instantiate(sender, codeId, initMsg, label, fees, { + ...(initCoins && initCoins.length && { funds: initCoins }), + }); + return res; + } + queryConfig = async(): Promise => { + return this.client.queryContractSmart(this.contractAddress, { config: {} }); + } + queryExchangeRate = async(): Promise => { + return this.client.queryContractSmart(this.contractAddress, { exchange_rate: {} }); + } + bond = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { bond: {} }, fee || "auto", memo, funds); + } + unbond = async(sender:string, args: UnbondArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { unbond: args }, fee || "auto", memo, funds); + } + updateConfig = async(sender:string, args: UpdateConfigArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { update_config: args }, fee || "auto", memo, funds); + } +} diff --git a/integration_tests/src/generated/contractLib/lidoFactory.ts b/integration_tests/src/generated/contractLib/lidoFactory.ts new file mode 100644 index 00000000..a3820053 --- /dev/null +++ b/integration_tests/src/generated/contractLib/lidoFactory.ts @@ -0,0 +1,57 @@ +import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult, InstantiateResult } from "@cosmjs/cosmwasm-stargate"; +import { StdFee } from "@cosmjs/amino"; +import { Coin } from "@cosmjs/amino"; +export interface InstantiateMsg { + core_code_id: number; + salt: string; + subdenom: string; + token_code_id: number; +} +export interface LidoFactorySchema { + responses: State; + [k: string]: unknown; +} +export interface State { + core_contract: string; + token_contract: string; +} + + +function isSigningCosmWasmClient( + client: CosmWasmClient | SigningCosmWasmClient +): client is SigningCosmWasmClient { + return 'execute' in client; +} + +export class Client { + private readonly client: CosmWasmClient | SigningCosmWasmClient; + contractAddress: string; + constructor(client: CosmWasmClient | SigningCosmWasmClient, contractAddress: string) { + this.client = client; + this.contractAddress = contractAddress; + } + mustBeSigningClient() { + return new Error("This client is not a SigningCosmWasmClient"); + } + static async instantiate( + client: SigningCosmWasmClient, + sender: string, + codeId: number, + initMsg: InstantiateMsg, + label: string, + initCoins?: readonly Coin[], + fees?: StdFee | 'auto' | number, + ): Promise { + const res = await client.instantiate(sender, codeId, initMsg, label, fees, { + ...(initCoins && initCoins.length && { funds: initCoins }), + }); + return res; + } + queryState = async(): Promise => { + return this.client.queryContractSmart(this.contractAddress, { state: {} }); + } + init = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise => { + if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); } + return this.client.execute(sender, this.contractAddress, { init: {} }, fee || "auto", memo, funds); + } +} diff --git a/integration_tests/src/generated/contractLib/lidoToken.ts b/integration_tests/src/generated/contractLib/lidoToken.ts index 0f79eea3..fe58f8a3 100644 --- a/integration_tests/src/generated/contractLib/lidoToken.ts +++ b/integration_tests/src/generated/contractLib/lidoToken.ts @@ -2,7 +2,7 @@ import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult, InstantiateResult import { StdFee } from "@cosmjs/amino"; import { Coin } from "@cosmjs/amino"; export interface InstantiateMsg { - core: string; + core_address: string; subdenom: string; } /** @@ -26,7 +26,7 @@ export interface LidoTokenSchema { [k: string]: unknown; } export interface ConfigResponse { - core: string; + core_address: string; denom: string; } export interface MintArgs {