@manifest-network/manifest-mcp-browser 0.1.1 → 0.1.5

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 (121) hide show
  1. package/.github/workflows/publish.yml +4 -2
  2. package/CLAUDE.md +7 -3
  3. package/README.md +1 -1
  4. package/dist/client.d.ts +6 -1
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/client.js +77 -21
  7. package/dist/client.js.map +1 -1
  8. package/dist/cosmos.d.ts.map +1 -1
  9. package/dist/cosmos.js +7 -57
  10. package/dist/cosmos.js.map +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +16 -25
  13. package/dist/index.js.map +1 -1
  14. package/dist/modules.d.ts +30 -1
  15. package/dist/modules.d.ts.map +1 -1
  16. package/dist/modules.js +65 -1
  17. package/dist/modules.js.map +1 -1
  18. package/dist/modules.test.js +58 -1
  19. package/dist/modules.test.js.map +1 -1
  20. package/dist/queries/auth.d.ts +7 -1
  21. package/dist/queries/auth.d.ts.map +1 -1
  22. package/dist/queries/auth.js +18 -45
  23. package/dist/queries/auth.js.map +1 -1
  24. package/dist/queries/bank.d.ts +7 -1
  25. package/dist/queries/bank.d.ts.map +1 -1
  26. package/dist/queries/bank.js +24 -38
  27. package/dist/queries/bank.js.map +1 -1
  28. package/dist/queries/billing.d.ts +7 -1
  29. package/dist/queries/billing.d.ts.map +1 -1
  30. package/dist/queries/billing.js +28 -54
  31. package/dist/queries/billing.js.map +1 -1
  32. package/dist/queries/distribution.d.ts +7 -1
  33. package/dist/queries/distribution.d.ts.map +1 -1
  34. package/dist/queries/distribution.js +18 -36
  35. package/dist/queries/distribution.js.map +1 -1
  36. package/dist/queries/gov.d.ts +7 -1
  37. package/dist/queries/gov.d.ts.map +1 -1
  38. package/dist/queries/gov.js +24 -41
  39. package/dist/queries/gov.js.map +1 -1
  40. package/dist/queries/index.d.ts +2 -1
  41. package/dist/queries/index.d.ts.map +1 -1
  42. package/dist/queries/index.js +1 -1
  43. package/dist/queries/index.js.map +1 -1
  44. package/dist/queries/staking.d.ts +7 -1
  45. package/dist/queries/staking.d.ts.map +1 -1
  46. package/dist/queries/staking.js +36 -59
  47. package/dist/queries/staking.js.map +1 -1
  48. package/dist/queries/utils.d.ts +42 -10
  49. package/dist/queries/utils.d.ts.map +1 -1
  50. package/dist/queries/utils.js +64 -12
  51. package/dist/queries/utils.js.map +1 -1
  52. package/dist/queries/utils.test.js +68 -8
  53. package/dist/queries/utils.test.js.map +1 -1
  54. package/dist/transactions/bank.d.ts +2 -2
  55. package/dist/transactions/bank.d.ts.map +1 -1
  56. package/dist/transactions/bank.js +9 -18
  57. package/dist/transactions/bank.js.map +1 -1
  58. package/dist/transactions/billing.d.ts +2 -2
  59. package/dist/transactions/billing.d.ts.map +1 -1
  60. package/dist/transactions/billing.js +29 -86
  61. package/dist/transactions/billing.js.map +1 -1
  62. package/dist/transactions/distribution.d.ts +2 -2
  63. package/dist/transactions/distribution.d.ts.map +1 -1
  64. package/dist/transactions/distribution.js +7 -13
  65. package/dist/transactions/distribution.js.map +1 -1
  66. package/dist/transactions/gov.d.ts +2 -2
  67. package/dist/transactions/gov.d.ts.map +1 -1
  68. package/dist/transactions/gov.js +29 -20
  69. package/dist/transactions/gov.js.map +1 -1
  70. package/dist/transactions/index.d.ts +1 -1
  71. package/dist/transactions/index.d.ts.map +1 -1
  72. package/dist/transactions/index.js +1 -1
  73. package/dist/transactions/index.js.map +1 -1
  74. package/dist/transactions/manifest.d.ts +2 -2
  75. package/dist/transactions/manifest.d.ts.map +1 -1
  76. package/dist/transactions/manifest.js +7 -14
  77. package/dist/transactions/manifest.js.map +1 -1
  78. package/dist/transactions/staking.d.ts +2 -2
  79. package/dist/transactions/staking.d.ts.map +1 -1
  80. package/dist/transactions/staking.js +7 -13
  81. package/dist/transactions/staking.js.map +1 -1
  82. package/dist/transactions/utils.d.ts +63 -1
  83. package/dist/transactions/utils.d.ts.map +1 -1
  84. package/dist/transactions/utils.js +121 -2
  85. package/dist/transactions/utils.js.map +1 -1
  86. package/dist/transactions/utils.test.js +351 -1
  87. package/dist/transactions/utils.test.js.map +1 -1
  88. package/dist/types.d.ts +203 -8
  89. package/dist/types.d.ts.map +1 -1
  90. package/dist/types.js.map +1 -1
  91. package/dist/wallet/mnemonic.d.ts +1 -0
  92. package/dist/wallet/mnemonic.d.ts.map +1 -1
  93. package/dist/wallet/mnemonic.js +34 -13
  94. package/dist/wallet/mnemonic.js.map +1 -1
  95. package/package.json +5 -1
  96. package/src/client.ts +84 -21
  97. package/src/cosmos.ts +13 -109
  98. package/src/index.ts +17 -23
  99. package/src/modules.test.ts +60 -0
  100. package/src/modules.ts +122 -5
  101. package/src/queries/auth.ts +35 -74
  102. package/src/queries/bank.ts +40 -58
  103. package/src/queries/billing.ts +46 -86
  104. package/src/queries/distribution.ts +35 -59
  105. package/src/queries/gov.ts +40 -64
  106. package/src/queries/index.ts +10 -1
  107. package/src/queries/staking.ts +55 -91
  108. package/src/queries/utils.test.ts +103 -8
  109. package/src/queries/utils.ts +92 -12
  110. package/src/transactions/bank.ts +9 -33
  111. package/src/transactions/billing.ts +30 -137
  112. package/src/transactions/distribution.ts +7 -29
  113. package/src/transactions/gov.ts +33 -37
  114. package/src/transactions/index.ts +1 -1
  115. package/src/transactions/manifest.ts +7 -29
  116. package/src/transactions/staking.ts +7 -29
  117. package/src/transactions/utils.test.ts +390 -1
  118. package/src/transactions/utils.ts +191 -2
  119. package/src/types.ts +318 -9
  120. package/src/wallet/mnemonic.ts +41 -17
  121. package/.claude/settings.local.json +0 -20
