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

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 (131) hide show
  1. package/.github/workflows/publish.yml +4 -2
  2. package/CLAUDE.md +11 -6
  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 +98 -1
  17. package/dist/modules.js.map +1 -1
  18. package/dist/modules.test.js +60 -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/sku.d.ts +13 -0
  45. package/dist/queries/sku.d.ts.map +1 -0
  46. package/dist/queries/sku.js +60 -0
  47. package/dist/queries/sku.js.map +1 -0
  48. package/dist/queries/staking.d.ts +7 -1
  49. package/dist/queries/staking.d.ts.map +1 -1
  50. package/dist/queries/staking.js +36 -59
  51. package/dist/queries/staking.js.map +1 -1
  52. package/dist/queries/utils.d.ts +60 -10
  53. package/dist/queries/utils.d.ts.map +1 -1
  54. package/dist/queries/utils.js +80 -12
  55. package/dist/queries/utils.js.map +1 -1
  56. package/dist/queries/utils.test.js +68 -8
  57. package/dist/queries/utils.test.js.map +1 -1
  58. package/dist/transactions/bank.d.ts +2 -2
  59. package/dist/transactions/bank.d.ts.map +1 -1
  60. package/dist/transactions/bank.js +9 -18
  61. package/dist/transactions/bank.js.map +1 -1
  62. package/dist/transactions/billing.d.ts +2 -2
  63. package/dist/transactions/billing.d.ts.map +1 -1
  64. package/dist/transactions/billing.js +125 -89
  65. package/dist/transactions/billing.js.map +1 -1
  66. package/dist/transactions/distribution.d.ts +2 -2
  67. package/dist/transactions/distribution.d.ts.map +1 -1
  68. package/dist/transactions/distribution.js +7 -13
  69. package/dist/transactions/distribution.js.map +1 -1
  70. package/dist/transactions/gov.d.ts +2 -2
  71. package/dist/transactions/gov.d.ts.map +1 -1
  72. package/dist/transactions/gov.js +29 -20
  73. package/dist/transactions/gov.js.map +1 -1
  74. package/dist/transactions/index.d.ts +1 -1
  75. package/dist/transactions/index.d.ts.map +1 -1
  76. package/dist/transactions/index.js +1 -1
  77. package/dist/transactions/index.js.map +1 -1
  78. package/dist/transactions/manifest.d.ts +2 -2
  79. package/dist/transactions/manifest.d.ts.map +1 -1
  80. package/dist/transactions/manifest.js +7 -14
  81. package/dist/transactions/manifest.js.map +1 -1
  82. package/dist/transactions/sku.d.ts +7 -0
  83. package/dist/transactions/sku.d.ts.map +1 -0
  84. package/dist/transactions/sku.js +184 -0
  85. package/dist/transactions/sku.js.map +1 -0
  86. package/dist/transactions/staking.d.ts +2 -2
  87. package/dist/transactions/staking.d.ts.map +1 -1
  88. package/dist/transactions/staking.js +7 -13
  89. package/dist/transactions/staking.js.map +1 -1
  90. package/dist/transactions/utils.d.ts +65 -1
  91. package/dist/transactions/utils.d.ts.map +1 -1
  92. package/dist/transactions/utils.js +123 -2
  93. package/dist/transactions/utils.js.map +1 -1
  94. package/dist/transactions/utils.test.js +351 -1
  95. package/dist/transactions/utils.test.js.map +1 -1
  96. package/dist/types.d.ts +218 -8
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/types.js.map +1 -1
  99. package/dist/wallet/mnemonic.d.ts +1 -0
  100. package/dist/wallet/mnemonic.d.ts.map +1 -1
  101. package/dist/wallet/mnemonic.js +34 -13
  102. package/dist/wallet/mnemonic.js.map +1 -1
  103. package/package.json +5 -1
  104. package/src/client.ts +84 -21
  105. package/src/cosmos.ts +13 -109
  106. package/src/index.ts +17 -23
  107. package/src/modules.test.ts +62 -0
  108. package/src/modules.ts +155 -5
  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/sku.ts +85 -0
  116. package/src/queries/staking.ts +55 -91
  117. package/src/queries/utils.test.ts +103 -8
  118. package/src/queries/utils.ts +119 -12
  119. package/src/transactions/bank.ts +9 -33
  120. package/src/transactions/billing.ts +155 -141
  121. package/src/transactions/distribution.ts +7 -29
  122. package/src/transactions/gov.ts +33 -37
  123. package/src/transactions/index.ts +1 -1
  124. package/src/transactions/manifest.ts +7 -29
  125. package/src/transactions/sku.ts +232 -0
  126. package/src/transactions/staking.ts +7 -29
  127. package/src/transactions/utils.test.ts +390 -1
  128. package/src/transactions/utils.ts +194 -2
  129. package/src/types.ts +344 -9
  130. package/src/wallet/mnemonic.ts +41 -17
  131. package/.claude/settings.local.json +0 -20
