@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,15 +1,34 @@
1
1
  import { ManifestQueryClient } from '../client.js';
2
- import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
3
- import { parseBigInt, defaultPagination } from './utils.js';
2
+ import {
3
+ BillingParamsResult, LeaseResult, LeasesResult, CreditAccountResult,
4
+ CreditAccountsResult, CreditAddressResult, WithdrawableAmountResult,
5
+ ProviderWithdrawableResult, CreditEstimateResult
6
+ } from '../types.js';
7
+ import { parseBigInt, requireArgs, extractPaginationArgs } from './utils.js';
8
+ import { throwUnsupportedSubcommand } from '../modules.js';
9
+
10
+ /** Billing query result union type */
11
+ type BillingQueryResult =
12
+ | BillingParamsResult
13
+ | LeaseResult
14
+ | LeasesResult
15
+ | CreditAccountResult
16
+ | CreditAccountsResult
17
+ | CreditAddressResult
18
+ | WithdrawableAmountResult
19
+ | ProviderWithdrawableResult
20
+ | CreditEstimateResult;
4
21
 
5
22
  /**
6
23
  * Route billing module query to manifestjs query client
24
+ *
25
+ * Paginated queries support --limit flag (default: 100, max: 1000)
7
26
  */
8
27
  export async function routeBillingQuery(
9
28
  queryClient: ManifestQueryClient,
10
29
  subcommand: string,
11
30
  args: string[]
12
- ): Promise<Record<string, unknown>> {
31
+ ): Promise<BillingQueryResult> {
13
32
  const billing = queryClient.liftedinit.billing.v1;
14
33
 
15
34
  switch (subcommand) {
@@ -19,146 +38,87 @@ export async function routeBillingQuery(
19
38
  }
20
39
 
21
40
  case 'lease': {
22
- if (args.length < 1) {
23
- throw new ManifestMCPError(
24
- ManifestMCPErrorCode.QUERY_FAILED,
25
- 'lease requires lease-uuid argument'
26
- );
27
- }
41
+ requireArgs(args, 1, ['lease-uuid'], 'billing lease');
28
42
  const [leaseUuid] = args;
29
43
  const result = await billing.lease({ leaseUuid });
30
44
  return { lease: result.lease };
31
45
  }
32
46
 
33
47
  case 'leases': {
48
+ const { pagination } = extractPaginationArgs(args, 'billing leases');
34
49
  // stateFilter: 0 = LEASE_STATE_UNSPECIFIED (returns all)
35
- const result = await billing.leases({ stateFilter: 0, pagination: defaultPagination });
50
+ const result = await billing.leases({ stateFilter: 0, pagination });
36
51
  return { leases: result.leases, pagination: result.pagination };
37
52
  }
38
53
 
39
54
  case 'leases-by-tenant': {
40
- if (args.length < 1) {
41
- throw new ManifestMCPError(
42
- ManifestMCPErrorCode.QUERY_FAILED,
43
- 'leases-by-tenant requires tenant-address argument'
44
- );
45
- }
46
- const [tenant] = args;
47
- const result = await billing.leasesByTenant({ tenant, stateFilter: 0, pagination: defaultPagination });
55
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'billing leases-by-tenant');
56
+ requireArgs(remainingArgs, 1, ['tenant-address'], 'billing leases-by-tenant');
57
+ const [tenant] = remainingArgs;
58
+ const result = await billing.leasesByTenant({ tenant, stateFilter: 0, pagination });
48
59
  return { leases: result.leases, pagination: result.pagination };
49
60
  }
50
61
 
51
62
  case 'leases-by-provider': {
52
- if (args.length < 1) {
53
- throw new ManifestMCPError(
54
- ManifestMCPErrorCode.QUERY_FAILED,
55
- 'leases-by-provider requires provider-uuid argument'
56
- );
57
- }
58
- const [providerUuid] = args;
59
- const result = await billing.leasesByProvider({ providerUuid, stateFilter: 0, pagination: defaultPagination });
63
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'billing leases-by-provider');
64
+ requireArgs(remainingArgs, 1, ['provider-uuid'], 'billing leases-by-provider');
65
+ const [providerUuid] = remainingArgs;
66
+ const result = await billing.leasesByProvider({ providerUuid, stateFilter: 0, pagination });
60
67
  return { leases: result.leases, pagination: result.pagination };
61
68
  }
