@cosmwasm/ts-codegen 1.12.1 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +147 -118
  2. package/builder/builder.js +26 -24
  3. package/bundler/bundler.js +27 -17
  4. package/cli.js +2 -2
  5. package/commands/create-boilerplate.js +29 -18
  6. package/commands/generate.js +26 -35
  7. package/commands/install.js +22 -18
  8. package/esm/builder/builder.js +10 -18
  9. package/esm/bundler/bundler.js +10 -10
  10. package/esm/cli.js +2 -2
  11. package/esm/commands/create-boilerplate.js +11 -10
  12. package/esm/commands/generate.js +26 -35
  13. package/esm/commands/install.js +23 -19
  14. package/esm/file.js +4 -3
  15. package/esm/helpers/baseClient.js +184 -0
  16. package/esm/helpers/contractContextBase.js +15 -13
  17. package/esm/helpers/contractContextBaseShortHandCtor.js +11 -9
  18. package/esm/helpers/contractsContextTSX.js +7 -7
  19. package/esm/helpers/create-helpers.js +3 -1
  20. package/esm/helpers/index.js +1 -0
  21. package/esm/plugins/client.js +1 -1
  22. package/esm/plugins/message-builder.js +4 -4
  23. package/esm/plugins/message-composer.js +1 -1
  24. package/esm/plugins/plugin-base.js +3 -2
  25. package/esm/plugins/provider-bundle.js +9 -5
  26. package/esm/plugins/provider.js +1 -1
  27. package/esm/plugins/react-query.js +8 -7
  28. package/esm/plugins/recoil.js +4 -4
  29. package/esm/plugins/types.js +3 -3
  30. package/esm/ts-codegen.js +2 -1
  31. package/esm/utils/clean.js +1 -1
  32. package/esm/utils/cleanse.js +9 -5
  33. package/esm/utils/package.js +1 -1
  34. package/esm/utils/parse.js +5 -7
  35. package/esm/utils/prompt.js +2 -2
  36. package/esm/utils/schemas.js +32 -19
  37. package/esm/utils/unused.js +3 -4
  38. package/file.js +7 -3
  39. package/helpers/baseClient.d.ts +1 -0
  40. package/helpers/baseClient.js +187 -0
  41. package/helpers/contractContextBase.d.ts +1 -1
  42. package/helpers/contractContextBase.js +15 -13
  43. package/helpers/contractContextBaseShortHandCtor.d.ts +1 -1
  44. package/helpers/contractContextBaseShortHandCtor.js +11 -9
  45. package/helpers/contractsContextTSX.d.ts +1 -1
  46. package/helpers/contractsContextTSX.js +7 -7
  47. package/helpers/create-helpers.js +2 -0
  48. package/helpers/index.d.ts +1 -0
  49. package/helpers/index.js +1 -0
  50. package/package.json +20 -15
  51. package/plugins/client.js +18 -8
  52. package/plugins/message-builder.js +20 -10
  53. package/plugins/message-composer.js +18 -8
  54. package/plugins/plugin-base.js +19 -8
  55. package/plugins/provider-bundle.js +25 -11
  56. package/plugins/provider.js +17 -7
  57. package/plugins/react-query.js +24 -13
  58. package/plugins/recoil.js +20 -10
  59. package/plugins/types.js +19 -9
  60. package/ts-codegen.js +5 -1
  61. package/utils/clean.js +1 -1
  62. package/utils/cleanse.d.ts +1 -0
  63. package/utils/cleanse.js +12 -7
  64. package/utils/files.js +17 -7
  65. package/utils/package.js +2 -3
  66. package/utils/parse.js +5 -7
  67. package/utils/prompt.js +2 -2
  68. package/utils/schemas.d.ts +5 -1
  69. package/utils/schemas.js +34 -20
  70. package/utils/unused.js +20 -11
@@ -7,38 +7,33 @@ export default async (argv) => {
7
7
  type: 'path',
8
8
  name: 'schema',
9
9
  message: 'which directory contains the the Rust contracts?',
10
- default: './schema'
10
+ default: './schema',
11
11
  },
12
12
  {
13
13
  _: true,
14
14
  type: 'path',
15
15
  name: 'out',
16
16
  message: 'where is the output directory?',
17
- default: './ts'
17
+ default: './ts',
18
18
  },
