Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract App Module Plugin #112

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
28335f3
Initial abstract-app class
adairrr Apr 14, 2023
1b9cf55
Abstract App query interface
adairrr Apr 15, 2023
e380fee
Add query factory to abstract app
adairrr Apr 16, 2023
8f87074
Abstract app types
adairrr Apr 16, 2023
e7eaf04
Abstract app query clients
adairrr May 21, 2023
c926307
AppExecuteInterface
adairrr May 21, 2023
fe66c65
Missing extends in IAppClient
adairrr May 21, 2023
cbb72b9
Abstract app execute client
adairrr May 21, 2023
17557cb
App execute client
adairrr May 21, 2023
6ebed01
Lint the message composer
adairrr May 21, 2023
97d5ab0
Update message builder with abstract
adairrr May 21, 2023
67195cb
Merge 'main'
adairrr May 21, 2023
3777a4b
Clean up abstract app client
adairrr May 21, 2023
3172021
Merge branch 'underscoreFunds' into feature/abstractApp
adairrr May 21, 2023
a3a62aa
Merge branch 'underscoreFunds' into feature/abstractApp
adairrr May 21, 2023
c04b24c
Update react query generation with abstract app
adairrr May 21, 2023
22a40f1
Rely on msg builder for abstract-app
adairrr May 21, 2023
9880c32
Abstract app readme
adairrr May 21, 2023
814b353
Extract from execute msg in appclient
adairrr May 21, 2023
9d3e56b
Update ts-codegen tests
adairrr May 21, 2023
2898bf5
Union _moduleAddress with undefined
adairrr May 21, 2023
2d1640b
Add clientPrefix option to abstractApp
adairrr May 30, 2023
3dd3d78
Merge branch 'main' into feature/abstractApp
NoahSaso Jul 10, 2023
338bbed
Changed wasm-ast-types package name back to npm.
NoahSaso Jul 10, 2023
ea8122e
number to AbstractAccountId and update tests
adairrr Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rely on msg builder for abstract-app
adairrr committed May 21, 2023
commit 22a40f1198ed955540be98b0510b070f5a4db203
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
import { CamelCasedProperties } from "type-fest";
import { SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { AbstractQueryClient, AbstractAccountQueryClient, AbstractAccountClient, AppExecuteMsg, AppModuleExecuteMsgBuilder, AbstractClient } from "@abstract-money/abstract.js";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { toUtf8 } from "@cosmjs/encoding";
import { StdFee, Coin } from "@cosmjs/amino";
import { Decimal, AssetEntry, BondingPeriodSelector, Duration, InstantiateMsg, ExecuteMsg, Uint128, AnsAsset, QueryMsg, MigrateMsg, Expiration, Timestamp, Uint64, ArrayOfTupleOfStringAndArrayOfClaim, Claim, ArrayOfClaim, Addr, PoolAddressBaseForAddr, AssetInfoBaseForAddr, PoolType, Config, PoolMetadata } from "./Autocompounder.types";
import { AutocompounderQueryMsgBuilder, AutocompounderExecuteMsgBuilder } from "./Autocompounder.msg-builder";
@@ -123,10 +121,10 @@ export class AutocompounderAppQueryClient implements IAutocompounderAppQueryClie
}
export interface IAutocompounderAppClient extends IAutocompounderAppQueryClient {
accountClient: AbstractAccountClient;
updateFeeConfig: (params: CamelCasedProperties<Extract<QueryMsg, {
updateFeeConfig: (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_fee_config: unknown;
}>["update_fee_config"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
deposit: (params: CamelCasedProperties<Extract<QueryMsg, {
deposit: (params: CamelCasedProperties<Extract<ExecuteMsg, {
deposit: unknown;
}>["deposit"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
withdraw: (fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
@@ -164,12 +162,12 @@ export class AutocompounderAppClient extends AutocompounderAppQueryClient implem
this.batchUnbond = this.batchUnbond.bind(this);
}

updateFeeConfig = async (params: CamelCasedProperties<Extract<QueryMsg, {
updateFeeConfig = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_fee_config: unknown;
}>["update_fee_config"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(AutocompounderExecuteMsgBuilder.updateFeeConfig(params), fee, memo, _funds);
};
deposit = async (params: CamelCasedProperties<Extract<QueryMsg, {
deposit = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
deposit: unknown;
}>["deposit"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(AutocompounderExecuteMsgBuilder.deposit(params), fee, memo, _funds);
114 changes: 114 additions & 0 deletions __output__/abstract/apps/autocompounder/Autocompounder.msg-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* This file was automatically generated by @cosmwasm/ts-codegen@latest.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { Decimal, AssetEntry, BondingPeriodSelector, Duration, InstantiateMsg, ExecuteMsg, Uint128, AnsAsset, QueryMsg, MigrateMsg, Expiration, Timestamp, Uint64, ArrayOfTupleOfStringAndArrayOfClaim, Claim, ArrayOfClaim, Addr, PoolAddressBaseForAddr, AssetInfoBaseForAddr, PoolType, Config, PoolMetadata } from "./Autocompounder.types";
import { CamelCasedProperties } from "type-fest";
export abstract class AutocompounderExecuteMsgBuilder {
static updateFeeConfig = ({
deposit,
performance,
withdrawal
}: CamelCasedProperties<Extract<ExecuteMsg, {
update_fee_config: unknown;
}>["update_fee_config"]>): ExecuteMsg => {
return {
update_fee_config: ({
deposit,
performance,
withdrawal
} as const)
};
};
static deposit = ({
funds
}: CamelCasedProperties<Extract<ExecuteMsg, {
deposit: unknown;
}>["deposit"]>): ExecuteMsg => {
return {
deposit: ({
funds
} as const)
};
};
static withdraw = (): ExecuteMsg => {
return {
withdraw: ({} as const)
};
};
static compound = (): ExecuteMsg => {
return {
compound: ({} as const)
};
};
static batchUnbond = (): ExecuteMsg => {
return {
batch_unbond: ({} as const)
};
};
}
export abstract class AutocompounderQueryMsgBuilder {
static config = (): QueryMsg => {
return {
config: ({} as const)
};
};
static pendingClaims = ({
address
}: CamelCasedProperties<Extract<QueryMsg, {
pending_claims: unknown;
}>["pending_claims"]>): QueryMsg => {
return {
pending_claims: ({
address
} as const)
};
};
static claims = ({
address
}: CamelCasedProperties<Extract<QueryMsg, {
claims: unknown;
}>["claims"]>): QueryMsg => {
return {
claims: ({
address
} as const)
};
};
static allClaims = ({
limit,
startAfter
}: CamelCasedProperties<Extract<QueryMsg, {
all_claims: unknown;
}>["all_claims"]>): QueryMsg => {
return {
all_claims: ({
limit,
start_after: startAfter
} as const)
};
};
static latestUnbonding = (): QueryMsg => {
return {
latest_unbonding: ({} as const)
};
};
static totalLpPosition = (): QueryMsg => {
return {
total_lp_position: ({} as const)
};
};
static balance = ({
address
}: CamelCasedProperties<Extract<QueryMsg, {
balance: unknown;
}>["balance"]>): QueryMsg => {
return {
balance: ({
address
} as const)
};
};
}
3 changes: 3 additions & 0 deletions packages/ts-codegen/__tests__/ts-codegen.test.ts
Original file line number Diff line number Diff line change
@@ -317,6 +317,9 @@ it('abstract-app/autocompounder', async () => {
messageComposer: {
enabled: true
},
msgBuilder: {
enabled: true
},
abstractApp: {
enabled: true
}
42 changes: 30 additions & 12 deletions packages/wasm-ast-types/src/abstract-app/abstract-app.ts
Original file line number Diff line number Diff line change
@@ -64,19 +64,23 @@ const ABSTRACT_CLIENT = 'AbstractClient';
const ABSTRACT_QUERY_CLIENT = 'AbstractQueryClient';
const ABSTRACT_ACCOUNT_QUERY_CLIENT = 'AbstractAccountQueryClient';

function extractCamelcasedQueryParams(jsonschema, underscoreName: string) {
const queryParams = Object.keys(
function extractCamelcasedMethodParams(
type: 'ExecuteMsg' | 'QueryMsg',
jsonschema,
underscoreName: string
) {
const methadParams = Object.keys(
jsonschema.properties[underscoreName]?.properties ?? {}
);

// the actual type of the ref
const methodParam = t.identifier('params');
methodParam.typeAnnotation = createExtractTypeAnnotation(
underscoreName,
'QueryMsg'
type
);

const parameters = queryParams.length ? [methodParam] : [];
const parameters = methadParams.length ? [methodParam] : [];
return parameters;
}

@@ -134,7 +138,11 @@ export const createAppQueryInterface = (
const underscoreName = Object.keys(jsonschema.properties)[0];
const methodName = camel(underscoreName);
const responseType = getResponseType(context, underscoreName);
const parameters = extractCamelcasedQueryParams(jsonschema, underscoreName);
const parameters = extractCamelcasedMethodParams(
'QueryMsg',
jsonschema,
underscoreName
);

const func = {
type: 'TSFunctionType',
@@ -234,14 +242,16 @@ export const createAppExecuteInterface = (
'ExecuteResult',
'AppExecuteMsg',
'AppModuleExecuteMsgBuilder',
'MsgExecuteContract',
'toUtf8'
]);

const methods = getMessageProperties(executeMsg).map((jsonschema) => {
const underscoreName = Object.keys(jsonschema.properties)[0];
const methodName = camel(underscoreName);
const parameters = extractCamelcasedQueryParams(jsonschema, underscoreName);
const parameters = extractCamelcasedMethodParams(
'ExecuteMsg',
jsonschema,
underscoreName
);

const func = {
type: 'TSFunctionType',
@@ -335,7 +345,7 @@ const EXECUTE_APP_FN = t.classProperty(
t.memberExpression(
t.thisExpression(),

t.identifier('accountClient'),
t.identifier('accountClient')
),
t.identifier('sender')
),
@@ -641,7 +651,11 @@ const createAppQueryMethod = (
moduleName
);

const parameters = extractCamelcasedQueryParams(schema, underscoreName);
const parameters = extractCamelcasedMethodParams(
'QueryMsg',
schema,
underscoreName
);

return t.classProperty(
t.identifier(methodName),
@@ -794,7 +808,7 @@ export const createAppExecuteClass = (
};

/*
deposit = async (params: CamelCasedProperties<Extract<QueryMsg, {
deposit = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
deposit: unknown;
}>["deposit"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return this._execute(AutocompounderExecuteMsgBuilder.deposit(params), fee, memo, _funds);
@@ -819,7 +833,11 @@ const createAppExecMethod = (
moduleName
);

const methodParameters = extractCamelcasedQueryParams(schema, underscoreName);
const methodParameters = extractCamelcasedMethodParams(
'ExecuteMsg',
schema,
underscoreName
);

return t.classProperty(
t.identifier(methodName),