62
69
 
63
70
  case 'leases-by-sku': {
64
- if (args.length < 1) {
65
- throw new ManifestMCPError(
66
- ManifestMCPErrorCode.QUERY_FAILED,
67
- 'leases-by-sku requires sku-uuid argument'
68
- );
69
- }
70
- const [skuUuid] = args;
71
- const result = await billing.leasesBySKU({ skuUuid, stateFilter: 0, pagination: defaultPagination });
71
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'billing leases-by-sku');
72
+ requireArgs(remainingArgs, 1, ['sku-uuid'], 'billing leases-by-sku');
73
+ const [skuUuid] = remainingArgs;
74
+ const result = await billing.leasesBySKU({ skuUuid, stateFilter: 0, pagination });
72
75
  return { leases: result.leases, pagination: result.pagination };
73
76
  }
74
77
 
75
78
  case 'credit-account': {
76
- if (args.length < 1) {
77
- throw new ManifestMCPError(
78
- ManifestMCPErrorCode.QUERY_FAILED,
79
- 'credit-account requires tenant-address argument'
80
- );
81
- }
79
+ requireArgs(args, 1, ['tenant-address'], 'billing credit-account');
82
80
  const [tenant] = args;
83
81
  const result = await billing.creditAccount({ tenant });
84
82
  return { creditAccount: result.creditAccount };
85
83
  }
86
84
 
87
85
  case 'credit-accounts': {
88
- const result = await billing.creditAccounts({ pagination: defaultPagination });
86
+ const { pagination } = extractPaginationArgs(args, 'billing credit-accounts');
87
+ const result = await billing.creditAccounts({ pagination });
89
88
  return { creditAccounts: result.creditAccounts, pagination: result.pagination };
90
89
  }
91
90
 
92
91
  case 'credit-address': {
93
- if (args.length < 1) {
94
- throw new ManifestMCPError(
95
- ManifestMCPErrorCode.QUERY_FAILED,
96
- 'credit-address requires tenant-address argument'
97
- );
98
- }
92
+ requireArgs(args, 1, ['tenant-address'], 'billing credit-address');
99
93
  const [tenant] = args;
100
94
  const result = await billing.creditAddress({ tenant });
101
95
  return { creditAddress: result.creditAddress };
102
96
  }
103
97
 
104
98
  case 'withdrawable-amount': {
105
- if (args.length < 1) {
106
- throw new ManifestMCPError(
107
- ManifestMCPErrorCode.QUERY_FAILED,
108
- 'withdrawable-amount requires lease-uuid argument'
109
- );
110
- }
99
+ requireArgs(args, 1, ['lease-uuid'], 'billing withdrawable-amount');
111
100
  const [leaseUuid] = args;
112
101
  const result = await billing.withdrawableAmount({ leaseUuid });
113
102
  return { amounts: result.amounts };
114
103
  }
115
104
 
116
105
  case 'provider-withdrawable': {
117
- if (args.length < 1) {
118
- throw new ManifestMCPError(
119
- ManifestMCPErrorCode.QUERY_FAILED,
120
- 'provider-withdrawable requires provider-uuid argument'
121
- );
122
- }
106
+ requireArgs(args, 1, ['provider-uuid'], 'billing provider-withdrawable');
123
107
  const [providerUuid] = args;
124
- // limit: max leases to process (default 100, max 1000)
108
+ // Optional: limit for max leases to process (default 100, max 1000)
125
109
  const limit = args[1] ? parseBigInt(args[1], 'limit') : BigInt(100);
126
110
  const result = await billing.providerWithdrawable({ providerUuid, limit });
127
111
  return { amounts: result.amounts };
128
112
  }