19
19
  {
20
20
  _: true,
21
21
  type: 'string',
22
22
  name: 'name',
23
- message: 'contract name?'
23
+ message: 'contract name?',
24
24
  },
25
25
  {
26
26
  type: 'checkbox',
27
27
  name: 'plugin',
28
28
  message: 'which plugins?',
29
- choices: [
30
- 'client',
31
- 'recoil',
32
- 'react-query',
33
- 'message-composer'
34
- ]
29
+ choices: ['client', 'recoil', 'react-query', 'message-composer'],
35
30
  },
36
31
  {
37
32
  type: 'confirm',
38
33
  name: 'bundle',
39
34
  message: 'enable bundle?',
40
- default: true
41
- }
35
+ default: true,
36
+ },
42
37
  ];
43
38
  if (argv.typesOnly) {
44
39
  argv.plugin = 'types';
@@ -55,24 +50,23 @@ export default async (argv) => {
55
50
  type: 'confirm',
56
51
  name: 'optionalClient',
57
52
  message: 'optionalClient?',
58
- default: false
53
+ default: false,
59
54
  },
60
55
  {
61
56
  type: 'list',
62
57
  name: 'version',
63
58
  message: 'which react-query version?',
64
59
  default: 'v4',
65
- choices: ['v3', 'v4']
60
+ choices: ['v3', 'v4'],
66
61
  },
67
62
  {
68
63
  type: 'confirm',
69
64
  name: 'queryKeys',
70
65
  message: 'queryKeys?',
71
- default: false
66
+ default: false,
72
67
  },
73
68
  ]);
74
69
  }
75
- ;
76
70
  const { optionalClient, version, queryKeys } = await prompt(questions2, argv);
77
71
  const questions3 = [];
78
72
  if (version === 'v4') {
@@ -82,11 +76,10 @@ export default async (argv) => {
82
76
  type: 'confirm',
83
77
  name: 'mutations',
84
78
  message: 'Generate useMutation hooks?',
85
- default: false
86
- }
79
+ default: false,
80
+ },
87
81
  ]);
88
82
  }
89
- ;
90
83
  const { mutations } = await prompt(questions3, argv);
91
84
  const queryFactoryQuestions = [];
92
85
  if (queryKeys) {
@@ -96,11 +89,10 @@ export default async (argv) => {
96
89
  type: 'confirm',
97
90
  name: 'queryFactory',
98
91
  message: 'queryFactory? ',
99
- default: false
100
- }
92
+ default: false,
93
+ },
101
94
  ]);
102
95
  }
103
- ;
104
96
  const { queryFactory } = await prompt(queryFactoryQuestions, argv);
105
97
  ///////// END REACT QUERY
106
98
  ///////// BUNDLE
@@ -111,27 +103,26 @@ export default async (argv) => {
111
103
  type: 'string',
112
104
  name: 'bundleFile',
113
105
  message: 'bundleFile?',
114
- default: 'index.ts'
106
+ default: 'index.ts',
115
107
  },
116
108
  {
117
109
  type: 'string',
118
110
  name: 'bundleScope',
119
111
  message: 'bundleScope?',
120
- default: 'contracts'
121
- }
112
+ default: 'contracts',
113
+ },
122
114
  ]);
123
115
  }
124
- ;
125
116
  const { bundleFile, bundleScope } = await prompt(questions4, argv);
126
117
  ///////// END BUNDLE
127
118
  const options = {
128
119
  types: {
129
- enabled: true
120
+ enabled: true,
130
121
  },
131
122
  client: {
132
123
  enabled: plugin.includes('client') ||
133
124
  plugin.includes('recoil') ||
134
- plugin.includes('react-query')
125
+ plugin.includes('react-query'),
135
126
  },
136
127
  reactQuery: {
137
128
  enabled: plugin.includes('react-query'),
@@ -139,31 +130,31 @@ export default async (argv) => {
139
130
  queryKeys,
140
131
  version,
141
132
  mutations,
142
- queryFactory
133
+ queryFactory,
143
134
  },
144
135
  recoil: {
145
136
  enabled: plugin.includes('recoil'),
146
137
  },
147
138
  messageComposer: {
148
- enabled: plugin.includes('message-composer')
139
+ enabled: plugin.includes('message-composer'),
149
140
  },
150
141
  messageBuilder: {
151
- enabled: plugin.includes('message-builder')
142
+ enabled: plugin.includes('message-builder'),
152
143
  },
153
144
  bundle: {
154
145
  enabled: bundle,
155
146
  scope: bundleScope,
156
- bundleFile
157
- }
147
+ bundleFile,
148
+ },
158
149
  };