@@ -1,25 +1,40 @@
1
1
  import { ManifestQueryClient } from '../client.js';
2
- import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
3
- import { parseBigInt, defaultPagination } from './utils.js';
2
+ import {
3
+ DelegationResult, DelegationsResult, UnbondingDelegationResult, UnbondingDelegationsResult,
4
+ RedelegationsResult, ValidatorResult, ValidatorsResult, StakingPoolResult,
5
+ StakingParamsResult, HistoricalInfoResult
6
+ } from '../types.js';
7
+ import { parseBigInt, requireArgs, extractPaginationArgs } from './utils.js';
8
+ import { throwUnsupportedSubcommand } from '../modules.js';
9
+
10
+ /** Staking query result union type */
11
+ type StakingQueryResult =
12
+ | DelegationResult
13
+ | DelegationsResult
14
+ | UnbondingDelegationResult
15
+ | UnbondingDelegationsResult
16
+ | RedelegationsResult
17
+ | ValidatorResult
18
+ | ValidatorsResult
19
+ | StakingPoolResult
20
+ | StakingParamsResult
21
+ | HistoricalInfoResult;
4
22
 
5
23
  /**
6
24
  * Route staking query to manifestjs query client
25
+ *
26
+ * Paginated queries support --limit flag (default: 100, max: 1000)
7
27
  */
