Skip to content

Commit

Permalink
feat: ts clients
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Dec 13, 2023
1 parent 43e91ed commit 0a98916
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 18 deletions.
38 changes: 22 additions & 16 deletions integration_tests/src/generated/contractLib/index.ts
Original file line number Diff line number Diff line change
@@ -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;
101 changes: 101 additions & 0 deletions integration_tests/src/generated/contractLib/lidoCore.ts
Original file line number Diff line number Diff line change
@@ -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<InstantiateResult> {
const res = await client.instantiate(sender, codeId, initMsg, label, fees, {
...(initCoins && initCoins.length && { funds: initCoins }),
});
return res;
}
queryConfig = async(): Promise<Config> => {
return this.client.queryContractSmart(this.contractAddress, { config: {} });
}
queryExchangeRate = async(): Promise<Decimal256> => {
return this.client.queryContractSmart(this.contractAddress, { exchange_rate: {} });
}
bond = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
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<ExecuteResult> => {
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<ExecuteResult> => {
if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); }
return this.client.execute(sender, this.contractAddress, { update_config: args }, fee || "auto", memo, funds);
}
}
57 changes: 57 additions & 0 deletions integration_tests/src/generated/contractLib/lidoFactory.ts
Original file line number Diff line number Diff line change
@@ -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<InstantiateResult> {
const res = await client.instantiate(sender, codeId, initMsg, label, fees, {
...(initCoins && initCoins.length && { funds: initCoins }),
});
return res;
}
queryState = async(): Promise<State> => {
return this.client.queryContractSmart(this.contractAddress, { state: {} });
}
init = async(sender: string, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
if (!isSigningCosmWasmClient(this.client)) { throw this.mustBeSigningClient(); }
return this.client.execute(sender, this.contractAddress, { init: {} }, fee || "auto", memo, funds);
}
}
4 changes: 2 additions & 2 deletions integration_tests/src/generated/contractLib/lidoToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/**
Expand All @@ -26,7 +26,7 @@ export interface LidoTokenSchema {
[k: string]: unknown;
}
export interface ConfigResponse {
core: string;
core_address: string;
denom: string;
}
export interface MintArgs {
Expand Down

0 comments on commit 0a98916

Please sign in to comment.