159
150
  await codegen({
160
151
  contracts: [
161
152
  {
162
153
  name,
163
- dir: schema
164
- }
154
+ dir: schema,
155
+ },
165
156
  ],
166
157
  outPath: out,
167
- options
158
+ options,
168
159
  });
169
160
  };
@@ -1,5 +1,5 @@
1
1
  import { readFileSync, writeFileSync } from 'fs';
2
- import { sync as glob } from 'glob';
2
+ import { globSync as glob } from 'glob';
3
3
  import { sync as mkdirp } from 'mkdirp';
4
4
  import { tmpdir } from 'os';
5
5
  import { parse } from 'parse-package-name';
@@ -11,10 +11,12 @@ const TMPDIR = tmpdir();
11
11
  const rnd = () => Math.random().toString(36).substring(2, 15) +
12
12
  Math.random().toString(36).substring(2, 15);
13
13
  const getPackages = (names) => {
14
- return names.map(pkg => {
14
+ return names
15
+ .map((pkg) => {
15
16
  const { name, version } = parse(pkg);
16
17
  return `${name}@${version}`;
17
- }).join(' ');
18
+ })
19
+ .join(' ');
18
20
  };
19
21
  export default async (argv) => {
20
22
  // don't prompt if we got this...
@@ -27,7 +29,7 @@ export default async (argv) => {
27
29
  try {
28
30
  thisPackage = JSON.parse(readFileSync(join(cur, 'package.json'), 'utf-8'));
29
31
  }
30
- catch (e) {
32
+ catch {
31
33
  throw new Error('make sure you are inside of a telescope package!');
32
34
  }
33
35
  // what are we installing?
@@ -46,14 +48,14 @@ export default async (argv) => {
46
48
  'stargaze-vending-factory',
47
49
  'stargaze-vending-minter',
48
50
  'stargaze-whitelist',
49
- 'wasmswap'
50
- ].map(name => {
51
+ 'wasmswap',
52
+ ].map((name) => {
51
53
  return {
52
54
  name,
53
- value: `@cosmjson/${name}`
55
+ value: `@cosmjson/${name}`,
54
56
  };
55
- })
56
- }
57
+ }),
58
+ },
57
59
  ], argv);
58
60
  // install
59
61
  if (!Array.isArray(pkg))