8
28
  export async function routeStakingQuery(
9
29
  queryClient: ManifestQueryClient,
10
30
  subcommand: string,
11
31
  args: string[]
12
- ): Promise<Record<string, unknown>> {
32
+ ): Promise<StakingQueryResult> {
13
33
  const staking = queryClient.cosmos.staking.v1beta1;
14
34
 
15
35
  switch (subcommand) {
16
36
  case 'delegation': {
17
- if (args.length < 2) {
18
- throw new ManifestMCPError(
19
- ManifestMCPErrorCode.QUERY_FAILED,
20
- 'delegation requires delegator-address and validator-address arguments'
21
- );
22
- }
37
+ requireArgs(args, 2, ['delegator-address', 'validator-address'], 'staking delegation');
23
38
  const [delegatorAddr, validatorAddr] = args;
24
39
  const result = await staking.delegation({
25
40
  delegatorAddr,
@@ -29,14 +44,10 @@ export async function routeStakingQuery(
29
44
  }
30
45
 
31
46
  case 'delegations': {
32
- if (args.length < 1) {
33
- throw new ManifestMCPError(
34
- ManifestMCPErrorCode.QUERY_FAILED,
35
- 'delegations requires delegator-address argument'
36
- );
37
- }
38
- const [delegatorAddr] = args;
39
- const result = await staking.delegatorDelegations({ delegatorAddr, pagination: defaultPagination });
47
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking delegations');
48
+ requireArgs(remainingArgs, 1, ['delegator-address'], 'staking delegations');
49
+ const [delegatorAddr] = remainingArgs;
50
+ const result = await staking.delegatorDelegations({ delegatorAddr, pagination });
40
51
  return {
41
52
  delegationResponses: result.delegationResponses,
42
53
  pagination: result.pagination,
@@ -44,12 +55,7 @@ export async function routeStakingQuery(
44
55
  }
45
56
 
46
57
  case 'unbonding-delegation': {
47
- if (args.length < 2) {
48
- throw new ManifestMCPError(
49
- ManifestMCPErrorCode.QUERY_FAILED,
50
- 'unbonding-delegation requires delegator-address and validator-address arguments'
51
- );
52
- }
58
+ requireArgs(args, 2, ['delegator-address', 'validator-address'], 'staking unbonding-delegation');
53
59
  const [delegatorAddr, validatorAddr] = args;
54
60
  const result = await staking.unbondingDelegation({
55
61
  delegatorAddr,
@@ -59,14 +65,10 @@ export async function routeStakingQuery(
59
65
  }
60
66
 
61
67
  case 'unbonding-delegations': {
62
- if (args.length < 1) {
63
- throw new ManifestMCPError(
64
- ManifestMCPErrorCode.QUERY_FAILED,
65
- 'unbonding-delegations requires delegator-address argument'
66
- );
67
- }
68
- const [delegatorAddr] = args;
69
- const result = await staking.delegatorUnbondingDelegations({ delegatorAddr, pagination: defaultPagination });
68
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking unbonding-delegations');
69
+ requireArgs(remainingArgs, 1, ['delegator-address'], 'staking unbonding-delegations');
70
+ const [delegatorAddr] = remainingArgs;
71
+ const result = await staking.delegatorUnbondingDelegations({ delegatorAddr, pagination });
70
72
  return {
71
73
  unbondingResponses: result.unbondingResponses,
72
74
  pagination: result.pagination,
@@ -74,20 +76,17 @@ export async function routeStakingQuery(
74
76
  }
75
77
 
76
78
  case 'redelegations': {
77
- if (args.length < 1) {
78
- throw new ManifestMCPError(
79
- ManifestMCPErrorCode.QUERY_FAILED,
80
- 'redelegations requires delegator-address argument'
81
- );
82
- }
83
- const [delegatorAddr] = args;
84
- const srcValidatorAddr = args[1] || '';
85
- const dstValidatorAddr = args[2] || '';
79
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking redelegations');
80
+ requireArgs(remainingArgs, 1, ['delegator-address'], 'staking redelegations');
81
+ const [delegatorAddr] = remainingArgs;
82
+ // Optional: src and dst validator addresses for filtering
83
+ const srcValidatorAddr = remainingArgs[1] || '';
84
+ const dstValidatorAddr = remainingArgs[2] || '';
86
85
  const result = await staking.redelegations({
87
86
  delegatorAddr,
88
87
  srcValidatorAddr,
89
88
  dstValidatorAddr,
90
- pagination: defaultPagination,
89
+ pagination,
91
90
  });
92
91
  return {
93
92
  redelegationResponses: result.redelegationResponses,
@@ -96,32 +95,25 @@ export async function routeStakingQuery(
96
95
  }
97
96
 
98
97
  case 'validator': {
99
- if (args.length < 1) {
100
- throw new ManifestMCPError(
101
- ManifestMCPErrorCode.QUERY_FAILED,
102
- 'validator requires validator-address argument'
103
- );
104
- }
98
+ requireArgs(args, 1, ['validator-address'], 'staking validator');
105
99
  const [validatorAddr] = args;
106
100
  const result = await staking.validator({ validatorAddr });
107
101
  return { validator: result.validator };
108
102
  }
109
103
 
110
104
  case 'validators': {
111
- const status = args[0] || '';
112
- const result = await staking.validators({ status, pagination: defaultPagination });
105
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking validators');
106
+ // Optional: status filter
107
+ const status = remainingArgs[0] || '';
108
+ const result = await staking.validators({ status, pagination });
113
109
  return { validators: result.validators, pagination: result.pagination };
114
110
  }
115
111
 
116
112
  case 'validator-delegations': {
117
- if (args.length < 1) {
118
- throw new ManifestMCPError(
119
- ManifestMCPErrorCode.QUERY_FAILED,
120
- 'validator-delegations requires validator-address argument'
121
- );
122
- }
123
- const [validatorAddr] = args;
124
- const result = await staking.validatorDelegations({ validatorAddr, pagination: defaultPagination });
113
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking validator-delegations');
114
+ requireArgs(remainingArgs, 1, ['validator-address'], 'staking validator-delegations');
115
+ const [validatorAddr] = remainingArgs;
116
+ const result = await staking.validatorDelegations({ validatorAddr, pagination });
125
117
  return {
126
118
  delegationResponses: result.delegationResponses,
127
119
  pagination: result.pagination,
@@ -129,14 +121,10 @@ export async function routeStakingQuery(
129
121
  }
130
122
 
131
123
  case 'validator-unbonding-delegations': {
132
- if (args.length < 1) {
133
- throw new ManifestMCPError(
134
- ManifestMCPErrorCode.QUERY_FAILED,
135
- 'validator-unbonding-delegations requires validator-address argument'
136
- );
137
- }
138
- const [validatorAddr] = args;
139
- const result = await staking.validatorUnbondingDelegations({ validatorAddr, pagination: defaultPagination });
124
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'staking validator-unbonding-delegations');
125
+ requireArgs(remainingArgs, 1, ['validator-address'], 'staking validator-unbonding-delegations');
126
+ const [validatorAddr] = remainingArgs;
127
+ const result = await staking.validatorUnbondingDelegations({ validatorAddr, pagination });
140
128
  return {
141
129
  unbondingResponses: result.unbondingResponses,
142
130
  pagination: result.pagination,
@@ -154,37 +142,13 @@ export async function routeStakingQuery(
154
142
  }
155
143
 
156
144
  case 'historical-info': {
157
- if (args.length < 1) {
158
- throw new ManifestMCPError(
159
- ManifestMCPErrorCode.QUERY_FAILED,
160
- 'historical-info requires height argument'
161
- );
162
- }
145
+ requireArgs(args, 1, ['height'], 'staking historical-info');
163
146
  const height = parseBigInt(args[0], 'height');
164
147
  const result = await staking.historicalInfo({ height });
165
148
  return { hist: result.hist };
166
149
  }
167
150
 
168
151
  default:
169
- throw new ManifestMCPError(
170
- ManifestMCPErrorCode.UNSUPPORTED_QUERY,
171
- `Unsupported staking query subcommand: ${subcommand}`,
172
- {
173
- availableSubcommands: [
174
- 'delegation',
175
- 'delegations',
176
- 'unbonding-delegation',
177
- 'unbonding-delegations',
178
- 'redelegations',
179
- 'validator',
180
- 'validators',
181
- 'validator-delegations',
182
- 'validator-unbonding-delegations',
183
- 'pool',
184
- 'params',
185
- 'historical-info',
186
- ],
187
- }
188
- );
152
+ throwUnsupportedSubcommand('query', 'staking', subcommand);
189
153
  }
190
154
  }
@@ -1,5 +1,12 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { parseBigInt, parseInt } from './utils.js';
2
+ import {
3
+ parseBigInt,
4
+ parseInteger,
5
+ createPagination,
6
+ extractPaginationArgs,
7
+ DEFAULT_PAGE_LIMIT,
8
+ MAX_PAGE_LIMIT,
9
+ } from './utils.js';
3
10
  import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
4
11
 
5
12
  describe('parseBigInt', () => {
@@ -38,24 +45,112 @@ describe('parseBigInt', () => {
38
45
  });
39
46
  });
40
47
 
41
- describe('parseInt', () => {
48
+ describe('parseInteger', () => {
42
49
  it('should parse valid integer strings', () => {
43
- expect(parseInt('0', 'status')).toBe(0);
44
- expect(parseInt('123', 'status')).toBe(123);
45
- expect(parseInt('-5', 'status')).toBe(-5);
50
+ expect(parseInteger('0', 'status')).toBe(0);
51
+ expect(parseInteger('123', 'status')).toBe(123);
52
+ expect(parseInteger('-5', 'status')).toBe(-5);
46
53
  });
47
54
 
48
55
  it('should throw ManifestMCPError for invalid integers', () => {
49
- expect(() => parseInt('', 'status')).toThrow(ManifestMCPError);
50
- expect(() => parseInt('abc', 'status')).toThrow(ManifestMCPError);
56
+ expect(() => parseInteger('', 'status')).toThrow(ManifestMCPError);
57
+ expect(() => parseInteger('abc', 'status')).toThrow(ManifestMCPError);
51
58
  });
52
59
 
53
60
  it('should have correct error code', () => {
54
61
  try {
55
- parseInt('invalid', 'status');
62
+ parseInteger('invalid', 'status');
56
63
  } catch (error) {
57
64
  expect(error).toBeInstanceOf(ManifestMCPError);
58
65
  expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.QUERY_FAILED);
59
66
  }
60
67
  });
61
68
  });
69
+
70
+ describe('createPagination', () => {
71
+ it('should use default limit when none provided', () => {
72
+ const pagination = createPagination();
73
+ expect(pagination.limit).toBe(DEFAULT_PAGE_LIMIT);
74
+ expect(pagination.offset).toBe(BigInt(0));
75
+ expect(pagination.countTotal).toBe(false);
76
+ expect(pagination.reverse).toBe(false);
77
+ expect(pagination.key).toEqual(new Uint8Array());
78
+ });
79
+
80
+ it('should use provided limit', () => {
81
+ const pagination = createPagination(BigInt(50));
82
+ expect(pagination.limit).toBe(BigInt(50));
83
+ });
84
+
85
+ it('should clamp limit to minimum of 1', () => {
86
+ const pagination = createPagination(BigInt(0));
87
+ expect(pagination.limit).toBe(BigInt(1));
88
+
89
+ const paginationNegative = createPagination(BigInt(-10));
90
+ expect(paginationNegative.limit).toBe(BigInt(1));
91
+ });
92
+
93
+ it('should clamp limit to maximum', () => {
94
+ const pagination = createPagination(BigInt(9999));
95
+ expect(pagination.limit).toBe(MAX_PAGE_LIMIT);
96
+ });
97
+ });
98
+
99
+ describe('extractPaginationArgs', () => {
100
+ it('should return default pagination when no --limit flag', () => {
101
+ const { pagination, remainingArgs } = extractPaginationArgs(['arg1', 'arg2'], 'test');
102
+ expect(pagination.limit).toBe(DEFAULT_PAGE_LIMIT);
103
+ expect(remainingArgs).toEqual(['arg1', 'arg2']);
104
+ });
105
+
106
+ it('should extract --limit flag and value', () => {
107
+ const { pagination, remainingArgs } = extractPaginationArgs(
108
+ ['arg1', '--limit', '50', 'arg2'],
109
+ 'test'
110
+ );
111
+ expect(pagination.limit).toBe(BigInt(50));
112
+ expect(remainingArgs).toEqual(['arg1', 'arg2']);
113
+ });
114
+
115
+ it('should handle --limit at end of args', () => {
116
+ const { pagination, remainingArgs } = extractPaginationArgs(
117
+ ['arg1', '--limit', '25'],
118
+ 'test'
119
+ );
120
+ expect(pagination.limit).toBe(BigInt(25));
121
+ expect(remainingArgs).toEqual(['arg1']);
122
+ });
123
+
124
+ it('should handle --limit at start of args', () => {
125
+ const { pagination, remainingArgs } = extractPaginationArgs(
126
+ ['--limit', '75', 'arg1'],
127
+ 'test'
128
+ );
129
+ expect(pagination.limit).toBe(BigInt(75));
130
+ expect(remainingArgs).toEqual(['arg1']);
131
+ });
132
+
133
+ it('should throw for invalid limit value', () => {
134
+ expect(() =>
135
+ extractPaginationArgs(['--limit', 'abc'], 'test')
136
+ ).toThrow(ManifestMCPError);
137
+ });
138
+
139
+ it('should throw for limit below minimum', () => {
140
+ expect(() =>
141
+ extractPaginationArgs(['--limit', '0'], 'test')
142
+ ).toThrow(ManifestMCPError);
143
+ });
144
+
145
+ it('should throw for limit above maximum', () => {
146
+ expect(() =>
147
+ extractPaginationArgs(['--limit', '9999'], 'test')
148
+ ).toThrow(ManifestMCPError);
149
+ });
150
+
151
+ it('should handle empty args array', () => {
152
+ const { pagination, remainingArgs } = extractPaginationArgs([], 'test');
153
+ expect(pagination.limit).toBe(DEFAULT_PAGE_LIMIT);
154
+ expect(remainingArgs).toEqual([]);
155
+ });
156
+ });
@@ -1,20 +1,86 @@
1
1
  import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
2
- import { parseBigIntWithCode } from '../transactions/utils.js';
2
+ import { parseBigIntWithCode, requireArgs as requireArgsBase, extractFlag, filterConsumedArgs } from '../transactions/utils.js';
3
3
 
4
4
  /** Default page size limit for paginated queries to prevent resource exhaustion */
5
5
  export const DEFAULT_PAGE_LIMIT = BigInt(100);
6
6
 
7
+ /** Maximum page size limit to prevent DoS */
8
+ export const MAX_PAGE_LIMIT = BigInt(1000);
9
+
10
+ /**
11
+ * Cosmos SDK pagination configuration
12
+ */
13
+ export interface PaginationConfig {
14
+ readonly key: Uint8Array;
15
+ readonly offset: bigint;
16
+ readonly limit: bigint;
17
+ readonly countTotal: boolean;
18
+ readonly reverse: boolean;
19
+ }
20
+
21
+ /**
22
+ * Create pagination configuration with optional custom limit.
23
+ * Validates that limit is within acceptable bounds.
24
+ *
25
+ * @param limit - Optional custom limit (defaults to DEFAULT_PAGE_LIMIT)
26
+ * @returns Cosmos SDK pagination object
27
+ */
28
+ export function createPagination(limit?: bigint): PaginationConfig {
29
+ let effectiveLimit = limit ?? DEFAULT_PAGE_LIMIT;
30
+
31
+ // Clamp to valid range
32
+ if (effectiveLimit < BigInt(1)) {
33
+ effectiveLimit = BigInt(1);
34
+ } else if (effectiveLimit > MAX_PAGE_LIMIT) {
35
+ effectiveLimit = MAX_PAGE_LIMIT;
36
+ }
37
+
38
+ return {
39
+ key: new Uint8Array(),
40
+ offset: BigInt(0),
41
+ limit: effectiveLimit,
42
+ countTotal: false,
43
+ reverse: false,
44
+ };
45
+ }
46
+
7
47
  /**
8
- * Default pagination configuration for queries
9
- * Uses Cosmos SDK pagination format
48
+ * Default pagination configuration for queries (for backwards compatibility)
49
+ * @deprecated Use createPagination() instead for configurable limits
10
50
  */
11
- export const defaultPagination = {
12
- key: new Uint8Array(),
13
- offset: BigInt(0),
14
- limit: DEFAULT_PAGE_LIMIT,
15
- countTotal: false,
16
- reverse: false,
17
- };
51
+ export const defaultPagination = createPagination();
52
+
53
+ /**
54
+ * Extract --limit flag from args and return pagination config with remaining args.
55
+ * Use this helper for paginated queries.
56
+ *
57
+ * @param args - The arguments array
58
+ * @param context - Context for error messages
59
+ * @returns Object with pagination config and filtered args
60
+ */
61
+ export function extractPaginationArgs(
62
+ args: string[],
63
+ context: string
64
+ ): { pagination: PaginationConfig; remainingArgs: string[] } {
65
+ const { value: limitStr, consumedIndices } = extractFlag(args, '--limit', context);
66
+ const remainingArgs = filterConsumedArgs(args, consumedIndices);
67
+
68
+ let pagination: PaginationConfig;
69
+ if (limitStr) {
70
+ const limit = parseBigInt(limitStr, 'limit');
71
+ if (limit < BigInt(1) || limit > MAX_PAGE_LIMIT) {
72
+ throw new ManifestMCPError(
73
+ ManifestMCPErrorCode.QUERY_FAILED,
74
+ `Invalid limit: ${limit}. Must be between 1 and ${MAX_PAGE_LIMIT}.`
75
+ );
76
+ }
77
+ pagination = createPagination(limit);
78
+ } else {
79
+ pagination = createPagination();
80
+ }
81
+
82
+ return { pagination, remainingArgs };
83
+ }
18
84
 
19
85
  /**
20
86
  * Safely parse a string to BigInt with proper error handling (for queries)
@@ -24,9 +90,10 @@ export function parseBigInt(value: string, fieldName: string): bigint {
24
90
  }
25
91
 
26
92
  /**
27
- * Safely parse a string to integer with proper error handling
93
+ * Safely parse a string to integer with proper error handling.
94
+ * Named parseInteger to avoid shadowing global parseInt.
28
95
  */
29
- export function parseInt(value: string, fieldName: string): number {
96
+ export function parseInteger(value: string, fieldName: string): number {
30
97
  const parsed = Number.parseInt(value, 10);
31
98
  if (Number.isNaN(parsed)) {
32
99
  throw new ManifestMCPError(
@@ -36,3 +103,16 @@ export function parseInt(value: string, fieldName: string): number {
36
103
  }
37
104
  return parsed;
38
105
  }
106
+
107
+ /**
108
+ * Validate that required arguments are present (for queries).
109
+ * Uses QUERY_FAILED error code by default.
110
+ */
111
+ export function requireArgs(
112
+ args: string[],
113
+ minCount: number,
114
+ expectedNames: string[],
115
+ context: string
116
+ ): void {
117
+ requireArgsBase(args, minCount, expectedNames, context, ManifestMCPErrorCode.QUERY_FAILED);
118
+ }
@@ -1,7 +1,8 @@
1
1
  import { SigningStargateClient } from '@cosmjs/stargate';
2
2
  import { cosmos } from '@manifest-network/manifestjs';
3
- import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult, ManifestMCPConfig } from '../types.js';
4
- import { parseAmount, buildTxResult, validateAddress, validateMemo, validateArgsLength } from './utils.js';
3
+ import { CosmosTxResult } from '../types.js';
4
+ import { throwUnsupportedSubcommand } from '../modules.js';
5
+ import { parseAmount, buildTxResult, validateAddress, validateMemo, validateArgsLength, extractFlag, parseColonPair, requireArgs } from './utils.js';
5
6
 
6
7
  const { MsgSend, MsgMultiSend } = cosmos.bank.v1beta1;
7
8
 
@@ -13,29 +14,20 @@ export async function routeBankTransaction(
13
14
  senderAddress: string,
14
15
  subcommand: string,
15
16
  args: string[],
16
- _config: ManifestMCPConfig,
17
17
  waitForConfirmation: boolean
18
18
  ): Promise<CosmosTxResult> {
19
19
  validateArgsLength(args, 'bank transaction');
20
20
 
21
21
  switch (subcommand) {
22
22
  case 'send': {
23
- if (args.length < 2) {
24
- throw new ManifestMCPError(
25
- ManifestMCPErrorCode.TX_FAILED,
26
- 'send requires recipient-address and amount arguments'
27
- );
28
- }
29
-
23
+ requireArgs(args, 2, ['recipient-address', 'amount'], 'bank send');
30
24
  const [recipientAddress, amountStr] = args;
31
25
  validateAddress(recipientAddress, 'recipient address');
32
26
  const { amount, denom } = parseAmount(amountStr);
33
27
 
34
28
  // Extract optional memo from args
35
- let memo = '';
36
- const memoIndex = args.indexOf('--memo');
37
- if (memoIndex !== -1 && args[memoIndex + 1]) {
38
- memo = args[memoIndex + 1];
29
+ const { value: memo = '' } = extractFlag(args, '--memo', 'bank send');
30
+ if (memo) {
39
31
  validateMemo(memo);
40
32
  }
41
33
 
@@ -53,22 +45,10 @@ export async function routeBankTransaction(
53
45
  }
54
46
 
55
47
  case 'multi-send': {
56
- if (args.length < 2) {
57
- throw new ManifestMCPError(
58
- ManifestMCPErrorCode.TX_FAILED,
59
- 'multi-send requires at least one recipient:amount pair'
60
- );
61
- }
62
-
48
+ requireArgs(args, 1, ['recipient:amount'], 'bank multi-send');
63
49
  // Parse format: multi-send recipient1:amount1 recipient2:amount2 ...
64
50
  const outputs = args.map((arg) => {
65
- const [address, amountStr] = arg.split(':');
66
- if (!address || !amountStr) {
67
- throw new ManifestMCPError(
68
- ManifestMCPErrorCode.TX_FAILED,
69
- `Invalid multi-send format: ${arg}. Expected format: address:amount`
70
- );
71
- }
51
+ const [address, amountStr] = parseColonPair(arg, 'address', 'amount', 'multi-send');
72
52
  validateAddress(address, 'recipient address');
73
53
  const { amount, denom } = parseAmount(amountStr);
74
54
  return { address, coins: [{ denom, amount }] };
@@ -101,10 +81,6 @@ export async function routeBankTransaction(
101
81
  }
102
82
 
103
83
  default:
104
- throw new ManifestMCPError(
105
- ManifestMCPErrorCode.UNSUPPORTED_TX,
106
- `Unsupported bank transaction subcommand: ${subcommand}`,
107
- { availableSubcommands: ['send', 'multi-send'] }
108
- );
84
+ throwUnsupportedSubcommand('tx', 'bank', subcommand);
109
85
  }
110
86
  }