@manifest-network/manifest-mcp-browser 0.1.0 → 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 (137) hide show
  1. package/.github/workflows/publish.yml +4 -2
  2. package/CLAUDE.md +9 -3
  3. package/README.md +6 -1
  4. package/dist/client.d.ts +13 -1
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/client.js +105 -9
  7. package/dist/client.js.map +1 -1
  8. package/dist/config.d.ts +4 -0
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/config.js +52 -7
  11. package/dist/config.js.map +1 -1
  12. package/dist/config.test.js +128 -0
  13. package/dist/config.test.js.map +1 -1
  14. package/dist/cosmos.d.ts.map +1 -1
  15. package/dist/cosmos.js +11 -57
  16. package/dist/cosmos.js.map +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +16 -25
  19. package/dist/index.js.map +1 -1
  20. package/dist/modules.d.ts +30 -1
  21. package/dist/modules.d.ts.map +1 -1
  22. package/dist/modules.js +67 -3
  23. package/dist/modules.js.map +1 -1
  24. package/dist/modules.test.js +58 -1
  25. package/dist/modules.test.js.map +1 -1
  26. package/dist/queries/auth.d.ts +7 -1
  27. package/dist/queries/auth.d.ts.map +1 -1
  28. package/dist/queries/auth.js +18 -45
  29. package/dist/queries/auth.js.map +1 -1
  30. package/dist/queries/bank.d.ts +7 -1
  31. package/dist/queries/bank.d.ts.map +1 -1
  32. package/dist/queries/bank.js +24 -38
  33. package/dist/queries/bank.js.map +1 -1
  34. package/dist/queries/billing.d.ts +7 -1
  35. package/dist/queries/billing.d.ts.map +1 -1
  36. package/dist/queries/billing.js +28 -54
  37. package/dist/queries/billing.js.map +1 -1
  38. package/dist/queries/distribution.d.ts +7 -1
  39. package/dist/queries/distribution.d.ts.map +1 -1
  40. package/dist/queries/distribution.js +18 -36
  41. package/dist/queries/distribution.js.map +1 -1
  42. package/dist/queries/gov.d.ts +7 -1
  43. package/dist/queries/gov.d.ts.map +1 -1
  44. package/dist/queries/gov.js +24 -41
  45. package/dist/queries/gov.js.map +1 -1
  46. package/dist/queries/index.d.ts +2 -1
  47. package/dist/queries/index.d.ts.map +1 -1
  48. package/dist/queries/index.js +1 -1
  49. package/dist/queries/index.js.map +1 -1
  50. package/dist/queries/staking.d.ts +7 -1
  51. package/dist/queries/staking.d.ts.map +1 -1
  52. package/dist/queries/staking.js +36 -59
  53. package/dist/queries/staking.js.map +1 -1
  54. package/dist/queries/utils.d.ts +42 -10
  55. package/dist/queries/utils.d.ts.map +1 -1
  56. package/dist/queries/utils.js +64 -12
  57. package/dist/queries/utils.js.map +1 -1
  58. package/dist/queries/utils.test.js +68 -8
  59. package/dist/queries/utils.test.js.map +1 -1
  60. package/dist/transactions/bank.d.ts +2 -2
  61. package/dist/transactions/bank.d.ts.map +1 -1
  62. package/dist/transactions/bank.js +9 -18
  63. package/dist/transactions/bank.js.map +1 -1
  64. package/dist/transactions/billing.d.ts +2 -2
  65. package/dist/transactions/billing.d.ts.map +1 -1
  66. package/dist/transactions/billing.js +52 -34
  67. package/dist/transactions/billing.js.map +1 -1
  68. package/dist/transactions/distribution.d.ts +2 -2
  69. package/dist/transactions/distribution.d.ts.map +1 -1
  70. package/dist/transactions/distribution.js +7 -13
  71. package/dist/transactions/distribution.js.map +1 -1
  72. package/dist/transactions/gov.d.ts +2 -2
  73. package/dist/transactions/gov.d.ts.map +1 -1
  74. package/dist/transactions/gov.js +32 -17
  75. package/dist/transactions/gov.js.map +1 -1
  76. package/dist/transactions/index.d.ts +1 -1
  77. package/dist/transactions/index.d.ts.map +1 -1
  78. package/dist/transactions/index.js +1 -1
  79. package/dist/transactions/index.js.map +1 -1
  80. package/dist/transactions/manifest.d.ts +2 -2
  81. package/dist/transactions/manifest.d.ts.map +1 -1
  82. package/dist/transactions/manifest.js +7 -14
  83. package/dist/transactions/manifest.js.map +1 -1
  84. package/dist/transactions/staking.d.ts +2 -2
  85. package/dist/transactions/staking.d.ts.map +1 -1
  86. package/dist/transactions/staking.js +7 -13
  87. package/dist/transactions/staking.js.map +1 -1
  88. package/dist/transactions/utils.d.ts +63 -1
  89. package/dist/transactions/utils.d.ts.map +1 -1
  90. package/dist/transactions/utils.js +121 -2
  91. package/dist/transactions/utils.js.map +1 -1
  92. package/dist/transactions/utils.test.js +351 -1
  93. package/dist/transactions/utils.test.js.map +1 -1
  94. package/dist/types.d.ts +212 -8
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/types.js.map +1 -1
  97. package/dist/wallet/mnemonic.d.ts +1 -0
  98. package/dist/wallet/mnemonic.d.ts.map +1 -1
  99. package/dist/wallet/mnemonic.js +34 -13
  100. package/dist/wallet/mnemonic.js.map +1 -1
  101. package/package.json +11 -6
  102. package/src/client.ts +119 -9
  103. package/src/config.test.ts +156 -0
  104. package/src/config.ts +59 -7
  105. package/src/cosmos.ts +19 -109
  106. package/src/index.ts +17 -23
  107. package/src/modules.test.ts +60 -0
  108. package/src/modules.ts +124 -7
  109. package/src/queries/auth.ts +35 -74
  110. package/src/queries/bank.ts +40 -58
  111. package/src/queries/billing.ts +46 -86
  112. package/src/queries/distribution.ts +35 -59
  113. package/src/queries/gov.ts +40 -64
  114. package/src/queries/index.ts +10 -1
  115. package/src/queries/staking.ts +55 -91
  116. package/src/queries/utils.test.ts +103 -8
  117. package/src/queries/utils.ts +92 -12
  118. package/src/transactions/bank.ts +9 -33
  119. package/src/transactions/billing.ts +64 -59
  120. package/src/transactions/distribution.ts +7 -29
  121. package/src/transactions/gov.ts +40 -34
  122. package/src/transactions/index.ts +1 -1
  123. package/src/transactions/manifest.ts +7 -29
  124. package/src/transactions/staking.ts +7 -29
  125. package/src/transactions/utils.test.ts +390 -1
  126. package/src/transactions/utils.ts +191 -2
  127. package/src/types.ts +328 -9
  128. package/src/wallet/mnemonic.ts +41 -17
  129. package/.claude/settings.local.json +0 -17
  130. package/dist/browser.d.ts.map +0 -1
  131. package/dist/browser.js.map +0 -1
  132. package/dist/queries/manifest.d.ts +0 -10
  133. package/dist/queries/manifest.d.ts.map +0 -1
  134. package/dist/queries/manifest.js +0 -14
  135. package/dist/queries/manifest.js.map +0 -1
  136. package/dist/wallet/keplr.d.ts.map +0 -1
  137. package/dist/wallet/keplr.js.map +0 -1