129
113
 
130
114
  case 'credit-estimate': {
131
- if (args.length < 1) {
132
- throw new ManifestMCPError(
133
- ManifestMCPErrorCode.QUERY_FAILED,
134
- 'credit-estimate requires tenant-address argument'
135
- );
136
- }
115
+ requireArgs(args, 1, ['tenant-address'], 'billing credit-estimate');
137
116
  const [tenant] = args;
138
117
  const result = await billing.creditEstimate({ tenant });
139
118
  return { estimate: result };
140
119
  }
141
120
 
142
121
  default:
143
- throw new ManifestMCPError(
144
- ManifestMCPErrorCode.UNSUPPORTED_QUERY,
145
- `Unsupported billing query subcommand: ${subcommand}`,
146
- {
147
- availableSubcommands: [
148
- 'params',
149
- 'lease',
150
- 'leases',
151
- 'leases-by-tenant',
152
- 'leases-by-provider',
153
- 'leases-by-sku',
154
- 'credit-account',
155
- 'credit-accounts',
156
- 'credit-address',
157
- 'withdrawable-amount',
158
- 'provider-withdrawable',
159
- 'credit-estimate',
160
- ],
161
- }
162
- );
122
+ throwUnsupportedSubcommand('query', 'billing', subcommand);
163
123
  }
164
124
  }
@@ -1,26 +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
+ RewardsResult, CommissionResult, CommunityPoolResult, DistributionParamsResult,
4
+ ValidatorOutstandingRewardsResult, SlashesResult, DelegatorValidatorsResult,
5
+ DelegatorWithdrawAddressResult
6
+ } from '../types.js';
7
+ import { parseBigInt, requireArgs, extractPaginationArgs } from './utils.js';
8
+ import { throwUnsupportedSubcommand } from '../modules.js';
9
+
10
+ /** Distribution query result union type */
11
+ type DistributionQueryResult =
12
+ | RewardsResult
13
+ | CommissionResult
14
+ | CommunityPoolResult
15
+ | DistributionParamsResult
16
+ | ValidatorOutstandingRewardsResult
17
+ | SlashesResult
18
+ | DelegatorValidatorsResult
19
+ | DelegatorWithdrawAddressResult;
4
20
 
5
21
  /**
6
22
  * Route distribution query to manifestjs query client
23
+ *
24
+ * Paginated queries support --limit flag (default: 100, max: 1000)
7
25
  */