@@ -63,26 +65,28 @@ export default async (argv) => {
63
65
  process.chdir(tmp);
64
66
  exec(`npm install ${getPackages(pkg)} --production --prefix ./smart-contracts`);
65
67
  // protos
66
- const pkgs = glob('./smart-contracts/**/package.json');
68
+ const pkgs = glob('./smart-contracts/**/package.json').sort();
67
69
  const cmds = pkgs
68
- .filter((f) => { return f !== './smart-contracts/package.json'; })
70
+ .filter((f) => {
71
+ return f !== './smart-contracts/package.json';
72
+ })
69
73
  .map((f) => resolve(join(tmp, f)))
70
74
  .map((conf) => {
71
75
  const extDir = dirname(conf);
72
76
  const dir = extDir.split('node_modules/')[1];
73
77
  const dst = basename(dir);
74
- const files = glob(`${extDir}/**/*`, { nodir: true });
75
- files.forEach(f => {
76
- if (extname(f) === '.json'
77
- || f === 'package.json'
78
- || /license/i.test(f)
79
- || /readme/i.test(f))
78
+ const files = glob(`${extDir}/**/*`, { nodir: true }).sort();
79
+ files.forEach((f) => {
80
+ if (extname(f) === '.json' ||
81
+ f === 'package.json' ||
82
+ /license/i.test(f) ||
83
+ /readme/i.test(f))
80
84
  return;
81
85
  rimraf(f);
82
86
  });
83
87
  return [extDir, resolve(join(cur, 'contracts', dst)), dir];
84
88
  });
85
- // move protos
89
+ // move protos
86
90
  for (const [src, dst, pkg] of cmds) {
87
91
  rimraf(dst);
88
92
  console.log(`installing ${pkg}...`);
@@ -95,7 +99,7 @@ export default async (argv) => {
95
99
  thisPackage.devDependencies = thisPackage.devDependencies ?? {};
96
100
  thisPackage.devDependencies = {
97
101
  ...thisPackage.devDependencies,
98
- ...deps
102
+ ...deps,
99
103
  };
100
104
  thisPackage.devDependencies = Object.fromEntries(Object.entries(thisPackage.devDependencies).sort());
101
105
  writeFileSync(join(cur, 'package.json'), JSON.stringify(thisPackage, null, 2));
package/esm/file.js CHANGED
@@ -1,15 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from 'fs';
3
+ import minimist from 'minimist';
3
4
  import { cli } from './cli';
4
5
  import { prompt } from './utils/prompt';
5
- const argv = require('minimist')(process.argv.slice(2));
6
+ const argv = minimist(process.argv.slice(2));
6
7
  const question = [
7
8
  {
8
9
  _: true,
9
10
  type: 'string',
10
11
  name: 'file',
11
- message: 'file'
12
- }
12
+ message: 'file',
13
+ },
13
14
  ];
14
15
  (async () => {
15
16
  const { file } = await prompt(question, argv);
@@ -0,0 +1,184 @@
1
+ export const baseClient = `
2
+ import { StdFee, Coin } from '@interchainjs/types';
3
+ import { DirectSigner } from '@interchainjs/cosmos';
4
+ import { getSmartContractState } from 'interchainjs/cosmwasm/wasm/v1/query.rpc.func';
5
+ import { executeContract } from 'interchainjs/cosmwasm/wasm/v1/tx.rpc.func';
6
+ import { QuerySmartContractStateRequest, QuerySmartContractStateResponse } from 'interchainjs/cosmwasm/wasm/v1/query';
7
+ import { MsgExecuteContract } from 'interchainjs/cosmwasm/wasm/v1/tx';
8
+ import { Chain } from '@chain-registry/v2-types';
9
+
10
+ // Encoding utility functions
11
+ const fromUint8Array = <T>(uint8Array: Uint8Array): T => {
12
+ const text = new TextDecoder().decode(uint8Array);
13
+ return JSON.parse(text);
14
+ };
15
+
16
+ const toUint8Array = (obj: any): Uint8Array => {
17
+ const text = JSON.stringify(obj);
18
+ return new TextEncoder().encode(text);
19
+ };
20
+
21
+ // Chain registry configuration
22
+ // The amount under gasPrice represents gas price per unit
23
+ export interface ChainConfig {
24
+ chain?: Chain;
25
+ gasPrice?: {
26
+ denom: string;
27
+ amount: string;
28
+ };
29
+ }
30
+
31
+ // Gas fee calculation utilities
32
+ export const calculateGasFromChain = (chain: Chain, gasAmount: string): StdFee => {
33
+ try {
34
+ const feeTokens = chain.fees?.feeTokens;
35
+
36
+ if (feeTokens && feeTokens.length > 0) {
37
+ const primaryToken = feeTokens[0];
38
+ // v2 chain-registry uses camelCase: averageGasPrice, lowGasPrice, fixedMinGasPrice
39
+ const gasPrice = primaryToken.averageGasPrice || primaryToken.lowGasPrice || primaryToken.fixedMinGasPrice || 0.025;
40
+ const gasAmountNum = parseInt(gasAmount);
41
+ const feeAmount = Math.ceil(gasAmountNum * gasPrice).toString();
42
+
43
+ return {
44
+ amount: [{
45
+ denom: primaryToken.denom,
46
+ amount: feeAmount
47
+ }],
48
+ gas: gasAmount
49
+ };
50
+ }
51
+ } catch (error) {
52
+ console.warn('Failed to calculate gas from chain registry:', error);
53
+ }
54
+
55
+ // Fallback to default
56
+ return { amount: [], gas: gasAmount };
57
+ };
58
+
59
+ // Default gas amount - users can easily change this
60
+ export let DEFAULT_GAS_AMOUNT = '200000';
61
+
62
+ // Allow users to set their preferred default gas amount
63
+ export const setDefaultGasAmount = (gasAmount: string): void => {
64
+ DEFAULT_GAS_AMOUNT = gasAmount;
65
+ };
66
+
67
+ // Get current default gas amount
68
+ export const getDefaultGasAmount = (): string => DEFAULT_GAS_AMOUNT;
69
+
70
+ export const getAutoGasFee = (chainConfig?: ChainConfig): StdFee => {
71
+ const gasAmount = DEFAULT_GAS_AMOUNT;
72
+
73
+ if (chainConfig?.chain) {
74
+ return calculateGasFromChain(chainConfig.chain, gasAmount);
75
+ }
76
+
77
+ if (chainConfig?.gasPrice) {
78
+ const gasAmountNum = parseInt(gasAmount);
79
+ const gasPriceNum = parseFloat(chainConfig.gasPrice.amount);
80
+ const feeAmount = Math.ceil(gasAmountNum * gasPriceNum).toString();
81
+
82
+ return {
83
+ amount: [{
84
+ denom: chainConfig.gasPrice.denom,
85
+ amount: feeAmount
86
+ }],
87
+ gas: gasAmount
88
+ };
89
+ }
90
+
91
+ // Fallback: no fee tokens, just gas amount
92
+ return { amount: [], gas: gasAmount };
93
+ };
94
+
95
+ // InterchainJS interfaces for CosmWasm clients
96
+ export interface ICosmWasmClient {
97
+ queryContractSmart(contractAddr: string, query: any): Promise<any>;
98
+ }
99
+
100
+ export interface ISigningCosmWasmClient {
101
+ execute(
102
+ sender: string,
103
+ contractAddress: string,
104
+ msg: any,
105
+ fee?: number | StdFee | "auto",
106
+ memo?: string,
107
+ funds?: Coin[],
108
+ chainConfig?: ChainConfig
109
+ ): Promise<any>;
110
+ }
111
+
112
+ export interface ISigningClient {
113
+ signAndBroadcast(
114
+ signerAddress: string,
115
+ messages: any[],
116
+ fee: number | StdFee | "auto",
117
+ memo?: string
118
+ ): Promise<any>;
119
+ }
120
+
121
+ // Helper functions to create InterchainJS clients
122
+ export function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient {
123
+ return {
124
+ queryContractSmart: async (contractAddr: string, query: any) => {
125
+ // Create the request object
126
+ const request: QuerySmartContractStateRequest = {
127
+ address: contractAddr,
128
+ queryData: toUint8Array(query)
129
+ };
130
+
131
+ // Execute the query using InterchainJS
132
+ const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);
133
+
134
+ // Parse and return the result
135
+ return fromUint8Array(response.data);
136
+ },
137
+ };
138
+ }
139
+
140
+ export function getSigningCosmWasmClient(signingClient: DirectSigner): ISigningCosmWasmClient {
141
+ return {
142
+ execute: async (
143
+ sender: string,
144
+ contractAddress: string,
145
+ msg: any,
146
+ fee?: number | StdFee | "auto",
147
+ memo?: string,
148
+ funds?: Coin[],
149
+ chainConfig?: ChainConfig
150
+ ) => {
151
+ // Handle fee conversion
152
+ let finalFee: StdFee;
153
+ if (typeof fee === 'number') {
154
+ finalFee = { amount: [], gas: fee.toString() };
155
+ } else if (fee === 'auto') {
156
+ finalFee = getAutoGasFee(chainConfig);
157
+ } else if (fee) {
158
+ finalFee = fee;
159
+ } else {
160
+ finalFee = getAutoGasFee(chainConfig);
161
+ }
162
+
163
+ // Create the message object
164
+ const message: MsgExecuteContract = {
165
+ sender,
166
+ contract: contractAddress,
167
+ msg: toUint8Array(msg),
168
+ funds: funds || []
169
+ };
170
+
171
+ // Execute the transaction using InterchainJS
172
+ const result = await executeContract(
173
+ signingClient as any,
174
+ sender,
175
+ message,
176
+ finalFee,
177
+ memo || ''
178
+ );
179
+
180
+ return result;
181
+ },
182
+ };
183
+ }
184
+ `;
@@ -1,13 +1,15 @@
1
1
  export const contractContextBase = `
2
2
  import {
3
- CosmWasmClient,
4
- SigningCosmWasmClient,
5
- } from '@cosmjs/cosmwasm-stargate';
3
+ ICosmWasmClient,
4
+ ISigningCosmWasmClient,
5
+ getCosmWasmClient,
6
+ getSigningCosmWasmClient,
7
+ } from './baseClient';
6
8
 
7
9
  export interface IContractConstructor {
8
10
  address: string | undefined;
9
- cosmWasmClient: CosmWasmClient | undefined;
10
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
11
+ cosmWasmClient: ICosmWasmClient | undefined;
12
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
11
13
  }
12
14
 
13
15
  export const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';
@@ -49,15 +51,15 @@ export class ContractBase<
49
51
  > {
50
52
 
51
53
  address: string | undefined;
52
- cosmWasmClient: CosmWasmClient | undefined;
53
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
54
+ cosmWasmClient: ICosmWasmClient | undefined;
55
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
54
56
  TSign?: new (
55
- client: SigningCosmWasmClient,
57
+ client: ISigningCosmWasmClient,
56
58
  sender: string,
57
59
  contractAddress: string
58
60
  ) => TSign;
59
61
  TQuery?: new (
60
- client: CosmWasmClient,
62
+ client: ICosmWasmClient,
61
63
  contractAddress: string
62
64
  ) => TQuery;
63
65
  TMsgComposer?: new (
@@ -67,15 +69,15 @@ export class ContractBase<
67
69
 
68
70
  constructor(
69
71
  address: string | undefined,
70
- cosmWasmClient: CosmWasmClient | undefined,
71
- signingCosmWasmClient: SigningCosmWasmClient | undefined,
72
+ cosmWasmClient: ICosmWasmClient | undefined,
73
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined,
72
74
  TSign?: new (
73
- client: SigningCosmWasmClient,
75
+ client: ISigningCosmWasmClient,
74
76
  sender: string,
75
77
  contractAddress: string
76
78
  ) => TSign,
77
79
  TQuery?: new (
78
- client: CosmWasmClient,
80
+ client: ICosmWasmClient,
79
81
  contractAddress: string
80
82
  ) => TQuery,
81
83
  TMsgComposer?: new (
@@ -1,13 +1,15 @@
1
1
  export const contractContextBaseShortHandCtor = `
2
2
  import {
3
- CosmWasmClient,
4
- SigningCosmWasmClient,
5
- } from '@cosmjs/cosmwasm-stargate';
3
+ ICosmWasmClient,
4
+ ISigningCosmWasmClient,
5
+ getCosmWasmClient,
6
+ getSigningCosmWasmClient,
7
+ } from './baseClient';
6
8
 
7
9
  export interface IContractConstructor {
8
10
  address: string | undefined;
9
- cosmWasmClient: CosmWasmClient | undefined;
10
- signingCosmWasmClient: SigningCosmWasmClient | undefined;
11
+ cosmWasmClient: ICosmWasmClient | undefined;
12
+ signingCosmWasmClient: ISigningCosmWasmClient | undefined;
11
13
  }
12
14
 
13
15
  export const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';
@@ -49,15 +51,15 @@ export class ContractBase<
49
51
  > {
50
52
  constructor(
51
53
  protected address: string | undefined,
52
- protected cosmWasmClient: CosmWasmClient | undefined,
53
- protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
54
+ protected cosmWasmClient: ICosmWasmClient | undefined,
55
+ protected signingCosmWasmClient: ISigningCosmWasmClient | undefined,
54
56
  private TSign?: new (
55
- client: SigningCosmWasmClient,
57
+ client: ISigningCosmWasmClient,
56
58
  sender: string,
57
59
  contractAddress: string
58
60
  ) => TSign,
59
61
  private TQuery?: new (
60
- client: CosmWasmClient,
62
+ client: ICosmWasmClient,
61
63
  contractAddress: string
62
64
  ) => TQuery,
63
65
  private TMsgComposer?: new (
@@ -1,16 +1,16 @@
1
1
  export const contractsContextTSX = `
2
2
  import React, { useEffect, useMemo, useRef, useState, useContext } from 'react';
3
3
  import {
4
- CosmWasmClient,
5
- SigningCosmWasmClient,
6
- } from '@cosmjs/cosmwasm-stargate';
4
+ ICosmWasmClient,
5
+ ISigningCosmWasmClient,
6
+ } from './baseClient';
7
7
 
8
8
  import { IContractsContext, getProviders } from './contractContextProviders';
9
9
 
10
10
  export interface ContractsConfig {
11
11
  address: string | undefined;
12
- getCosmWasmClient: () => Promise<CosmWasmClient>;
13
- getSigningCosmWasmClient: () => Promise<SigningCosmWasmClient>;
12
+ getCosmWasmClient: () => Promise<ICosmWasmClient>;
13
+ getSigningCosmWasmClient: () => Promise<ISigningCosmWasmClient>;
14
14
  }
15
15
 
16
16
  const ContractsContext = React.createContext<IContractsContext | null>(null);
@@ -22,9 +22,9 @@ export const ContractsProvider = ({
22
22
  children: React.ReactNode;
23
23
  contractsConfig: ContractsConfig;
24
24
  }) => {
25
- const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient>();
25
+ const [cosmWasmClient, setCosmWasmClient] = useState<ICosmWasmClient>();
26
26
  const [signingCosmWasmClient, setSigningCosmWasmClient] =
27
- useState<SigningCosmWasmClient>();
27
+ useState<ISigningCosmWasmClient>();
28
28
 
29
29
  const { address, getCosmWasmClient, getSigningCosmWasmClient } =
30
30
  contractsConfig;
@@ -1,6 +1,6 @@
1
1
  import { sync as mkdirp } from 'mkdirp';
2
2
  import { basename, dirname, extname, join } from 'path';
3
- import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from '../helpers';
3
+ import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, baseClient, } from '../helpers';
4
4
  import { writeContentToFile } from '../utils/files';
5
5
  import { header } from '../utils/header';
6
6
  const write = (outPath, file, content, varname) => {
@@ -17,6 +17,8 @@ const write = (outPath, file, content, varname) => {
17
17
  };
18
18
  export const createHelpers = (input, builderContext) => {
19
19
  const files = [];
20
+ // Always generate baseClient.ts since InterchainJS interfaces are needed by all clients
21
+ files.push(write(input.outPath, 'baseClient.ts', baseClient));
20
22
  if (input.options?.useContractsHook?.enabled &&
21
23
  Object.keys(builderContext.providers)?.length) {
22
24
  const useShorthandCtor = input.options?.useShorthandCtor;
@@ -1,3 +1,4 @@
1
1
  export * from './contractContextBase';
2
2
  export * from './contractContextBaseShortHandCtor';
3
+ export * from './baseClient';
3
4
  export * from './contractsContextTSX';
@@ -43,7 +43,7 @@ export class ClientPlugin extends BuilderPluginBase {
43
43
  context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
44
44
  }
45
45
  }
46
- if (typeHash.hasOwnProperty('Coin')) {
46
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
47
47
  // @ts-ignore
48
48
  delete context.utils.Coin;
49
49
  }
@@ -1,5 +1,5 @@
1
1
  import * as w from '@cosmwasm/ts-codegen-ast';
2
- import { getMessageProperties, RenderContext } from '@cosmwasm/ts-codegen-ast';
2
+ import { getMessageProperties, RenderContext, } from '@cosmwasm/ts-codegen-ast';
3
3
  import { pascal } from 'case';
4
4
  import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
5
5
  import { BuilderPluginBase } from './plugin-base';
@@ -37,7 +37,7 @@ export class MessageBuilderPlugin extends BuilderPluginBase {
37
37
  body.push(w.createMessageBuilderClass(context, className, QueryMsg));
38
38
  }
39
39
  }
40
- if (typeHash.hasOwnProperty('Coin')) {
40
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
41
41
  // @ts-ignore
42
42
  delete context.utils.Coin;
43
43
  }
@@ -45,8 +45,8 @@ export class MessageBuilderPlugin extends BuilderPluginBase {
45
45
  {
46
46
  type: 'message-builder',
47
47
  localname,
48
- body
49
- }
48
+ body,
49
+ },
50
50
  ];
51
51
  }
52
52
  }
@@ -30,7 +30,7 @@ export class MessageComposerPlugin extends BuilderPluginBase {
30
30
  context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
31
31
  }
32
32
  }
33
- if (typeHash.hasOwnProperty('Coin')) {
33
+ if (Object.prototype.hasOwnProperty.call(typeHash, 'Coin')) {
34
34
  // @ts-ignore
35
35
  delete context.utils.Coin;
36
36
  }