@@ -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
  }
@@ -1,11 +1,14 @@
1
1
  import { SigningStargateClient } from '@cosmjs/stargate';
2
2
  import { liftedinit } from '@manifest-network/manifestjs';
3
- import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult, ManifestMCPConfig } from '../types.js';
4
- import { parseAmount, buildTxResult, parseBigInt, validateAddress, validateArgsLength } from './utils.js';
5
- import { getSubcommandUsage } from '../modules.js';
3
+ import { CosmosTxResult, ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
4
+ import { parseAmount, buildTxResult, parseBigInt, validateAddress, validateArgsLength, extractFlag, filterConsumedArgs, parseColonPair, requireArgs, parseHexBytes } from './utils.js';
5
+ import { getSubcommandUsage, throwUnsupportedSubcommand } from '../modules.js';
6
6
 
7
7
  const { MsgFundCredit, MsgCreateLease, MsgCloseLease, MsgWithdraw } = liftedinit.billing.v1;
8
8
 
9
+ /** Maximum meta hash length in bytes (64 bytes for SHA-512) */
10
+ const MAX_META_HASH_BYTES = 64;
11
+
9
12
  /**
10
13
  * Route billing transaction to appropriate handler
11
14
  */
@@ -14,22 +17,13 @@ export async function routeBillingTransaction(
14
17
  senderAddress: string,
15
18
  subcommand: string,
16
19
  args: string[],
17
- _config: ManifestMCPConfig,
18
20
  waitForConfirmation: boolean
19
21
  ): Promise<CosmosTxResult> {
20
22
  validateArgsLength(args, 'billing transaction');
21
23
 
22
24
  switch (subcommand) {
23
25
  case 'fund-credit': {
24
- if (args.length < 2) {
25
- const usage = getSubcommandUsage('tx', 'billing', 'fund-credit');
26
- throw new ManifestMCPError(
27
- ManifestMCPErrorCode.TX_FAILED,
28
- `fund-credit requires tenant-address and amount arguments. Received ${args.length} argument(s): [${args.map(a => `"${a}"`).join(', ')}]. Usage: fund-credit ${usage || '<tenant-address> <amount>'}`,
29
- { receivedArgs: args, expectedArgs: ['tenant-address', 'amount'], usage }
30
- );
31
- }
32
-
26
+ requireArgs(args, 2, ['tenant-address', 'amount'], 'billing fund-credit');
33
27
  const [tenant, amountStr] = args;
34
28
  validateAddress(tenant, 'tenant address');
35
29
  const { amount, denom } = parseAmount(amountStr);
@@ -48,24 +42,17 @@ export async function routeBillingTransaction(
48
42
  }
49
43
 
50
44
  case 'create-lease': {
51
- if (args.length < 1) {
52
- const usage = getSubcommandUsage('tx', 'billing', 'create-lease');
53
- throw new ManifestMCPError(
54
- ManifestMCPErrorCode.TX_FAILED,
55
- `create-lease requires at least one sku-uuid:quantity pair. Usage: create-lease ${usage || '<sku-uuid:quantity>...'}`,
56
- { usage }
57
- );
58
- }
45
+ // Parse optional --meta-hash flag (can appear anywhere in args)
46
+ const { value: metaHashHex, consumedIndices } = extractFlag(args, '--meta-hash', 'billing create-lease');
47
+ const metaHash = metaHashHex ? parseHexBytes(metaHashHex, 'meta-hash', MAX_META_HASH_BYTES) : undefined;
48
+
49
+ // Filter out --meta-hash and its value to get item args
50
+ const itemArgs = filterConsumedArgs(args, consumedIndices);
51
+ requireArgs(itemArgs, 1, ['sku-uuid:quantity'], 'billing create-lease');
59
52
 
60
53
  // Parse items (format: sku-uuid:quantity ...)
61
- const items = args.map((arg) => {
62
- const [skuUuid, quantityStr] = arg.split(':');
63
- if (!skuUuid || !quantityStr) {
64
- throw new ManifestMCPError(
65
- ManifestMCPErrorCode.TX_FAILED,
66
- `Invalid lease item format: ${arg}. Expected format: sku-uuid:quantity`
67
- );
68
- }
54
+ const items = itemArgs.map((arg) => {
55
+ const [skuUuid, quantityStr] = parseColonPair(arg, 'sku-uuid', 'quantity', 'lease item');
69
56
  return { skuUuid, quantity: parseBigInt(quantityStr, 'quantity') };
70
57
  });
71
58
 
@@ -74,6 +61,7 @@ export async function routeBillingTransaction(
74
61
  value: MsgCreateLease.fromPartial({
75
62
  tenant: senderAddress,
76
63
  items,
64
+ metaHash: metaHash ?? new Uint8Array(),
77
65
  }),
78
66
  };
79
67
 
@@ -82,25 +70,20 @@ export async function routeBillingTransaction(
82
70
  }
83
71
 
84
72
  case 'close-lease': {
85
- if (args.length < 1) {
86
- const usage = getSubcommandUsage('tx', 'billing', 'close-lease');
87
- throw new ManifestMCPError(
88
- ManifestMCPErrorCode.TX_FAILED,
89
- `close-lease requires at least one lease-uuid argument. Usage: close-lease ${usage || '<lease-uuid>...'}`,
90
- { usage }
91
- );
92
- }
73
+ // Parse optional --reason flag
74
+ const { value: reason, consumedIndices } = extractFlag(args, '--reason', 'billing close-lease');
75
+ const leaseArgs = filterConsumedArgs(args, consumedIndices);
76
+ requireArgs(leaseArgs, 1, ['lease-uuid'], 'billing close-lease');
93
77
 
94
78
  // MsgCloseLease can close multiple leases at once
95
- const leaseUuids = args;
96
- const reason = ''; // Optional reason, could be added as a flag later
79
+ const leaseUuids = leaseArgs;
97
80
 
98
81
  const msg = {
99
82
  typeUrl: '/liftedinit.billing.v1.MsgCloseLease',
100
83
  value: MsgCloseLease.fromPartial({
101
84
  sender: senderAddress,
102
85
  leaseUuids,
103
- reason,
86
+ reason: reason ?? '',
104
87
  }),
105
88
  };
106
89
 
@@ -109,31 +92,56 @@ export async function routeBillingTransaction(
109
92
  }
110
93
 
111
94
  case 'withdraw': {
112
- if (args.length < 1) {
113
- const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
114
- throw new ManifestMCPError(
115
- ManifestMCPErrorCode.TX_FAILED,
116
- `withdraw requires at least one lease-uuid argument or provider-uuid with --provider flag. Usage: withdraw ${usage || '<lease-uuid>... OR --provider <provider-uuid>'}`,
117
- { usage }
118
- );
119
- }
95
+ requireArgs(args, 1, ['lease-uuid or --provider'], 'billing withdraw');
96
+
97
+ // Extract flags
98
+ const providerFlag = extractFlag(args, '--provider', 'billing withdraw');
99
+ const limitFlag = extractFlag(args, '--limit', 'billing withdraw');
120
100
 
121
- // Check if using provider-wide withdrawal
122
- const providerFlagIndex = args.indexOf('--provider');
123
101
  let leaseUuids: string[] = [];
124
102
  let providerUuid = '';
103
+ let limit = BigInt(0); // 0 means use default (50)
125
104
 
126
- if (providerFlagIndex !== -1) {
105
+ if (providerFlag.value) {
127
106
  // Provider-wide withdrawal mode
128
- providerUuid = args[providerFlagIndex + 1] || '';
129
- if (!providerUuid) {
107
+ providerUuid = providerFlag.value;
108
+
109
+ // Parse optional --limit flag (only valid with --provider)
110
+ if (limitFlag.value) {
111
+ limit = parseBigInt(limitFlag.value, 'limit');
112
+ if (limit < BigInt(1) || limit > BigInt(100)) {
113
+ throw new ManifestMCPError(
114
+ ManifestMCPErrorCode.TX_FAILED,
115
+ `Invalid limit: ${limit}. Must be between 1 and 100.`
116
+ );
117
+ }
118
+ }
119
+
120
+ // Check for any extra arguments that weren't consumed
121
+ const allConsumed = [...providerFlag.consumedIndices, ...limitFlag.consumedIndices];
122
+ const extraArgs = filterConsumedArgs(args, allConsumed);
123
+ if (extraArgs.length > 0) {
124
+ const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
130
125
  throw new ManifestMCPError(
131
126
  ManifestMCPErrorCode.TX_FAILED,
132
- 'withdraw with --provider flag requires provider-uuid argument'
127
+ `Provider-wide withdrawal does not accept additional arguments. ` +
128
+ `Got unexpected: ${extraArgs.map(a => `"${a}"`).join(', ')}. ` +
129
+ `For lease-specific withdrawal, omit --provider flag. Usage: withdraw ${usage ?? '<args>'}`
133
130
  );
134
131
  }
135
132
  } else {
136
133
  // Lease-specific withdrawal mode
134
+ // Check for unexpected flags (--limit without --provider is invalid)
135
+ const unexpectedFlags = args.filter(arg => arg.startsWith('--'));
136
+ if (unexpectedFlags.length > 0) {
137
+ const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
138
+ throw new ManifestMCPError(
139
+ ManifestMCPErrorCode.TX_FAILED,
140
+ `Unexpected flag(s) in lease-specific withdrawal mode: ${unexpectedFlags.join(', ')}. ` +
141
+ `Use --provider for provider-wide withdrawal. Usage: withdraw ${usage ?? '<args>'}`
142
+ );
143
+ }
144
+
137
145
  leaseUuids = args;
138
146
  }
139
147
 
@@ -143,6 +151,7 @@ export async function routeBillingTransaction(
143
151
  sender: senderAddress,
144
152
  leaseUuids,
145
153
  providerUuid,
154
+ limit,
146
155
  }),
147
156
  };
148
157
 
@@ -151,10 +160,6 @@ export async function routeBillingTransaction(
151
160
  }
152
161
 
153
162
  default:
154
- throw new ManifestMCPError(
155
- ManifestMCPErrorCode.UNSUPPORTED_TX,
156
- `Unsupported billing transaction subcommand: ${subcommand}`,
157
- { availableSubcommands: ['fund-credit', 'create-lease', 'close-lease', 'withdraw'] }
158
- );
163
+ throwUnsupportedSubcommand('tx', 'billing', subcommand);
159
164
  }
160
165
  }
@@ -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, validateArgsLength } from './utils.js';
3
+ import { CosmosTxResult } from '../types.js';
4
+ import { throwUnsupportedSubcommand } from '../modules.js';
5
+ import { parseAmount, buildTxResult, validateAddress, validateArgsLength, requireArgs } from './utils.js';
5
6
 
6
7
  const { MsgWithdrawDelegatorReward, MsgSetWithdrawAddress, MsgFundCommunityPool } = cosmos.distribution.v1beta1;
7
8
 
@@ -13,20 +14,13 @@ export async function routeDistributionTransaction(
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, 'distribution transaction');
20
20
 
21
21
  switch (subcommand) {
22
22
  case 'withdraw-rewards': {
23
- if (args.length < 1) {
24
- throw new ManifestMCPError(
25
- ManifestMCPErrorCode.TX_FAILED,
26
- 'withdraw-rewards requires validator-address argument'
27
- );
28
- }
29
-
23
+ requireArgs(args, 1, ['validator-address'], 'distribution withdraw-rewards');
30
24
  const [validatorAddress] = args;
31
25
  validateAddress(validatorAddress, 'validator address');
32
26
 
@@ -43,13 +37,7 @@ export async function routeDistributionTransaction(
43
37
  }
44
38
 
45
39
  case 'set-withdraw-addr': {
46
- if (args.length < 1) {
47
- throw new ManifestMCPError(
48
- ManifestMCPErrorCode.TX_FAILED,
49
- 'set-withdraw-addr requires withdraw-address argument'
50
- );
51
- }
52
-
40
+ requireArgs(args, 1, ['withdraw-address'], 'distribution set-withdraw-addr');
53
41
  const [withdrawAddress] = args;
54
42
  validateAddress(withdrawAddress, 'withdraw address');
55
43
 
@@ -66,13 +54,7 @@ export async function routeDistributionTransaction(
66
54
  }
67
55
 
68
56
  case 'fund-community-pool': {
69
- if (args.length < 1) {
70
- throw new ManifestMCPError(
71
- ManifestMCPErrorCode.TX_FAILED,
72
- 'fund-community-pool requires amount argument'
73
- );
74
- }
75
-
57
+ requireArgs(args, 1, ['amount'], 'distribution fund-community-pool');
76
58
  const [amountStr] = args;
77
59
  const { amount, denom } = parseAmount(amountStr);
78
60
 
@@ -89,10 +71,6 @@ export async function routeDistributionTransaction(
89
71
  }
90
72
 
91
73
  default:
92
- throw new ManifestMCPError(
93
- ManifestMCPErrorCode.UNSUPPORTED_TX,
94
- `Unsupported distribution transaction subcommand: ${subcommand}`,
95
- { availableSubcommands: ['withdraw-rewards', 'set-withdraw-addr', 'fund-community-pool'] }
96
- );
74
+ throwUnsupportedSubcommand('tx', 'distribution', subcommand);
97
75
  }
98
76
  }
@@ -1,10 +1,34 @@
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, parseBigInt, validateArgsLength } from './utils.js';
3
+ import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult } from '../types.js';
4
+ import { throwUnsupportedSubcommand } from '../modules.js';
5
+ import { parseAmount, buildTxResult, parseBigInt, validateArgsLength, extractFlag, requireArgs } from './utils.js';
5
6
 
6
7
  const { MsgVote, MsgDeposit, MsgVoteWeighted, VoteOption } = cosmos.gov.v1;
7
8
 
9
+ /** 10^18 as BigInt for fixed-point math */
10
+ const FIXED18_ONE = BigInt('1000000000000000000');
11
+
12
+ /**
13
+ * Format a fixed-18 BigInt as a decimal string without precision loss.
14
+ * E.g., 500000000000000000n -> "0.5", 1000000000000000000n -> "1.0"
15
+ */
16
+ function formatFixed18(value: bigint): string {
17
+ const isNegative = value < BigInt(0);
18
+ const absValue = isNegative ? -value : value;
19
+ const intPart = absValue / FIXED18_ONE;
20
+ const fracPart = absValue % FIXED18_ONE;
21
+
22
+ // Pad fraction to 18 digits, then trim trailing zeros
23
+ const fracStr = fracPart.toString().padStart(18, '0').replace(/0+$/, '');
24
+
25
+ const sign = isNegative ? '-' : '';
26
+ if (fracStr === '') {
27
+ return `${sign}${intPart}.0`;
28
+ }
29
+ return `${sign}${intPart}.${fracStr}`;
30
+ }
31
+
8
32
  /**
9
33
  * Parse a decimal weight string to an 18-decimal fixed-point string.
10
34
  * Uses string manipulation to avoid floating-point precision loss.
@@ -70,30 +94,19 @@ export async function routeGovTransaction(
70
94
  senderAddress: string,
71
95
  subcommand: string,
72
96
  args: string[],
73
- _config: ManifestMCPConfig,
74
97
  waitForConfirmation: boolean
75
98
  ): Promise<CosmosTxResult> {
76
99
  validateArgsLength(args, 'gov transaction');
77
100
 
78
101
  switch (subcommand) {
79
102
  case 'vote': {
80
- if (args.length < 2) {
81
- throw new ManifestMCPError(
82
- ManifestMCPErrorCode.TX_FAILED,
83
- 'vote requires proposal-id and option arguments'
84
- );
85
- }
86
-
103
+ requireArgs(args, 2, ['proposal-id', 'option'], 'gov vote');
87
104
  const [proposalIdStr, optionStr] = args;
88
105
  const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
89
106
  const option = parseVoteOption(optionStr);
90
107
 
91
108
  // Extract optional metadata from args
92
- let metadata = '';
93
- const metadataIndex = args.indexOf('--metadata');
94
- if (metadataIndex !== -1 && args[metadataIndex + 1]) {
95
- metadata = args[metadataIndex + 1];
96
- }
109
+ const { value: metadata = '' } = extractFlag(args, '--metadata', 'gov vote');
97
110
 
98
111
  const msg = {
99
112
  typeUrl: '/cosmos.gov.v1.MsgVote',
@@ -110,13 +123,7 @@ export async function routeGovTransaction(
110
123
  }
111
124
 
112
125
  case 'weighted-vote': {
113
- if (args.length < 2) {
114
- throw new ManifestMCPError(
115
- ManifestMCPErrorCode.TX_FAILED,
116
- 'weighted-vote requires proposal-id and options arguments (format: yes=0.5,no=0.5)'
117
- );
118
- }
119
-
126
+ requireArgs(args, 2, ['proposal-id', 'options'], 'gov weighted-vote');
120
127
  const [proposalIdStr, optionsStr] = args;
121
128
  const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
122
129
 
@@ -136,6 +143,15 @@ export async function routeGovTransaction(
136
143
  return { option, weight };
137
144
  });
138
145
 
146
+ // Validate that weights sum to exactly 1.0 (10^18 in fixed-point)
147
+ const totalWeight = options.reduce((sum, opt) => sum + BigInt(opt.weight), BigInt(0));
148
+ if (totalWeight !== FIXED18_ONE) {
149
+ throw new ManifestMCPError(
150
+ ManifestMCPErrorCode.TX_FAILED,
151
+ `Weighted vote options must sum to exactly 1.0. Got ${formatFixed18(totalWeight)} (${options.map(o => o.weight).join(' + ')} = ${totalWeight})`
152
+ );
153
+ }
154
+
139
155
  const msg = {
140
156
  typeUrl: '/cosmos.gov.v1.MsgVoteWeighted',
141
157
  value: MsgVoteWeighted.fromPartial({
@@ -151,13 +167,7 @@ export async function routeGovTransaction(
151
167
  }
152
168
 
153
169
  case 'deposit': {
154
- if (args.length < 2) {
155
- throw new ManifestMCPError(
156
- ManifestMCPErrorCode.TX_FAILED,
157
- 'deposit requires proposal-id and amount arguments'
158
- );
159
- }
160
-
170
+ requireArgs(args, 2, ['proposal-id', 'amount'], 'gov deposit');
161
171
  const [proposalIdStr, amountStr] = args;
162
172
  const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
163
173
  const { amount, denom } = parseAmount(amountStr);
@@ -176,10 +186,6 @@ export async function routeGovTransaction(
176
186
  }
177
187
 
178
188
  default:
179
- throw new ManifestMCPError(
180
- ManifestMCPErrorCode.UNSUPPORTED_TX,
181
- `Unsupported gov transaction subcommand: ${subcommand}`,
182
- { availableSubcommands: ['vote', 'weighted-vote', 'deposit'] }
183
- );
189
+ throwUnsupportedSubcommand('tx', 'gov', subcommand);
184
190
  }
185
191
  }
@@ -1,4 +1,4 @@
1
- export { parseAmount, buildTxResult, parseBigInt } from './utils.js';
1
+ export { parseAmount, buildTxResult, parseBigInt, parseHexBytes, bytesToHex } from './utils.js';
2
2
  export { routeBankTransaction } from './bank.js';
3
3
  export { routeStakingTransaction } from './staking.js';
4
4
  export { routeDistributionTransaction } from './distribution.js';
@@ -1,7 +1,8 @@
1
1
  import { SigningStargateClient } from '@cosmjs/stargate';
2
2
  import { liftedinit } from '@manifest-network/manifestjs';
3
- import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult, ManifestMCPConfig } from '../types.js';
4
- import { parseAmount, buildTxResult, validateAddress, validateArgsLength } from './utils.js';
3
+ import { CosmosTxResult } from '../types.js';
4
+ import { throwUnsupportedSubcommand } from '../modules.js';
5
+ import { parseAmount, buildTxResult, validateAddress, validateArgsLength, parseColonPair, requireArgs } from './utils.js';
5
6
 
6
7
  const { MsgPayout, MsgBurnHeldBalance } = liftedinit.manifest.v1;
7
8
 
@@ -13,29 +14,16 @@ export async function routeManifestTransaction(
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, 'manifest transaction');
20
20
 
21
21
  switch (subcommand) {
22
22
  case 'payout': {
23
- if (args.length < 1) {
24
- throw new ManifestMCPError(
25
- ManifestMCPErrorCode.TX_FAILED,
26
- 'payout requires at least one address:amount pair'
27
- );
28
- }
29
-
23
+ requireArgs(args, 1, ['address:amount'], 'manifest payout');
30
24
  // Parse payout pairs (format: address:amount ...)
31
25
  const payoutPairs = args.map((arg) => {
32
- const [address, amountStr] = arg.split(':');
33
- if (!address || !amountStr) {
34
- throw new ManifestMCPError(
35
- ManifestMCPErrorCode.TX_FAILED,
36
- `Invalid payout pair format: ${arg}. Expected format: address:amount`
37
- );
38
- }
26
+ const [address, amountStr] = parseColonPair(arg, 'address', 'amount', 'payout pair');
39
27
  validateAddress(address, 'payout recipient address');
40
28
  const { amount, denom } = parseAmount(amountStr);
41
29
  return { address, coin: { denom, amount } };
@@ -54,13 +42,7 @@ export async function routeManifestTransaction(
54
42
  }
55
43
 
56
44
  case 'burn-held-balance': {
57
- if (args.length < 1) {
58
- throw new ManifestMCPError(
59
- ManifestMCPErrorCode.TX_FAILED,
60
- 'burn-held-balance requires at least one amount argument'
61
- );
62
- }
63
-
45
+ requireArgs(args, 1, ['amount'], 'manifest burn-held-balance');
64
46
  // Parse coins to burn
65
47
  const burnCoins = args.map((amountStr) => {
66
48
  const { amount, denom } = parseAmount(amountStr);
@@ -80,10 +62,6 @@ export async function routeManifestTransaction(
80
62
  }
81
63
 
82
64
  default:
83
- throw new ManifestMCPError(
84
- ManifestMCPErrorCode.UNSUPPORTED_TX,
85
- `Unsupported manifest transaction subcommand: ${subcommand}`,
86
- { availableSubcommands: ['payout', 'burn-held-balance'] }
87
- );
65
+ throwUnsupportedSubcommand('tx', 'manifest', subcommand);
88
66
  }
89
67
  }
@@ -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, validateArgsLength } from './utils.js';
3
+ import { CosmosTxResult } from '../types.js';
4
+ import { throwUnsupportedSubcommand } from '../modules.js';
5
+ import { parseAmount, buildTxResult, validateAddress, validateArgsLength, requireArgs } from './utils.js';
5
6
 
6
7
  const { MsgDelegate, MsgUndelegate, MsgBeginRedelegate } = cosmos.staking.v1beta1;
7
8
 
@@ -13,20 +14,13 @@ export async function routeStakingTransaction(
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, 'staking transaction');
20
20
 
21
21
  switch (subcommand) {
22
22
  case 'delegate': {
23
- if (args.length < 2) {
24
- throw new ManifestMCPError(
25
- ManifestMCPErrorCode.TX_FAILED,
26
- 'delegate requires validator-address and amount arguments'
27
- );
28
- }
29
-
23
+ requireArgs(args, 2, ['validator-address', 'amount'], 'staking delegate');
30
24
  const [validatorAddress, amountStr] = args;
31
25
  validateAddress(validatorAddress, 'validator address');
32
26
  const { amount, denom } = parseAmount(amountStr);
@@ -46,13 +40,7 @@ export async function routeStakingTransaction(
46
40
 
47
41
  case 'unbond':
48
42
  case 'undelegate': {
49
- if (args.length < 2) {
50
- throw new ManifestMCPError(
51
- ManifestMCPErrorCode.TX_FAILED,
52
- 'unbond requires validator-address and amount arguments'
53
- );
54
- }
55
-
43
+ requireArgs(args, 2, ['validator-address', 'amount'], 'staking unbond');
56
44
  const [validatorAddress, amountStr] = args;
57
45
  validateAddress(validatorAddress, 'validator address');
58
46
  const { amount, denom } = parseAmount(amountStr);
@@ -71,13 +59,7 @@ export async function routeStakingTransaction(
71
59
  }
72
60
 
73
61
  case 'redelegate': {
74
- if (args.length < 3) {
75
- throw new ManifestMCPError(
76
- ManifestMCPErrorCode.TX_FAILED,
77
- 'redelegate requires src-validator, dst-validator, and amount arguments'
78
- );
79
- }
80
-
62
+ requireArgs(args, 3, ['src-validator', 'dst-validator', 'amount'], 'staking redelegate');
81
63
  const [srcValidatorAddress, dstValidatorAddress, amountStr] = args;
82
64
  validateAddress(srcValidatorAddress, 'source validator address');
83
65
  validateAddress(dstValidatorAddress, 'destination validator address');
@@ -98,10 +80,6 @@ export async function routeStakingTransaction(
98
80
  }
99
81
 
100
82
  default:
101
- throw new ManifestMCPError(
102
- ManifestMCPErrorCode.UNSUPPORTED_TX,
103
- `Unsupported staking transaction subcommand: ${subcommand}`,
104
- { availableSubcommands: ['delegate', 'unbond', 'redelegate'] }
105
- );
83
+ throwUnsupportedSubcommand('tx', 'staking', subcommand);
106
84
  }
107
85
  }