8
26
  export async function routeDistributionQuery(
9
27
  queryClient: ManifestQueryClient,
10
28
  subcommand: string,
11
29
  args: string[]
12
- ): Promise<Record<string, unknown>> {
30
+ ): Promise<DistributionQueryResult> {
13
31
  const distribution = queryClient.cosmos.distribution.v1beta1;
14
32
 
15
33
  switch (subcommand) {
16
34
  case 'rewards': {
17
- if (args.length < 1) {
18
- throw new ManifestMCPError(
19
- ManifestMCPErrorCode.QUERY_FAILED,
20
- 'rewards requires delegator-address argument'
21
- );
22
- }
35
+ requireArgs(args, 1, ['delegator-address'], 'distribution rewards');
23
36
  const [delegatorAddress] = args;
37
+ // Optional: validator address for specific validator rewards
24
38
  const validatorAddress = args[1];
25
39
 
26
40
  if (validatorAddress) {
@@ -41,12 +55,7 @@ export async function routeDistributionQuery(
41
55
  }
42
56
 
43
57
  case 'commission': {
44
- if (args.length < 1) {
45
- throw new ManifestMCPError(
46
- ManifestMCPErrorCode.QUERY_FAILED,
47
- 'commission requires validator-address argument'
48
- );
49
- }
58
+ requireArgs(args, 1, ['validator-address'], 'distribution commission');
50
59
  const [validatorAddress] = args;
51
60
  const result = await distribution.validatorCommission({ validatorAddress });
52
61
  return { commission: result.commission };
@@ -63,76 +72,43 @@ export async function routeDistributionQuery(
63
72
  }
64
73
 
65
74
  case 'validator-outstanding-rewards': {
66
- if (args.length < 1) {
67
- throw new ManifestMCPError(
68
- ManifestMCPErrorCode.QUERY_FAILED,
69
- 'validator-outstanding-rewards requires validator-address argument'
70
- );
71
- }
75
+ requireArgs(args, 1, ['validator-address'], 'distribution validator-outstanding-rewards');
72
76
  const [validatorAddress] = args;
73
77
  const result = await distribution.validatorOutstandingRewards({ validatorAddress });
74
78
  return { rewards: result.rewards };
75
79
  }
76
80
 
77
81
  case 'slashes': {
78
- if (args.length < 1) {
79
- throw new ManifestMCPError(
80
- ManifestMCPErrorCode.QUERY_FAILED,
81
- 'slashes requires validator-address argument'
82
- );
83
- }
84
- const [validatorAddress] = args;
85
- const startingHeight = args[1] ? parseBigInt(args[1], 'starting-height') : BigInt(0);
86
- const endingHeight = args[2] ? parseBigInt(args[2], 'ending-height') : BigInt(Number.MAX_SAFE_INTEGER);
82
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'distribution slashes');
83
+ requireArgs(remainingArgs, 1, ['validator-address'], 'distribution slashes');
84
+ const [validatorAddress] = remainingArgs;
85
+ // Optional: starting and ending height for filtering
86
+ const startingHeight = remainingArgs[1] ? parseBigInt(remainingArgs[1], 'starting-height') : BigInt(0);
87
+ const endingHeight = remainingArgs[2] ? parseBigInt(remainingArgs[2], 'ending-height') : BigInt(Number.MAX_SAFE_INTEGER);
87
88
  const result = await distribution.validatorSlashes({
88
89
  validatorAddress,
89
90
  startingHeight,
90
91
  endingHeight,
91
- pagination: defaultPagination,
92
+ pagination,
92
93
  });
93
94
  return { slashes: result.slashes, pagination: result.pagination };
94
95
  }
95
96
 
96
97
  case 'delegator-validators': {
97
- if (args.length < 1) {
98
- throw new ManifestMCPError(
99
- ManifestMCPErrorCode.QUERY_FAILED,
100
- 'delegator-validators requires delegator-address argument'
101
- );
102
- }
98
+ requireArgs(args, 1, ['delegator-address'], 'distribution delegator-validators');
103
99
  const [delegatorAddress] = args;
104
100
  const result = await distribution.delegatorValidators({ delegatorAddress });
105
101
  return { validators: result.validators };
106
102
  }
107
103
 
108
104
  case 'delegator-withdraw-address': {
109
- if (args.length < 1) {
110
- throw new ManifestMCPError(
111
- ManifestMCPErrorCode.QUERY_FAILED,
112
- 'delegator-withdraw-address requires delegator-address argument'
113
- );
114
- }
105
+ requireArgs(args, 1, ['delegator-address'], 'distribution delegator-withdraw-address');
115
106
  const [delegatorAddress] = args;
116
107
  const result = await distribution.delegatorWithdrawAddress({ delegatorAddress });
117
108
  return { withdrawAddress: result.withdrawAddress };
118
109
  }
119
110
 
120
111
  default:
121
- throw new ManifestMCPError(
122
- ManifestMCPErrorCode.UNSUPPORTED_QUERY,
123
- `Unsupported distribution query subcommand: ${subcommand}`,
124
- {
125
- availableSubcommands: [
126
- 'rewards',
127
- 'commission',
128
- 'community-pool',
129
- 'params',
130
- 'validator-outstanding-rewards',
131
- 'slashes',
132
- 'delegator-validators',
133
- 'delegator-withdraw-address',
134
- ],
135
- }
136
- );
112
+ throwUnsupportedSubcommand('query', 'distribution', subcommand);
137
113
  }
138
114
  }
@@ -1,46 +1,54 @@
1
1
  import { ManifestQueryClient } from '../client.js';
2
- import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
3
- import { parseBigInt, parseInt, defaultPagination } from './utils.js';
2
+ import {
3
+ ProposalResult, ProposalsResult, VoteResult, VotesResult,
4
+ DepositResult, DepositsResult, TallyResult, GovParamsResult
5
+ } from '../types.js';
6
+ import { parseBigInt, parseInteger, requireArgs, extractPaginationArgs } from './utils.js';
7
+ import { throwUnsupportedSubcommand } from '../modules.js';
8
+
9
+ /** Gov query result union type */
10
+ type GovQueryResult =
11
+ | ProposalResult
12
+ | ProposalsResult
13
+ | VoteResult
14
+ | VotesResult
15
+ | DepositResult
16
+ | DepositsResult
17
+ | TallyResult
18
+ | GovParamsResult;
4
19
 
5
20
  /**
6
21
  * Route gov query to manifestjs query client
22
+ *
23
+ * Paginated queries support --limit flag (default: 100, max: 1000)
7
24
  */
8
25
  export async function routeGovQuery(
9
26
  queryClient: ManifestQueryClient,
10
27
  subcommand: string,
11
28
  args: string[]
12
- ): Promise<Record<string, unknown>> {
29
+ ): Promise<GovQueryResult> {
13
30
  const gov = queryClient.cosmos.gov.v1;
14
31
 
15
32
  switch (subcommand) {
16
33
  case 'proposal': {
17
- if (args.length < 1) {
18
- throw new ManifestMCPError(
19
- ManifestMCPErrorCode.QUERY_FAILED,
20
- 'proposal requires proposal-id argument'
21
- );
22
- }
34
+ requireArgs(args, 1, ['proposal-id'], 'gov proposal');
23
35
  const proposalId = parseBigInt(args[0], 'proposal-id');
24
36
  const result = await gov.proposal({ proposalId });
25
37
  return { proposal: result.proposal };
26
38
  }
27
39
 
28
40
  case 'proposals': {
29
- // Parse optional status filter
30
- const proposalStatus = args[0] ? parseInt(args[0], 'status') : 0;
31
- const voter = args[1] || '';
32
- const depositor = args[2] || '';
33
- const result = await gov.proposals({ proposalStatus, voter, depositor, pagination: defaultPagination });
41
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'gov proposals');
42
+ // All optional: status filter, voter, depositor
43
+ const proposalStatus = remainingArgs[0] ? parseInteger(remainingArgs[0], 'status') : 0;
44
+ const voter = remainingArgs[1] || '';
45
+ const depositor = remainingArgs[2] || '';
46
+ const result = await gov.proposals({ proposalStatus, voter, depositor, pagination });
34
47
  return { proposals: result.proposals, pagination: result.pagination };
35
48
  }
36
49
 
37
50
  case 'vote': {
38
- if (args.length < 2) {
39
- throw new ManifestMCPError(
40
- ManifestMCPErrorCode.QUERY_FAILED,
41
- 'vote requires proposal-id and voter-address arguments'
42
- );
43
- }
51
+ requireArgs(args, 2, ['proposal-id', 'voter-address'], 'gov vote');
44
52
  const proposalId = parseBigInt(args[0], 'proposal-id');
45
53
  const voter = args[1];
46
54
  const result = await gov.vote({ proposalId, voter });
@@ -48,24 +56,15 @@ export async function routeGovQuery(
48
56
  }
49
57
 
50
58
  case 'votes': {
51
- if (args.length < 1) {
52
- throw new ManifestMCPError(
53
- ManifestMCPErrorCode.QUERY_FAILED,
54
- 'votes requires proposal-id argument'
55
- );
56
- }
57
- const proposalId = parseBigInt(args[0], 'proposal-id');
58
- const result = await gov.votes({ proposalId, pagination: defaultPagination });
59
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'gov votes');
60
+ requireArgs(remainingArgs, 1, ['proposal-id'], 'gov votes');
61
+ const proposalId = parseBigInt(remainingArgs[0], 'proposal-id');
62
+ const result = await gov.votes({ proposalId, pagination });
59
63
  return { votes: result.votes, pagination: result.pagination };
60
64
  }
61
65
 
62
66
  case 'deposit': {
63
- if (args.length < 2) {
64
- throw new ManifestMCPError(
65
- ManifestMCPErrorCode.QUERY_FAILED,
66
- 'deposit requires proposal-id and depositor-address arguments'
67
- );
68
- }
67
+ requireArgs(args, 2, ['proposal-id', 'depositor-address'], 'gov deposit');
69
68
  const proposalId = parseBigInt(args[0], 'proposal-id');
70
69
  const depositor = args[1];
71
70
  const result = await gov.deposit({ proposalId, depositor });
@@ -73,30 +72,22 @@ export async function routeGovQuery(
73
72
  }
74
73
 
75
74
  case 'deposits': {
76
- if (args.length < 1) {
77
- throw new ManifestMCPError(
78
- ManifestMCPErrorCode.QUERY_FAILED,
79
- 'deposits requires proposal-id argument'
80
- );
81
- }
82
- const proposalId = parseBigInt(args[0], 'proposal-id');
83
- const result = await gov.deposits({ proposalId, pagination: defaultPagination });
75
+ const { pagination, remainingArgs } = extractPaginationArgs(args, 'gov deposits');
76
+ requireArgs(remainingArgs, 1, ['proposal-id'], 'gov deposits');
77
+ const proposalId = parseBigInt(remainingArgs[0], 'proposal-id');
78
+ const result = await gov.deposits({ proposalId, pagination });
84
79
  return { deposits: result.deposits, pagination: result.pagination };
85
80
  }
86
81
 
87
82
  case 'tally': {
88
- if (args.length < 1) {
89
- throw new ManifestMCPError(
90
- ManifestMCPErrorCode.QUERY_FAILED,
91
- 'tally requires proposal-id argument'
92
- );
93
- }
83
+ requireArgs(args, 1, ['proposal-id'], 'gov tally');
94
84
  const proposalId = parseBigInt(args[0], 'proposal-id');
95
85
  const result = await gov.tallyResult({ proposalId });
96
86
  return { tally: result.tally };
97
87
  }
98
88
 
99
89
  case 'params': {
90
+ // Optional: params type (defaults to 'tallying')
100
91
  const paramsType = args[0] || 'tallying';
101
92
  const result = await gov.params({ paramsType });
102
93
  return {
@@ -108,21 +99,6 @@ export async function routeGovQuery(
108
99
  }
109
100
 
110
101
  default:
111
- throw new ManifestMCPError(
112
- ManifestMCPErrorCode.UNSUPPORTED_QUERY,
113
- `Unsupported gov query subcommand: ${subcommand}`,
114
- {
115
- availableSubcommands: [
116
- 'proposal',
117
- 'proposals',
118
- 'vote',
119
- 'votes',
120
- 'deposit',
121
- 'deposits',
122
- 'tally',
123
- 'params',
124
- ],
125
- }
126
- );
102
+ throwUnsupportedSubcommand('query', 'gov', subcommand);
127
103
  }
128
104
  }
@@ -1,4 +1,13 @@
1
- export { parseBigInt, parseInt, defaultPagination, DEFAULT_PAGE_LIMIT } from './utils.js';
1
+ export {
2
+ parseBigInt,
3
+ parseInteger,
4
+ createPagination,
5
+ extractPaginationArgs,
6
+ DEFAULT_PAGE_LIMIT,
7
+ MAX_PAGE_LIMIT,
8
+ defaultPagination,
9
+ } from './utils.js';
10
+ export type { PaginationConfig } from './utils.js';
2
11
  export { routeBankQuery } from './bank.js';
3
12
  export { routeStakingQuery } from './staking.js';
4
13
  export { routeDistributionQuery } from './distribution.js';