@@ -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
 
@@ -138,11 +145,10 @@ export async function routeGovTransaction(
138
145
 
139
146
  // Validate that weights sum to exactly 1.0 (10^18 in fixed-point)
140
147
  const totalWeight = options.reduce((sum, opt) => sum + BigInt(opt.weight), BigInt(0));
141
- const oneInFixed18 = BigInt('1000000000000000000'); // 10^18
142
- if (totalWeight !== oneInFixed18) {
148
+ if (totalWeight !== FIXED18_ONE) {
143
149
  throw new ManifestMCPError(
144
150
  ManifestMCPErrorCode.TX_FAILED,
145
- `Weighted vote options must sum to exactly 1.0. Got ${Number(totalWeight) / 1e18} (${options.map(o => o.weight).join(' + ')} = ${totalWeight})`
151
+ `Weighted vote options must sum to exactly 1.0. Got ${formatFixed18(totalWeight)} (${options.map(o => o.weight).join(' + ')} = ${totalWeight})`
146
152
  );
147
153
  }
148
154
 
@@ -161,13 +167,7 @@ export async function routeGovTransaction(
161
167
  }
162
168
 
163
169
  case 'deposit': {
164
- if (args.length < 2) {
165
- throw new ManifestMCPError(
166
- ManifestMCPErrorCode.TX_FAILED,
167
- 'deposit requires proposal-id and amount arguments'
168
- );
169
- }
170
-
170
+ requireArgs(args, 2, ['proposal-id', 'amount'], 'gov deposit');
171
171
  const [proposalIdStr, amountStr] = args;
172
172
  const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
173
173
  const { amount, denom } = parseAmount(amountStr);
@@ -186,10 +186,6 @@ export async function routeGovTransaction(
186
186
  }
187
187
 
188
188
  default:
189
- throw new ManifestMCPError(
190
- ManifestMCPErrorCode.UNSUPPORTED_TX,
191
- `Unsupported gov transaction subcommand: ${subcommand}`,
192
- { availableSubcommands: ['vote', 'weighted-vote', 'deposit'] }
193
- );
189
+ throwUnsupportedSubcommand('tx', 'gov', subcommand);
194
190
  }
195
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
  }
@@ -0,0 +1,232 @@
1
+ import { SigningStargateClient } from '@cosmjs/stargate';
2
+ import { liftedinit } from '@manifest-network/manifestjs';
3
+ import { CosmosTxResult, ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
4
+ import { parseAmount, buildTxResult, validateAddress, validateArgsLength, extractFlag, filterConsumedArgs, requireArgs, parseHexBytes, MAX_META_HASH_BYTES } from './utils.js';
5
+ import { throwUnsupportedSubcommand } from '../modules.js';
6
+
7
+ const {
8
+ MsgCreateProvider, MsgUpdateProvider, MsgDeactivateProvider,
9
+ MsgCreateSKU, MsgUpdateSKU, MsgDeactivateSKU,
10
+ MsgUpdateParams,
11
+ Unit,
12
+ } = liftedinit.sku.v1;
13
+
14
+ /**
15
+ * Parse a unit string to the Unit enum value.
16
+ * Accepts 'per-hour' or 'per-day'.
17
+ */
18
+ function parseUnit(value: string): number {
19
+ switch (value.toLowerCase()) {
20
+ case 'per-hour':
21
+ return Unit.UNIT_PER_HOUR;
22
+ case 'per-day':
23
+ return Unit.UNIT_PER_DAY;
24
+ default:
25
+ throw new ManifestMCPError(
26
+ ManifestMCPErrorCode.TX_FAILED,
27
+ `Invalid unit: "${value}". Expected "per-hour" or "per-day".`
28
+ );
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Parse a boolean string ('true' or 'false').
34
+ */
35
+ function parseBooleanString(value: string, fieldName: string): boolean {
36
+ const lower = value.toLowerCase();
37
+ if (lower === 'true') return true;
38
+ if (lower === 'false') return false;
39
+ throw new ManifestMCPError(
40
+ ManifestMCPErrorCode.TX_FAILED,
41
+ `Invalid ${fieldName}: "${value}". Expected "true" or "false".`
42
+ );
43
+ }
44
+
45
+ /**
46
+ * Route SKU transaction to appropriate handler
47
+ */
48
+ export async function routeSkuTransaction(
49
+ client: SigningStargateClient,
50
+ senderAddress: string,
51
+ subcommand: string,
52
+ args: string[],
53
+ waitForConfirmation: boolean
54
+ ): Promise<CosmosTxResult> {
55
+ validateArgsLength(args, 'sku transaction');
56
+
57
+ switch (subcommand) {
58
+ case 'create-provider': {
59
+ // Parse optional --meta-hash flag
60
+ const { value: metaHashHex, consumedIndices } = extractFlag(args, '--meta-hash', 'sku create-provider');
61
+ const metaHash = metaHashHex ? parseHexBytes(metaHashHex, 'meta-hash', MAX_META_HASH_BYTES) : new Uint8Array();
62
+ const positionalArgs = filterConsumedArgs(args, consumedIndices);
63
+
64
+ requireArgs(positionalArgs, 3, ['address', 'payout-address', 'api-url'], 'sku create-provider');
65
+ const [address, payoutAddress, apiUrl] = positionalArgs;
66
+ validateAddress(address, 'address');
67
+ validateAddress(payoutAddress, 'payout address');
68
+
69
+ const msg = {
70
+ typeUrl: '/liftedinit.sku.v1.MsgCreateProvider',
71
+ value: MsgCreateProvider.fromPartial({
72
+ authority: senderAddress,
73
+ address,
74
+ payoutAddress,
75
+ metaHash,
76
+ apiUrl,
77
+ }),
78
+ };
79
+
80
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
81
+ return buildTxResult('sku', 'create-provider', result, waitForConfirmation);
82
+ }
83
+
84
+ case 'update-provider': {
85
+ // Parse optional flags
86
+ const metaHashFlag = extractFlag(args, '--meta-hash', 'sku update-provider');
87
+ const activeFlag = extractFlag(args, '--active', 'sku update-provider');
88
+ const allConsumed = [...metaHashFlag.consumedIndices, ...activeFlag.consumedIndices];
89
+ const positionalArgs = filterConsumedArgs(args, allConsumed);
90
+
91
+ requireArgs(positionalArgs, 4, ['provider-uuid', 'address', 'payout-address', 'api-url'], 'sku update-provider');
92
+ const [uuid, address, payoutAddress, apiUrl] = positionalArgs;
93
+ validateAddress(address, 'address');
94
+ validateAddress(payoutAddress, 'payout address');
95
+
96
+ const metaHash = metaHashFlag.value ? parseHexBytes(metaHashFlag.value, 'meta-hash', MAX_META_HASH_BYTES) : new Uint8Array();
97
+ const active = activeFlag.value ? parseBooleanString(activeFlag.value, 'active') : true;
98
+
99
+ const msg = {
100
+ typeUrl: '/liftedinit.sku.v1.MsgUpdateProvider',
101
+ value: MsgUpdateProvider.fromPartial({
102
+ authority: senderAddress,
103
+ uuid,
104
+ address,
105
+ payoutAddress,
106
+ metaHash,
107
+ active,
108
+ apiUrl,
109
+ }),
110
+ };
111
+
112
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
113
+ return buildTxResult('sku', 'update-provider', result, waitForConfirmation);
114
+ }
115
+
116
+ case 'deactivate-provider': {
117
+ requireArgs(args, 1, ['provider-uuid'], 'sku deactivate-provider');
118
+ const [uuid] = args;
119
+
120
+ const msg = {
121
+ typeUrl: '/liftedinit.sku.v1.MsgDeactivateProvider',
122
+ value: MsgDeactivateProvider.fromPartial({
123
+ authority: senderAddress,
124
+ uuid,
125
+ }),
126
+ };
127
+
128
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
129
+ return buildTxResult('sku', 'deactivate-provider', result, waitForConfirmation);
130
+ }
131
+
132
+ case 'create-sku': {
133
+ // Parse optional --meta-hash flag
134
+ const { value: metaHashHex, consumedIndices } = extractFlag(args, '--meta-hash', 'sku create-sku');
135
+ const metaHash = metaHashHex ? parseHexBytes(metaHashHex, 'meta-hash', MAX_META_HASH_BYTES) : new Uint8Array();
136
+ const positionalArgs = filterConsumedArgs(args, consumedIndices);
137
+
138
+ requireArgs(positionalArgs, 4, ['provider-uuid', 'name', 'unit', 'base-price'], 'sku create-sku');
139
+ const [providerUuid, name, unitStr, basePriceStr] = positionalArgs;
140
+
141
+ const unit = parseUnit(unitStr);
142
+ const { amount, denom } = parseAmount(basePriceStr);
143
+
144
+ const msg = {
145
+ typeUrl: '/liftedinit.sku.v1.MsgCreateSKU',
146
+ value: MsgCreateSKU.fromPartial({
147
+ authority: senderAddress,
148
+ providerUuid,
149
+ name,
150
+ unit,
151
+ basePrice: { denom, amount },
152
+ metaHash,
153
+ }),
154
+ };
155
+
156
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
157
+ return buildTxResult('sku', 'create-sku', result, waitForConfirmation);
158
+ }
159
+
160
+ case 'update-sku': {
161
+ // Parse optional flags
162
+ const metaHashFlag = extractFlag(args, '--meta-hash', 'sku update-sku');
163
+ const activeFlag = extractFlag(args, '--active', 'sku update-sku');
164
+ const allConsumed = [...metaHashFlag.consumedIndices, ...activeFlag.consumedIndices];
165
+ const positionalArgs = filterConsumedArgs(args, allConsumed);
166
+
167
+ requireArgs(positionalArgs, 5, ['sku-uuid', 'provider-uuid', 'name', 'unit', 'base-price'], 'sku update-sku');
168
+ const [uuid, providerUuid, name, unitStr, basePriceStr] = positionalArgs;
169
+
170
+ const unit = parseUnit(unitStr);
171
+ const { amount, denom } = parseAmount(basePriceStr);
172
+ const metaHash = metaHashFlag.value ? parseHexBytes(metaHashFlag.value, 'meta-hash', MAX_META_HASH_BYTES) : new Uint8Array();
173
+ const active = activeFlag.value ? parseBooleanString(activeFlag.value, 'active') : true;
174
+
175
+ const msg = {
176
+ typeUrl: '/liftedinit.sku.v1.MsgUpdateSKU',
177
+ value: MsgUpdateSKU.fromPartial({
178
+ authority: senderAddress,
179
+ uuid,
180
+ providerUuid,
181
+ name,
182
+ unit,
183
+ basePrice: { denom, amount },
184
+ metaHash,
185
+ active,
186
+ }),
187
+ };
188
+
189
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
190
+ return buildTxResult('sku', 'update-sku', result, waitForConfirmation);
191
+ }
192
+
193
+ case 'deactivate-sku': {
194
+ requireArgs(args, 1, ['sku-uuid'], 'sku deactivate-sku');
195
+ const [uuid] = args;
196
+
197
+ const msg = {
198
+ typeUrl: '/liftedinit.sku.v1.MsgDeactivateSKU',
199
+ value: MsgDeactivateSKU.fromPartial({
200
+ authority: senderAddress,
201
+ uuid,
202
+ }),
203
+ };
204
+
205
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
206
+ return buildTxResult('sku', 'deactivate-sku', result, waitForConfirmation);
207
+ }
208
+
209
+ case 'update-params': {
210
+ requireArgs(args, 1, ['allowed-address'], 'sku update-params');
211
+ for (const addr of args) {
212
+ validateAddress(addr, 'allowed address');
213
+ }
214
+
215
+ const msg = {
216
+ typeUrl: '/liftedinit.sku.v1.MsgUpdateParams',
217
+ value: MsgUpdateParams.fromPartial({
218
+ authority: senderAddress,
219
+ params: {
220
+ allowedList: args,
221
+ },
222
+ }),
223
+ };
224
+
225
+ const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
226
+ return buildTxResult('sku', 'update-params', result, waitForConfirmation);
227
+ }
228
+
229
+ default:
230
+ throwUnsupportedSubcommand('tx', 'sku', subcommand);
231
+ }
232
+ }
@@ -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
  }