@manifest-network/manifest-mcp-browser 0.1.7 → 0.1.9
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/README.md +5 -2
- package/dist/client.d.ts +5 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -2
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -10
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/queries/index.js +1 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/transactions/bank.d.ts.map +1 -1
- package/dist/transactions/bank.js +7 -5
- package/dist/transactions/bank.js.map +1 -1
- package/dist/transactions/gov.d.ts.map +1 -1
- package/dist/transactions/gov.js +7 -5
- package/dist/transactions/gov.js.map +1 -1
- package/dist/transactions/index.d.ts +1 -0
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +1 -0
- package/dist/transactions/index.js.map +1 -1
- package/dist/transactions/utils.d.ts.map +1 -1
- package/dist/transactions/utils.js +5 -6
- package/dist/transactions/utils.js.map +1 -1
- package/dist/types.d.ts +2 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +13 -3
- package/.github/workflows/ci.yml +0 -37
- package/.github/workflows/publish.yml +0 -53
- package/CLAUDE.md +0 -113
- package/dist/config.test.d.ts +0 -2
- package/dist/config.test.d.ts.map +0 -1
- package/dist/config.test.js +0 -251
- package/dist/config.test.js.map +0 -1
- package/dist/modules.test.d.ts +0 -2
- package/dist/modules.test.d.ts.map +0 -1
- package/dist/modules.test.js +0 -161
- package/dist/modules.test.js.map +0 -1
- package/dist/queries/utils.test.d.ts +0 -2
- package/dist/queries/utils.test.d.ts.map +0 -1
- package/dist/queries/utils.test.js +0 -117
- package/dist/queries/utils.test.js.map +0 -1
- package/dist/transactions/utils.test.d.ts +0 -2
- package/dist/transactions/utils.test.d.ts.map +0 -1
- package/dist/transactions/utils.test.js +0 -567
- package/dist/transactions/utils.test.js.map +0 -1
- package/src/client.ts +0 -288
- package/src/config.test.ts +0 -299
- package/src/config.ts +0 -174
- package/src/cosmos.ts +0 -106
- package/src/index.ts +0 -478
- package/src/modules.test.ts +0 -191
- package/src/modules.ts +0 -470
- package/src/queries/auth.ts +0 -97
- package/src/queries/bank.ts +0 -99
- package/src/queries/billing.ts +0 -124
- package/src/queries/distribution.ts +0 -114
- package/src/queries/gov.ts +0 -104
- package/src/queries/group.ts +0 -146
- package/src/queries/index.ts +0 -17
- package/src/queries/sku.ts +0 -85
- package/src/queries/staking.ts +0 -154
- package/src/queries/utils.test.ts +0 -156
- package/src/queries/utils.ts +0 -121
- package/src/transactions/bank.ts +0 -86
- package/src/transactions/billing.ts +0 -286
- package/src/transactions/distribution.ts +0 -76
- package/src/transactions/gov.ts +0 -164
- package/src/transactions/group.ts +0 -458
- package/src/transactions/index.ts +0 -8
- package/src/transactions/manifest.ts +0 -67
- package/src/transactions/sku.ts +0 -232
- package/src/transactions/staking.ts +0 -85
- package/src/transactions/utils.test.ts +0 -626
- package/src/transactions/utils.ts +0 -417
- package/src/types.ts +0 -548
- package/src/wallet/index.ts +0 -2
- package/src/wallet/mnemonic.ts +0 -146
- package/tsconfig.json +0 -23
|
@@ -1,286 +0,0 @@
|
|
|
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, parseBigInt, validateAddress, validateArgsLength, extractFlag, filterConsumedArgs, parseColonPair, requireArgs, parseHexBytes, MAX_META_HASH_BYTES } from './utils.js';
|
|
5
|
-
import { getSubcommandUsage, throwUnsupportedSubcommand } from '../modules.js';
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
MsgFundCredit, MsgCreateLease, MsgCloseLease, MsgWithdraw,
|
|
9
|
-
MsgCreateLeaseForTenant, MsgAcknowledgeLease, MsgRejectLease, MsgCancelLease,
|
|
10
|
-
MsgUpdateParams,
|
|
11
|
-
} = liftedinit.billing.v1;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Route billing transaction to appropriate handler
|
|
15
|
-
*/
|
|
16
|
-
export async function routeBillingTransaction(
|
|
17
|
-
client: SigningStargateClient,
|
|
18
|
-
senderAddress: string,
|
|
19
|
-
subcommand: string,
|
|
20
|
-
args: string[],
|
|
21
|
-
waitForConfirmation: boolean
|
|
22
|
-
): Promise<CosmosTxResult> {
|
|
23
|
-
validateArgsLength(args, 'billing transaction');
|
|
24
|
-
|
|
25
|
-
switch (subcommand) {
|
|
26
|
-
case 'fund-credit': {
|
|
27
|
-
requireArgs(args, 2, ['tenant-address', 'amount'], 'billing fund-credit');
|
|
28
|
-
const [tenant, amountStr] = args;
|
|
29
|
-
validateAddress(tenant, 'tenant address');
|
|
30
|
-
const { amount, denom } = parseAmount(amountStr);
|
|
31
|
-
|
|
32
|
-
const msg = {
|
|
33
|
-
typeUrl: '/liftedinit.billing.v1.MsgFundCredit',
|
|
34
|
-
value: MsgFundCredit.fromPartial({
|
|
35
|
-
sender: senderAddress,
|
|
36
|
-
tenant,
|
|
37
|
-
amount: { denom, amount },
|
|
38
|
-
}),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
42
|
-
return buildTxResult('billing', 'fund-credit', result, waitForConfirmation);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
case 'create-lease': {
|
|
46
|
-
// Parse optional --meta-hash flag (can appear anywhere in args)
|
|
47
|
-
const { value: metaHashHex, consumedIndices } = extractFlag(args, '--meta-hash', 'billing create-lease');
|
|
48
|
-
const metaHash = metaHashHex ? parseHexBytes(metaHashHex, 'meta-hash', MAX_META_HASH_BYTES) : undefined;
|
|
49
|
-
|
|
50
|
-
// Filter out --meta-hash and its value to get item args
|
|
51
|
-
const itemArgs = filterConsumedArgs(args, consumedIndices);
|
|
52
|
-
requireArgs(itemArgs, 1, ['sku-uuid:quantity'], 'billing create-lease');
|
|
53
|
-
|
|
54
|
-
// Parse items (format: sku-uuid:quantity ...)
|
|
55
|
-
const items = itemArgs.map((arg) => {
|
|
56
|
-
const [skuUuid, quantityStr] = parseColonPair(arg, 'sku-uuid', 'quantity', 'lease item');
|
|
57
|
-
return { skuUuid, quantity: parseBigInt(quantityStr, 'quantity') };
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const msg = {
|
|
61
|
-
typeUrl: '/liftedinit.billing.v1.MsgCreateLease',
|
|
62
|
-
value: MsgCreateLease.fromPartial({
|
|
63
|
-
tenant: senderAddress,
|
|
64
|
-
items,
|
|
65
|
-
metaHash: metaHash ?? new Uint8Array(),
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
70
|
-
return buildTxResult('billing', 'create-lease', result, waitForConfirmation);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
case 'close-lease': {
|
|
74
|
-
// Parse optional --reason flag
|
|
75
|
-
const { value: reason, consumedIndices } = extractFlag(args, '--reason', 'billing close-lease');
|
|
76
|
-
const leaseArgs = filterConsumedArgs(args, consumedIndices);
|
|
77
|
-
requireArgs(leaseArgs, 1, ['lease-uuid'], 'billing close-lease');
|
|
78
|
-
|
|
79
|
-
// MsgCloseLease can close multiple leases at once
|
|
80
|
-
const leaseUuids = leaseArgs;
|
|
81
|
-
|
|
82
|
-
const msg = {
|
|
83
|
-
typeUrl: '/liftedinit.billing.v1.MsgCloseLease',
|
|
84
|
-
value: MsgCloseLease.fromPartial({
|
|
85
|
-
sender: senderAddress,
|
|
86
|
-
leaseUuids,
|
|
87
|
-
reason: reason ?? '',
|
|
88
|
-
}),
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
92
|
-
return buildTxResult('billing', 'close-lease', result, waitForConfirmation);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
case 'withdraw': {
|
|
96
|
-
requireArgs(args, 1, ['lease-uuid or --provider'], 'billing withdraw');
|
|
97
|
-
|
|
98
|
-
// Extract flags
|
|
99
|
-
const providerFlag = extractFlag(args, '--provider', 'billing withdraw');
|
|
100
|
-
const limitFlag = extractFlag(args, '--limit', 'billing withdraw');
|
|
101
|
-
|
|
102
|
-
let leaseUuids: string[] = [];
|
|
103
|
-
let providerUuid = '';
|
|
104
|
-
let limit = BigInt(0); // 0 means use default (50)
|
|
105
|
-
|
|
106
|
-
if (providerFlag.value) {
|
|
107
|
-
// Provider-wide withdrawal mode
|
|
108
|
-
providerUuid = providerFlag.value;
|
|
109
|
-
|
|
110
|
-
// Parse optional --limit flag (only valid with --provider)
|
|
111
|
-
if (limitFlag.value) {
|
|
112
|
-
limit = parseBigInt(limitFlag.value, 'limit');
|
|
113
|
-
if (limit < BigInt(1) || limit > BigInt(100)) {
|
|
114
|
-
throw new ManifestMCPError(
|
|
115
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
116
|
-
`Invalid limit: ${limit}. Must be between 1 and 100.`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Check for any extra arguments that weren't consumed
|
|
122
|
-
const allConsumed = [...providerFlag.consumedIndices, ...limitFlag.consumedIndices];
|
|
123
|
-
const extraArgs = filterConsumedArgs(args, allConsumed);
|
|
124
|
-
if (extraArgs.length > 0) {
|
|
125
|
-
const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
|
|
126
|
-
throw new ManifestMCPError(
|
|
127
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
128
|
-
`Provider-wide withdrawal does not accept additional arguments. ` +
|
|
129
|
-
`Got unexpected: ${extraArgs.map(a => `"${a}"`).join(', ')}. ` +
|
|
130
|
-
`For lease-specific withdrawal, omit --provider flag. Usage: withdraw ${usage ?? '<args>'}`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
// Lease-specific withdrawal mode
|
|
135
|
-
// Check for unexpected flags (--limit without --provider is invalid)
|
|
136
|
-
const unexpectedFlags = args.filter(arg => arg.startsWith('--'));
|
|
137
|
-
if (unexpectedFlags.length > 0) {
|
|
138
|
-
const usage = getSubcommandUsage('tx', 'billing', 'withdraw');
|
|
139
|
-
throw new ManifestMCPError(
|
|
140
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
141
|
-
`Unexpected flag(s) in lease-specific withdrawal mode: ${unexpectedFlags.join(', ')}. ` +
|
|
142
|
-
`Use --provider for provider-wide withdrawal. Usage: withdraw ${usage ?? '<args>'}`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
leaseUuids = args;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const msg = {
|
|
150
|
-
typeUrl: '/liftedinit.billing.v1.MsgWithdraw',
|
|
151
|
-
value: MsgWithdraw.fromPartial({
|
|
152
|
-
sender: senderAddress,
|
|
153
|
-
leaseUuids,
|
|
154
|
-
providerUuid,
|
|
155
|
-
limit,
|
|
156
|
-
}),
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
160
|
-
return buildTxResult('billing', 'withdraw', result, waitForConfirmation);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
case 'create-lease-for-tenant': {
|
|
164
|
-
// Parse optional --meta-hash flag
|
|
165
|
-
const { value: metaHashHex, consumedIndices } = extractFlag(args, '--meta-hash', 'billing create-lease-for-tenant');
|
|
166
|
-
const metaHash = metaHashHex ? parseHexBytes(metaHashHex, 'meta-hash', MAX_META_HASH_BYTES) : undefined;
|
|
167
|
-
|
|
168
|
-
// Filter out --meta-hash and its value to get remaining args
|
|
169
|
-
const remainingArgs = filterConsumedArgs(args, consumedIndices);
|
|
170
|
-
requireArgs(remainingArgs, 2, ['tenant-address', 'sku-uuid:quantity'], 'billing create-lease-for-tenant');
|
|
171
|
-
|
|
172
|
-
const [tenant, ...itemArgs] = remainingArgs;
|
|
173
|
-
validateAddress(tenant, 'tenant address');
|
|
174
|
-
|
|
175
|
-
// Parse items (format: sku-uuid:quantity ...)
|
|
176
|
-
const items = itemArgs.map((arg) => {
|
|
177
|
-
const [skuUuid, quantityStr] = parseColonPair(arg, 'sku-uuid', 'quantity', 'lease item');
|
|
178
|
-
return { skuUuid, quantity: parseBigInt(quantityStr, 'quantity') };
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const msg = {
|
|
182
|
-
typeUrl: '/liftedinit.billing.v1.MsgCreateLeaseForTenant',
|
|
183
|
-
value: MsgCreateLeaseForTenant.fromPartial({
|
|
184
|
-
authority: senderAddress,
|
|
185
|
-
tenant,
|
|
186
|
-
items,
|
|
187
|
-
metaHash: metaHash ?? new Uint8Array(),
|
|
188
|
-
}),
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
192
|
-
return buildTxResult('billing', 'create-lease-for-tenant', result, waitForConfirmation);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
case 'acknowledge-lease': {
|
|
196
|
-
requireArgs(args, 1, ['lease-uuid'], 'billing acknowledge-lease');
|
|
197
|
-
const leaseUuids = args;
|
|
198
|
-
|
|
199
|
-
const msg = {
|
|
200
|
-
typeUrl: '/liftedinit.billing.v1.MsgAcknowledgeLease',
|
|
201
|
-
value: MsgAcknowledgeLease.fromPartial({
|
|
202
|
-
sender: senderAddress,
|
|
203
|
-
leaseUuids,
|
|
204
|
-
}),
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
208
|
-
return buildTxResult('billing', 'acknowledge-lease', result, waitForConfirmation);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
case 'reject-lease': {
|
|
212
|
-
// Parse optional --reason flag
|
|
213
|
-
const { value: reason, consumedIndices } = extractFlag(args, '--reason', 'billing reject-lease');
|
|
214
|
-
const leaseArgs = filterConsumedArgs(args, consumedIndices);
|
|
215
|
-
requireArgs(leaseArgs, 1, ['lease-uuid'], 'billing reject-lease');
|
|
216
|
-
|
|
217
|
-
const leaseUuids = leaseArgs;
|
|
218
|
-
|
|
219
|
-
const msg = {
|
|
220
|
-
typeUrl: '/liftedinit.billing.v1.MsgRejectLease',
|
|
221
|
-
value: MsgRejectLease.fromPartial({
|
|
222
|
-
sender: senderAddress,
|
|
223
|
-
leaseUuids,
|
|
224
|
-
reason: reason ?? '',
|
|
225
|
-
}),
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
229
|
-
return buildTxResult('billing', 'reject-lease', result, waitForConfirmation);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
case 'cancel-lease': {
|
|
233
|
-
requireArgs(args, 1, ['lease-uuid'], 'billing cancel-lease');
|
|
234
|
-
const leaseUuids = args;
|
|
235
|
-
|
|
236
|
-
const msg = {
|
|
237
|
-
typeUrl: '/liftedinit.billing.v1.MsgCancelLease',
|
|
238
|
-
value: MsgCancelLease.fromPartial({
|
|
239
|
-
tenant: senderAddress,
|
|
240
|
-
leaseUuids,
|
|
241
|
-
}),
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
245
|
-
return buildTxResult('billing', 'cancel-lease', result, waitForConfirmation);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
case 'update-params': {
|
|
249
|
-
requireArgs(args, 5, [
|
|
250
|
-
'max-leases-per-tenant', 'max-items-per-lease', 'min-lease-duration',
|
|
251
|
-
'max-pending-leases-per-tenant', 'pending-timeout',
|
|
252
|
-
], 'billing update-params');
|
|
253
|
-
|
|
254
|
-
const [
|
|
255
|
-
maxLeasesPerTenantStr, maxItemsPerLeaseStr, minLeaseDurationStr,
|
|
256
|
-
maxPendingLeasesPerTenantStr, pendingTimeoutStr,
|
|
257
|
-
...allowedAddresses
|
|
258
|
-
] = args;
|
|
259
|
-
|
|
260
|
-
for (const addr of allowedAddresses) {
|
|
261
|
-
validateAddress(addr, 'allowed address');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const msg = {
|
|
265
|
-
typeUrl: '/liftedinit.billing.v1.MsgUpdateParams',
|
|
266
|
-
value: MsgUpdateParams.fromPartial({
|
|
267
|
-
authority: senderAddress,
|
|
268
|
-
params: {
|
|
269
|
-
maxLeasesPerTenant: parseBigInt(maxLeasesPerTenantStr, 'max-leases-per-tenant'),
|
|
270
|
-
maxItemsPerLease: parseBigInt(maxItemsPerLeaseStr, 'max-items-per-lease'),
|
|
271
|
-
minLeaseDuration: parseBigInt(minLeaseDurationStr, 'min-lease-duration'),
|
|
272
|
-
maxPendingLeasesPerTenant: parseBigInt(maxPendingLeasesPerTenantStr, 'max-pending-leases-per-tenant'),
|
|
273
|
-
pendingTimeout: parseBigInt(pendingTimeoutStr, 'pending-timeout'),
|
|
274
|
-
allowedList: allowedAddresses,
|
|
275
|
-
},
|
|
276
|
-
}),
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
280
|
-
return buildTxResult('billing', 'update-params', result, waitForConfirmation);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
default:
|
|
284
|
-
throwUnsupportedSubcommand('tx', 'billing', subcommand);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
2
|
-
import { cosmos } from '@manifest-network/manifestjs';
|
|
3
|
-
import { CosmosTxResult } from '../types.js';
|
|
4
|
-
import { throwUnsupportedSubcommand } from '../modules.js';
|
|
5
|
-
import { parseAmount, buildTxResult, validateAddress, validateArgsLength, requireArgs } from './utils.js';
|
|
6
|
-
|
|
7
|
-
const { MsgWithdrawDelegatorReward, MsgSetWithdrawAddress, MsgFundCommunityPool } = cosmos.distribution.v1beta1;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Route distribution transaction to appropriate handler
|
|
11
|
-
*/
|
|
12
|
-
export async function routeDistributionTransaction(
|
|
13
|
-
client: SigningStargateClient,
|
|
14
|
-
senderAddress: string,
|
|
15
|
-
subcommand: string,
|
|
16
|
-
args: string[],
|
|
17
|
-
waitForConfirmation: boolean
|
|
18
|
-
): Promise<CosmosTxResult> {
|
|
19
|
-
validateArgsLength(args, 'distribution transaction');
|
|
20
|
-
|
|
21
|
-
switch (subcommand) {
|
|
22
|
-
case 'withdraw-rewards': {
|
|
23
|
-
requireArgs(args, 1, ['validator-address'], 'distribution withdraw-rewards');
|
|
24
|
-
const [validatorAddress] = args;
|
|
25
|
-
validateAddress(validatorAddress, 'validator address');
|
|
26
|
-
|
|
27
|
-
const msg = {
|
|
28
|
-
typeUrl: '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
|
|
29
|
-
value: MsgWithdrawDelegatorReward.fromPartial({
|
|
30
|
-
delegatorAddress: senderAddress,
|
|
31
|
-
validatorAddress,
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
36
|
-
return buildTxResult('distribution', 'withdraw-rewards', result, waitForConfirmation);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
case 'set-withdraw-addr': {
|
|
40
|
-
requireArgs(args, 1, ['withdraw-address'], 'distribution set-withdraw-addr');
|
|
41
|
-
const [withdrawAddress] = args;
|
|
42
|
-
validateAddress(withdrawAddress, 'withdraw address');
|
|
43
|
-
|
|
44
|
-
const msg = {
|
|
45
|
-
typeUrl: '/cosmos.distribution.v1beta1.MsgSetWithdrawAddress',
|
|
46
|
-
value: MsgSetWithdrawAddress.fromPartial({
|
|
47
|
-
delegatorAddress: senderAddress,
|
|
48
|
-
withdrawAddress,
|
|
49
|
-
}),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
53
|
-
return buildTxResult('distribution', 'set-withdraw-addr', result, waitForConfirmation);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
case 'fund-community-pool': {
|
|
57
|
-
requireArgs(args, 1, ['amount'], 'distribution fund-community-pool');
|
|
58
|
-
const [amountStr] = args;
|
|
59
|
-
const { amount, denom } = parseAmount(amountStr);
|
|
60
|
-
|
|
61
|
-
const msg = {
|
|
62
|
-
typeUrl: '/cosmos.distribution.v1beta1.MsgFundCommunityPool',
|
|
63
|
-
value: MsgFundCommunityPool.fromPartial({
|
|
64
|
-
depositor: senderAddress,
|
|
65
|
-
amount: [{ denom, amount }],
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
70
|
-
return buildTxResult('distribution', 'fund-community-pool', result, waitForConfirmation);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
default:
|
|
74
|
-
throwUnsupportedSubcommand('tx', 'distribution', subcommand);
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/transactions/gov.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
2
|
-
import { cosmos } from '@manifest-network/manifestjs';
|
|
3
|
-
import { ManifestMCPError, ManifestMCPErrorCode, CosmosTxResult } from '../types.js';
|
|
4
|
-
import { throwUnsupportedSubcommand } from '../modules.js';
|
|
5
|
-
import { parseAmount, buildTxResult, parseBigInt, validateArgsLength, extractFlag, requireArgs, parseVoteOption } from './utils.js';
|
|
6
|
-
|
|
7
|
-
const { MsgVote, MsgDeposit, MsgVoteWeighted, VoteOption } = cosmos.gov.v1;
|
|
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
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Parse a decimal weight string to an 18-decimal fixed-point string.
|
|
34
|
-
* Uses string manipulation to avoid floating-point precision loss.
|
|
35
|
-
*
|
|
36
|
-
* @param weightStr - Decimal string like "0.5", "0.333333333333333333", "1"
|
|
37
|
-
* @returns String representation of weight * 10^18
|
|
38
|
-
*/
|
|
39
|
-
function parseWeightToFixed18(weightStr: string): string {
|
|
40
|
-
// Validate format: must be a valid decimal number
|
|
41
|
-
if (!/^\d+(\.\d+)?$/.test(weightStr)) {
|
|
42
|
-
throw new ManifestMCPError(
|
|
43
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
44
|
-
`Invalid weight format: "${weightStr}". Expected decimal like "0.5" or "0.333333333333333333"`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const [intPart, decPart = ''] = weightStr.split('.');
|
|
49
|
-
|
|
50
|
-
// Pad or truncate decimal part to exactly 18 digits
|
|
51
|
-
const paddedDecimal = decPart.padEnd(18, '0').slice(0, 18);
|
|
52
|
-
|
|
53
|
-
// Combine integer and decimal parts
|
|
54
|
-
const combined = intPart + paddedDecimal;
|
|
55
|
-
|
|
56
|
-
// Remove leading zeros but keep at least one digit
|
|
57
|
-
const result = combined.replace(/^0+/, '') || '0';
|
|
58
|
-
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Route gov transaction to appropriate handler
|
|
64
|
-
*/
|
|
65
|
-
export async function routeGovTransaction(
|
|
66
|
-
client: SigningStargateClient,
|
|
67
|
-
senderAddress: string,
|
|
68
|
-
subcommand: string,
|
|
69
|
-
args: string[],
|
|
70
|
-
waitForConfirmation: boolean
|
|
71
|
-
): Promise<CosmosTxResult> {
|
|
72
|
-
validateArgsLength(args, 'gov transaction');
|
|
73
|
-
|
|
74
|
-
switch (subcommand) {
|
|
75
|
-
case 'vote': {
|
|
76
|
-
requireArgs(args, 2, ['proposal-id', 'option'], 'gov vote');
|
|
77
|
-
const [proposalIdStr, optionStr] = args;
|
|
78
|
-
const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
|
|
79
|
-
const option = parseVoteOption(optionStr, VoteOption);
|
|
80
|
-
|
|
81
|
-
// Extract optional metadata from args
|
|
82
|
-
const { value: metadata = '' } = extractFlag(args, '--metadata', 'gov vote');
|
|
83
|
-
|
|
84
|
-
const msg = {
|
|
85
|
-
typeUrl: '/cosmos.gov.v1.MsgVote',
|
|
86
|
-
value: MsgVote.fromPartial({
|
|
87
|
-
proposalId,
|
|
88
|
-
voter: senderAddress,
|
|
89
|
-
option,
|
|
90
|
-
metadata,
|
|
91
|
-
}),
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
95
|
-
return buildTxResult('gov', 'vote', result, waitForConfirmation);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
case 'weighted-vote': {
|
|
99
|
-
requireArgs(args, 2, ['proposal-id', 'options'], 'gov weighted-vote');
|
|
100
|
-
const [proposalIdStr, optionsStr] = args;
|
|
101
|
-
const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
|
|
102
|
-
|
|
103
|
-
// Parse weighted options (format: yes=0.5,no=0.3,abstain=0.2)
|
|
104
|
-
const options = optionsStr.split(',').map((opt) => {
|
|
105
|
-
const [optName, weightStr] = opt.split('=');
|
|
106
|
-
if (!optName || !weightStr) {
|
|
107
|
-
throw new ManifestMCPError(
|
|
108
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
109
|
-
`Invalid weighted vote format: ${opt}. Expected format: option=weight`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
const option = parseVoteOption(optName, VoteOption);
|
|
113
|
-
// Weight is a decimal string (e.g., "0.5" -> "500000000000000000" for 18 decimals)
|
|
114
|
-
// Use string-based conversion to avoid floating-point precision loss
|
|
115
|
-
const weight = parseWeightToFixed18(weightStr);
|
|
116
|
-
return { option, weight };
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// Validate that weights sum to exactly 1.0 (10^18 in fixed-point)
|
|
120
|
-
const totalWeight = options.reduce((sum, opt) => sum + BigInt(opt.weight), BigInt(0));
|
|
121
|
-
if (totalWeight !== FIXED18_ONE) {
|
|
122
|
-
throw new ManifestMCPError(
|
|
123
|
-
ManifestMCPErrorCode.TX_FAILED,
|
|
124
|
-
`Weighted vote options must sum to exactly 1.0. Got ${formatFixed18(totalWeight)} (${options.map(o => o.weight).join(' + ')} = ${totalWeight})`
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const msg = {
|
|
129
|
-
typeUrl: '/cosmos.gov.v1.MsgVoteWeighted',
|
|
130
|
-
value: MsgVoteWeighted.fromPartial({
|
|
131
|
-
proposalId,
|
|
132
|
-
voter: senderAddress,
|
|
133
|
-
options,
|
|
134
|
-
metadata: '',
|
|
135
|
-
}),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
139
|
-
return buildTxResult('gov', 'weighted-vote', result, waitForConfirmation);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
case 'deposit': {
|
|
143
|
-
requireArgs(args, 2, ['proposal-id', 'amount'], 'gov deposit');
|
|
144
|
-
const [proposalIdStr, amountStr] = args;
|
|
145
|
-
const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
|
|
146
|
-
const { amount, denom } = parseAmount(amountStr);
|
|
147
|
-
|
|
148
|
-
const msg = {
|
|
149
|
-
typeUrl: '/cosmos.gov.v1.MsgDeposit',
|
|
150
|
-
value: MsgDeposit.fromPartial({
|
|
151
|
-
proposalId,
|
|
152
|
-
depositor: senderAddress,
|
|
153
|
-
amount: [{ denom, amount }],
|
|
154
|
-
}),
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
|
|
158
|
-
return buildTxResult('gov', 'deposit', result, waitForConfirmation);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
default:
|
|
162
|
-
throwUnsupportedSubcommand('tx', 'gov', subcommand);
|
|
163
|
-
}
|
|
164
|
-
}
|