@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.
- package/.github/workflows/publish.yml +4 -2
- package/CLAUDE.md +7 -3
- package/README.md +1 -1
- package/dist/client.d.ts +6 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +77 -21
- package/dist/client.js.map +1 -1
- package/dist/cosmos.d.ts.map +1 -1
- package/dist/cosmos.js +7 -57
- package/dist/cosmos.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -25
- package/dist/index.js.map +1 -1
- package/dist/modules.d.ts +30 -1
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +65 -1
- package/dist/modules.js.map +1 -1
- package/dist/modules.test.js +58 -1
- package/dist/modules.test.js.map +1 -1
- package/dist/queries/auth.d.ts +7 -1
- package/dist/queries/auth.d.ts.map +1 -1
- package/dist/queries/auth.js +18 -45
- package/dist/queries/auth.js.map +1 -1
- package/dist/queries/bank.d.ts +7 -1
- package/dist/queries/bank.d.ts.map +1 -1
- package/dist/queries/bank.js +24 -38
- package/dist/queries/bank.js.map +1 -1
- package/dist/queries/billing.d.ts +7 -1
- package/dist/queries/billing.d.ts.map +1 -1
- package/dist/queries/billing.js +28 -54
- package/dist/queries/billing.js.map +1 -1
- package/dist/queries/distribution.d.ts +7 -1
- package/dist/queries/distribution.d.ts.map +1 -1
- package/dist/queries/distribution.js +18 -36
- package/dist/queries/distribution.js.map +1 -1
- package/dist/queries/gov.d.ts +7 -1
- package/dist/queries/gov.d.ts.map +1 -1
- package/dist/queries/gov.js +24 -41
- package/dist/queries/gov.js.map +1 -1
- package/dist/queries/index.d.ts +2 -1
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/queries/index.js +1 -1
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/staking.d.ts +7 -1
- package/dist/queries/staking.d.ts.map +1 -1
- package/dist/queries/staking.js +36 -59
- package/dist/queries/staking.js.map +1 -1
- package/dist/queries/utils.d.ts +42 -10
- package/dist/queries/utils.d.ts.map +1 -1
- package/dist/queries/utils.js +64 -12
- package/dist/queries/utils.js.map +1 -1
- package/dist/queries/utils.test.js +68 -8
- package/dist/queries/utils.test.js.map +1 -1
- package/dist/transactions/bank.d.ts +2 -2
- package/dist/transactions/bank.d.ts.map +1 -1
- package/dist/transactions/bank.js +9 -18
- package/dist/transactions/bank.js.map +1 -1
- package/dist/transactions/billing.d.ts +2 -2
- package/dist/transactions/billing.d.ts.map +1 -1
- package/dist/transactions/billing.js +29 -86
- package/dist/transactions/billing.js.map +1 -1
- package/dist/transactions/distribution.d.ts +2 -2
- package/dist/transactions/distribution.d.ts.map +1 -1
- package/dist/transactions/distribution.js +7 -13
- package/dist/transactions/distribution.js.map +1 -1
- package/dist/transactions/gov.d.ts +2 -2
- package/dist/transactions/gov.d.ts.map +1 -1
- package/dist/transactions/gov.js +29 -20
- package/dist/transactions/gov.js.map +1 -1
- package/dist/transactions/index.d.ts +1 -1
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +1 -1
- package/dist/transactions/index.js.map +1 -1
- package/dist/transactions/manifest.d.ts +2 -2
- package/dist/transactions/manifest.d.ts.map +1 -1
- package/dist/transactions/manifest.js +7 -14
- package/dist/transactions/manifest.js.map +1 -1
- package/dist/transactions/staking.d.ts +2 -2
- package/dist/transactions/staking.d.ts.map +1 -1
- package/dist/transactions/staking.js +7 -13
- package/dist/transactions/staking.js.map +1 -1
- package/dist/transactions/utils.d.ts +63 -1
- package/dist/transactions/utils.d.ts.map +1 -1
- package/dist/transactions/utils.js +121 -2
- package/dist/transactions/utils.js.map +1 -1
- package/dist/transactions/utils.test.js +351 -1
- package/dist/transactions/utils.test.js.map +1 -1
- package/dist/types.d.ts +203 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wallet/mnemonic.d.ts +1 -0
- package/dist/wallet/mnemonic.d.ts.map +1 -1
- package/dist/wallet/mnemonic.js +34 -13
- package/dist/wallet/mnemonic.js.map +1 -1
- package/package.json +5 -1
- package/src/client.ts +84 -21
- package/src/cosmos.ts +13 -109
- package/src/index.ts +17 -23
- package/src/modules.test.ts +60 -0
- package/src/modules.ts +122 -5
- package/src/queries/auth.ts +35 -74
- package/src/queries/bank.ts +40 -58
- package/src/queries/billing.ts +46 -86
- package/src/queries/distribution.ts +35 -59
- package/src/queries/gov.ts +40 -64
- package/src/queries/index.ts +10 -1
- package/src/queries/staking.ts +55 -91
- package/src/queries/utils.test.ts +103 -8
- package/src/queries/utils.ts +92 -12
- package/src/transactions/bank.ts +9 -33
- package/src/transactions/billing.ts +30 -137
- package/src/transactions/distribution.ts +7 -29
- package/src/transactions/gov.ts +33 -37
- package/src/transactions/index.ts +1 -1
- package/src/transactions/manifest.ts +7 -29
- package/src/transactions/staking.ts +7 -29
- package/src/transactions/utils.test.ts +390 -1
- package/src/transactions/utils.ts +191 -2
- package/src/types.ts +318 -9
- package/src/wallet/mnemonic.ts +41 -17
- package/.claude/settings.local.json +0 -20
|
@@ -1,47 +1,14 @@
|
|
|
1
1
|
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
2
|
-
import { fromHex } from '@cosmjs/encoding';
|
|
3
2
|
import { liftedinit } from '@manifest-network/manifestjs';
|
|
4
|
-
import { ManifestMCPError, ManifestMCPErrorCode
|
|
5
|
-
import { parseAmount, buildTxResult, parseBigInt, validateAddress, validateArgsLength } from './utils.js';
|
|
6
|
-
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';
|
|
7
6
|
|
|
8
7
|
const { MsgFundCredit, MsgCreateLease, MsgCloseLease, MsgWithdraw } = liftedinit.billing.v1;
|
|
9
8
|
|
|
10
9
|
/** Maximum meta hash length in bytes (64 bytes for SHA-512) */
|
|
11
10
|
const MAX_META_HASH_BYTES = 64;
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* Validate and parse a hex string into Uint8Array
|
|
15
|
-
* Uses @cosmjs/encoding for hex validation and conversion
|
|
16
|
-
*/
|
|
17
|
-
function parseMetaHash(hexString: string): Uint8Array {
|
|
18
|
-
// Check even length first to avoid fractional byte counts in error messages
|
|
19
|
-
if (hexString.length % 2 !== 0) {
|
|
20
|
-
throw new ManifestMCPError(
|
|
21
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
22
|
-
`Invalid meta-hash: hex string must have even length. Got ${hexString.length} characters.`
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Check max length (64 bytes = 128 hex chars)
|
|
27
|
-
const byteLength = hexString.length / 2;
|
|
28
|
-
if (byteLength > MAX_META_HASH_BYTES) {
|
|
29
|
-
throw new ManifestMCPError(
|
|
30
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
31
|
-
`Invalid meta-hash: exceeds maximum ${MAX_META_HASH_BYTES} bytes. Got ${byteLength} bytes (${hexString.length} hex chars).`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
return fromHex(hexString);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new ManifestMCPError(
|
|
39
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
40
|
-
`Invalid meta-hash: ${error instanceof Error ? error.message : String(error)}`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
12
|
/**
|
|
46
13
|
* Route billing transaction to appropriate handler
|
|
47
14
|
*/
|
|
@@ -50,22 +17,13 @@ export async function routeBillingTransaction(
|
|
|
50
17
|
senderAddress: string,
|
|
51
18
|
subcommand: string,
|
|
52
19
|
args: string[],
|
|
53
|
-
_config: ManifestMCPConfig,
|
|
54
20
|
waitForConfirmation: boolean
|
|
55
21
|
): Promise<CosmosTxResult> {
|
|
56
22
|
validateArgsLength(args, 'billing transaction');
|
|
57
23
|
|
|
58
24
|
switch (subcommand) {
|
|
59
25
|
case 'fund-credit': {
|
|
60
|
-
|
|
61
|
-
const usage = getSubcommandUsage('tx', 'billing', 'fund-credit');
|
|
62
|
-
throw new ManifestMCPError(
|
|
63
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
64
|
-
`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>'}`,
|
|
65
|
-
{ receivedArgs: args, expectedArgs: ['tenant-address', 'amount'], usage }
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
26
|
+
requireArgs(args, 2, ['tenant-address', 'amount'], 'billing fund-credit');
|
|
69
27
|
const [tenant, amountStr] = args;
|
|
70
28
|
validateAddress(tenant, 'tenant address');
|
|
71
29
|
const { amount, denom } = parseAmount(amountStr);
|
|
@@ -84,42 +42,17 @@ export async function routeBillingTransaction(
|
|
|
84
42
|
}
|
|
85
43
|
|
|
86
44
|
case 'create-lease': {
|
|
87
|
-
// Parse optional --meta-hash flag
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (args[0] === '--meta-hash') {
|
|
92
|
-
if (args.length < 2 || args[1].startsWith('--')) {
|
|
93
|
-
const usage = getSubcommandUsage('tx', 'billing', 'create-lease');
|
|
94
|
-
throw new ManifestMCPError(
|
|
95
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
96
|
-
`--meta-hash flag requires a hex value. Usage: create-lease ${usage ?? '<args>'}`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const hexHash = args[1];
|
|
100
|
-
// Validate and convert hex string to Uint8Array (max 64 bytes)
|
|
101
|
-
metaHash = parseMetaHash(hexHash);
|
|
102
|
-
itemArgs = args.slice(2);
|
|
103
|
-
}
|
|
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;
|
|
104
48
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
109
|
-
`create-lease requires at least one sku-uuid:quantity pair. Usage: create-lease ${usage ?? '<args>'}`,
|
|
110
|
-
{ usage }
|
|
111
|
-
);
|
|
112
|
-
}
|
|
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');
|
|
113
52
|
|
|
114
53
|
// Parse items (format: sku-uuid:quantity ...)
|
|
115
54
|
const items = itemArgs.map((arg) => {
|
|
116
|
-
const [skuUuid, quantityStr] = arg
|
|
117
|
-
if (!skuUuid || !quantityStr) {
|
|
118
|
-
throw new ManifestMCPError(
|
|
119
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
120
|
-
`Invalid lease item format: ${arg}. Expected format: sku-uuid:quantity`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
55
|
+
const [skuUuid, quantityStr] = parseColonPair(arg, 'sku-uuid', 'quantity', 'lease item');
|
|
123
56
|
return { skuUuid, quantity: parseBigInt(quantityStr, 'quantity') };
|
|
124
57
|
});
|
|
125
58
|
|
|
@@ -137,25 +70,20 @@ export async function routeBillingTransaction(
|
|
|
137
70
|
}
|
|
138
71
|
|
|
139
72
|
case 'close-lease': {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`close-lease requires at least one lease-uuid argument. Usage: close-lease ${usage || '<lease-uuid>...'}`,
|
|
145
|
-
{ usage }
|
|
146
|
-
);
|
|
147
|
-
}
|
|
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');
|
|
148
77
|
|
|
149
78
|
// MsgCloseLease can close multiple leases at once
|
|
150
|
-
const leaseUuids =
|
|
151
|
-
const reason = ''; // Optional reason, could be added as a flag later
|
|
79
|
+
const leaseUuids = leaseArgs;
|
|
152
80
|
|
|
153
81
|
const msg = {
|
|
154
82
|
typeUrl: '/liftedinit.billing.v1.MsgCloseLease',
|
|
155
83
|
value: MsgCloseLease.fromPartial({
|
|
156
84
|
sender: senderAddress,
|
|
157
85
|
leaseUuids,
|
|
158
|
-
reason,
|
|
86
|
+
reason: reason ?? '',
|
|
159
87
|
}),
|
|
160
88
|
};
|
|
161
89
|
|
|
@@ -164,57 +92,34 @@ export async function routeBillingTransaction(
|
|
|
164
92
|
}
|
|
165
93
|
|
|
166
94
|
case 'withdraw': {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
{ usage }
|
|
173
|
-
);
|
|
174
|
-
}
|
|
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');
|
|
175
100
|
|
|
176
|
-
// Check if using provider-wide withdrawal
|
|
177
|
-
const providerFlagIndex = args.indexOf('--provider');
|
|
178
|
-
const limitFlagIndex = args.indexOf('--limit');
|
|
179
101
|
let leaseUuids: string[] = [];
|
|
180
102
|
let providerUuid = '';
|
|
181
103
|
let limit = BigInt(0); // 0 means use default (50)
|
|
182
104
|
|
|
183
|
-
if (
|
|
105
|
+
if (providerFlag.value) {
|
|
184
106
|
// Provider-wide withdrawal mode
|
|
185
|
-
providerUuid =
|
|
186
|
-
if (!providerUuid || providerUuid.startsWith('--')) {
|
|
187
|
-
throw new ManifestMCPError(
|
|
188
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
189
|
-
'withdraw with --provider flag requires provider-uuid argument'
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Track consumed arg indices to detect extra arguments
|
|
194
|
-
const consumedIndices = new Set<number>([providerFlagIndex, providerFlagIndex + 1]);
|
|
107
|
+
providerUuid = providerFlag.value;
|
|
195
108
|
|
|
196
109
|
// Parse optional --limit flag (only valid with --provider)
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
if (!limitStr || limitStr.startsWith('--')) {
|
|
200
|
-
throw new ManifestMCPError(
|
|
201
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
202
|
-
'withdraw with --limit flag requires a number argument (1-100)'
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
limit = parseBigInt(limitStr, 'limit');
|
|
110
|
+
if (limitFlag.value) {
|
|
111
|
+
limit = parseBigInt(limitFlag.value, 'limit');
|
|
206
112
|
if (limit < BigInt(1) || limit > BigInt(100)) {
|
|
207
113
|
throw new ManifestMCPError(
|
|
208
114
|
ManifestMCPErrorCode.TX_FAILED,
|
|
209
115
|
`Invalid limit: ${limit}. Must be between 1 and 100.`
|
|
210
116
|
);
|
|
211
117
|
}
|
|
212
|
-
consumedIndices.add(limitFlagIndex);
|
|
213
|
-
consumedIndices.add(limitFlagIndex + 1);
|
|
214
118
|
}
|
|
215
119
|
|
|
216
120
|
// Check for any extra arguments that weren't consumed
|
|
217
|
-
const
|
|
121
|
+
const allConsumed = [...providerFlag.consumedIndices, ...limitFlag.consumedIndices];
|
|
122
|
+
const extraArgs = filterConsumedArgs(args, allConsumed);
|
|
218
123
|
if (extraArgs.length > 0) {
|
|
219
124
|
const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
|
|
220
125
|
throw new ManifestMCPError(
|
|
@@ -226,7 +131,7 @@ export async function routeBillingTransaction(
|
|
|
226
131
|
}
|
|
227
132
|
} else {
|
|
228
133
|
// Lease-specific withdrawal mode
|
|
229
|
-
// Check for unexpected flags
|
|
134
|
+
// Check for unexpected flags (--limit without --provider is invalid)
|
|
230
135
|
const unexpectedFlags = args.filter(arg => arg.startsWith('--'));
|
|
231
136
|
if (unexpectedFlags.length > 0) {
|
|
232
137
|
const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
|
|
@@ -238,14 +143,6 @@ export async function routeBillingTransaction(
|
|
|
238
143
|
}
|
|
239
144
|
|
|
240
145
|
leaseUuids = args;
|
|
241
|
-
|
|
242
|
-
if (leaseUuids.length === 0) {
|
|
243
|
-
const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
|
|
244
|
-
throw new ManifestMCPError(
|
|
245
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
246
|
-
`withdraw requires at least one lease-uuid. Usage: withdraw ${usage ?? '<args>'}`
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
146
|
}
|
|
250
147
|
|
|
251
148
|
const msg = {
|
|
@@ -263,10 +160,6 @@ export async function routeBillingTransaction(
|
|
|
263
160
|
}
|
|
264
161
|
|
|
265
162
|
default:
|
|
266
|
-
|
|
267
|
-
ManifestMCPErrorCode.UNSUPPORTED_TX,
|
|
268
|
-
`Unsupported billing transaction subcommand: ${subcommand}`,
|
|
269
|
-
{ availableSubcommands: ['fund-credit', 'create-lease', 'close-lease', 'withdraw'] }
|
|
270
|
-
);
|
|
163
|
+
throwUnsupportedSubcommand('tx', 'billing', subcommand);
|
|
271
164
|
}
|
|
272
165
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
2
2
|
import { cosmos } from '@manifest-network/manifestjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/transactions/gov.ts
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
2
2
|
import { cosmos } from '@manifest-network/manifestjs';
|
|
3
|
-
import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 ${
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|