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

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 (95) hide show
  1. package/README.md +5 -2
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +0 -10
  4. package/dist/config.js.map +1 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -7
  8. package/dist/index.js.map +1 -1
  9. package/dist/modules.d.ts.map +1 -1
  10. package/dist/modules.js +42 -0
  11. package/dist/modules.js.map +1 -1
  12. package/dist/queries/group.d.ts +12 -0
  13. package/dist/queries/group.d.ts.map +1 -0
  14. package/dist/queries/group.js +107 -0
  15. package/dist/queries/group.js.map +1 -0
  16. package/dist/queries/index.d.ts +2 -0
  17. package/dist/queries/index.d.ts.map +1 -1
  18. package/dist/queries/index.js +2 -0
  19. package/dist/queries/index.js.map +1 -1
  20. package/dist/queries/utils.d.ts +3 -18
  21. package/dist/queries/utils.d.ts.map +1 -1
  22. package/dist/queries/utils.js +2 -17
  23. package/dist/queries/utils.js.map +1 -1
  24. package/dist/transactions/bank.d.ts.map +1 -1
  25. package/dist/transactions/bank.js +7 -5
  26. package/dist/transactions/bank.js.map +1 -1
  27. package/dist/transactions/gov.d.ts.map +1 -1
  28. package/dist/transactions/gov.js +9 -30
  29. package/dist/transactions/gov.js.map +1 -1
  30. package/dist/transactions/group.d.ts +7 -0
  31. package/dist/transactions/group.d.ts.map +1 -0
  32. package/dist/transactions/group.js +339 -0
  33. package/dist/transactions/group.js.map +1 -0
  34. package/dist/transactions/index.d.ts +2 -0
  35. package/dist/transactions/index.d.ts.map +1 -1
  36. package/dist/transactions/index.js +2 -0
  37. package/dist/transactions/index.js.map +1 -1
  38. package/dist/transactions/utils.d.ts +37 -0
  39. package/dist/transactions/utils.d.ts.map +1 -1
  40. package/dist/transactions/utils.js +43 -0
  41. package/dist/transactions/utils.js.map +1 -1
  42. package/dist/types.d.ts +31 -3
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/types.js.map +1 -1
  45. package/package.json +5 -2
  46. package/.github/workflows/ci.yml +0 -37
  47. package/.github/workflows/publish.yml +0 -53
  48. package/CLAUDE.md +0 -111
  49. package/dist/config.test.d.ts +0 -2
  50. package/dist/config.test.d.ts.map +0 -1
  51. package/dist/config.test.js +0 -251
  52. package/dist/config.test.js.map +0 -1
  53. package/dist/modules.test.d.ts +0 -2
  54. package/dist/modules.test.d.ts.map +0 -1
  55. package/dist/modules.test.js +0 -159
  56. package/dist/modules.test.js.map +0 -1
  57. package/dist/queries/utils.test.d.ts +0 -2
  58. package/dist/queries/utils.test.d.ts.map +0 -1
  59. package/dist/queries/utils.test.js +0 -117
  60. package/dist/queries/utils.test.js.map +0 -1
  61. package/dist/transactions/utils.test.d.ts +0 -2
  62. package/dist/transactions/utils.test.d.ts.map +0 -1
  63. package/dist/transactions/utils.test.js +0 -471
  64. package/dist/transactions/utils.test.js.map +0 -1
  65. package/src/client.ts +0 -288
  66. package/src/config.test.ts +0 -299
  67. package/src/config.ts +0 -174
  68. package/src/cosmos.ts +0 -106
  69. package/src/index.ts +0 -478
  70. package/src/modules.test.ts +0 -189
  71. package/src/modules.ts +0 -428
  72. package/src/queries/auth.ts +0 -97
  73. package/src/queries/bank.ts +0 -99
  74. package/src/queries/billing.ts +0 -124
  75. package/src/queries/distribution.ts +0 -114
  76. package/src/queries/gov.ts +0 -104
  77. package/src/queries/index.ts +0 -16
  78. package/src/queries/sku.ts +0 -85
  79. package/src/queries/staking.ts +0 -154
  80. package/src/queries/utils.test.ts +0 -156
  81. package/src/queries/utils.ts +0 -145
  82. package/src/transactions/bank.ts +0 -86
  83. package/src/transactions/billing.ts +0 -286
  84. package/src/transactions/distribution.ts +0 -76
  85. package/src/transactions/gov.ts +0 -191
  86. package/src/transactions/index.ts +0 -7
  87. package/src/transactions/manifest.ts +0 -67
  88. package/src/transactions/sku.ts +0 -232
  89. package/src/transactions/staking.ts +0 -85
  90. package/src/transactions/utils.test.ts +0 -518
  91. package/src/transactions/utils.ts +0 -348
  92. package/src/types.ts +0 -497
  93. package/src/wallet/index.ts +0 -2
  94. package/src/wallet/mnemonic.ts +0 -146
  95. package/tsconfig.json +0 -23
@@ -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
- }
@@ -1,191 +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 } 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
- * Parse vote option string to VoteOption enum value from manifestjs
64
- */
65
- function parseVoteOption(optionStr: string): number {
66
- const option = optionStr.toLowerCase();
67
- switch (option) {
68
- case 'yes':
69
- case '1':
70
- return VoteOption.VOTE_OPTION_YES;
71
- case 'abstain':
72
- case '2':
73
- return VoteOption.VOTE_OPTION_ABSTAIN;
74
- case 'no':
75
- case '3':
76
- return VoteOption.VOTE_OPTION_NO;
77
- case 'no_with_veto':
78
- case 'nowithveto':
79
- case '4':
80
- return VoteOption.VOTE_OPTION_NO_WITH_VETO;
81
- default:
82
- throw new ManifestMCPError(
83
- ManifestMCPErrorCode.TX_FAILED,
84
- `Invalid vote option: ${optionStr}. Expected: yes, no, abstain, or no_with_veto`
85
- );
86
- }
87
- }
88
-
89
- /**
90
- * Route gov transaction to appropriate handler
91
- */
92
- export async function routeGovTransaction(
93
- client: SigningStargateClient,
94
- senderAddress: string,
95
- subcommand: string,
96
- args: string[],
97
- waitForConfirmation: boolean
98
- ): Promise<CosmosTxResult> {
99
- validateArgsLength(args, 'gov transaction');
100
-
101
- switch (subcommand) {
102
- case 'vote': {
103
- requireArgs(args, 2, ['proposal-id', 'option'], 'gov vote');
104
- const [proposalIdStr, optionStr] = args;
105
- const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
106
- const option = parseVoteOption(optionStr);
107
-
108
- // Extract optional metadata from args
109
- const { value: metadata = '' } = extractFlag(args, '--metadata', 'gov vote');
110
-
111
- const msg = {
112
- typeUrl: '/cosmos.gov.v1.MsgVote',
113
- value: MsgVote.fromPartial({
114
- proposalId,
115
- voter: senderAddress,
116
- option,
117
- metadata,
118
- }),
119
- };
120
-
121
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
122
- return buildTxResult('gov', 'vote', result, waitForConfirmation);
123
- }
124
-
125
- case 'weighted-vote': {
126
- requireArgs(args, 2, ['proposal-id', 'options'], 'gov weighted-vote');
127
- const [proposalIdStr, optionsStr] = args;
128
- const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
129
-
130
- // Parse weighted options (format: yes=0.5,no=0.3,abstain=0.2)
131
- const options = optionsStr.split(',').map((opt) => {
132
- const [optName, weightStr] = opt.split('=');
133
- if (!optName || !weightStr) {
134
- throw new ManifestMCPError(
135
- ManifestMCPErrorCode.TX_FAILED,
136
- `Invalid weighted vote format: ${opt}. Expected format: option=weight`
137
- );
138
- }
139
- const option = parseVoteOption(optName);
140
- // Weight is a decimal string (e.g., "0.5" -> "500000000000000000" for 18 decimals)
141
- // Use string-based conversion to avoid floating-point precision loss
142
- const weight = parseWeightToFixed18(weightStr);
143
- return { option, weight };
144
- });
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
-
155
- const msg = {
156
- typeUrl: '/cosmos.gov.v1.MsgVoteWeighted',
157
- value: MsgVoteWeighted.fromPartial({
158
- proposalId,
159
- voter: senderAddress,
160
- options,
161
- metadata: '',
162
- }),
163
- };
164
-
165
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
166
- return buildTxResult('gov', 'weighted-vote', result, waitForConfirmation);
167
- }
168
-
169
- case 'deposit': {
170
- requireArgs(args, 2, ['proposal-id', 'amount'], 'gov deposit');
171
- const [proposalIdStr, amountStr] = args;
172
- const proposalId = parseBigInt(proposalIdStr, 'proposal-id');
173
- const { amount, denom } = parseAmount(amountStr);
174
-
175
- const msg = {
176
- typeUrl: '/cosmos.gov.v1.MsgDeposit',
177
- value: MsgDeposit.fromPartial({
178
- proposalId,
179
- depositor: senderAddress,
180
- amount: [{ denom, amount }],
181
- }),
182
- };
183
-
184
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
185
- return buildTxResult('gov', 'deposit', result, waitForConfirmation);
186
- }
187
-
188
- default:
189
- throwUnsupportedSubcommand('tx', 'gov', subcommand);
190
- }
191
- }
@@ -1,7 +0,0 @@
1
- export { parseAmount, buildTxResult, parseBigInt, parseHexBytes, bytesToHex } from './utils.js';
2
- export { routeBankTransaction } from './bank.js';
3
- export { routeStakingTransaction } from './staking.js';
4
- export { routeDistributionTransaction } from './distribution.js';
5
- export { routeGovTransaction } from './gov.js';
6
- export { routeBillingTransaction } from './billing.js';
7
- export { routeManifestTransaction } from './manifest.js';
@@ -1,67 +0,0 @@
1
- import { SigningStargateClient } from '@cosmjs/stargate';
2
- import { liftedinit } from '@manifest-network/manifestjs';
3
- import { CosmosTxResult } from '../types.js';
4
- import { throwUnsupportedSubcommand } from '../modules.js';
5
- import { parseAmount, buildTxResult, validateAddress, validateArgsLength, parseColonPair, requireArgs } from './utils.js';
6
-
7
- const { MsgPayout, MsgBurnHeldBalance } = liftedinit.manifest.v1;
8
-
9
- /**
10
- * Route manifest transaction to appropriate handler
11
- */
12
- export async function routeManifestTransaction(
13
- client: SigningStargateClient,
14
- senderAddress: string,
15
- subcommand: string,
16
- args: string[],
17
- waitForConfirmation: boolean
18
- ): Promise<CosmosTxResult> {
19
- validateArgsLength(args, 'manifest transaction');
20
-
21
- switch (subcommand) {
22
- case 'payout': {
23
- requireArgs(args, 1, ['address:amount'], 'manifest payout');
24
- // Parse payout pairs (format: address:amount ...)
25
- const payoutPairs = args.map((arg) => {
26
- const [address, amountStr] = parseColonPair(arg, 'address', 'amount', 'payout pair');
27
- validateAddress(address, 'payout recipient address');
28
- const { amount, denom } = parseAmount(amountStr);
29
- return { address, coin: { denom, amount } };
30
- });
31
-
32
- const msg = {
33
- typeUrl: '/liftedinit.manifest.v1.MsgPayout',
34
- value: MsgPayout.fromPartial({
35
- authority: senderAddress,
36
- payoutPairs,
37
- }),
38
- };
39
-
40
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
41
- return buildTxResult('manifest', 'payout', result, waitForConfirmation);
42
- }
43
-
44
- case 'burn-held-balance': {
45
- requireArgs(args, 1, ['amount'], 'manifest burn-held-balance');
46
- // Parse coins to burn
47
- const burnCoins = args.map((amountStr) => {
48
- const { amount, denom } = parseAmount(amountStr);
49
- return { denom, amount };
50
- });
51
-
52
- const msg = {
53
- typeUrl: '/liftedinit.manifest.v1.MsgBurnHeldBalance',
54
- value: MsgBurnHeldBalance.fromPartial({
55
- authority: senderAddress,
56
- burnCoins,
57
- }),
58
- };
59
-
60
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
61
- return buildTxResult('manifest', 'burn-held-balance', result, waitForConfirmation);
62
- }
63
-
64
- default:
65
- throwUnsupportedSubcommand('tx', 'manifest', subcommand);
66
- }
67
- }
@@ -1,232 +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, 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,85 +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 { MsgDelegate, MsgUndelegate, MsgBeginRedelegate } = cosmos.staking.v1beta1;
8
-
9
- /**
10
- * Route staking transaction to appropriate handler
11
- */
12
- export async function routeStakingTransaction(
13
- client: SigningStargateClient,
14
- senderAddress: string,
15
- subcommand: string,
16
- args: string[],
17
- waitForConfirmation: boolean
18
- ): Promise<CosmosTxResult> {
19
- validateArgsLength(args, 'staking transaction');
20
-
21
- switch (subcommand) {
22
- case 'delegate': {
23
- requireArgs(args, 2, ['validator-address', 'amount'], 'staking delegate');
24
- const [validatorAddress, amountStr] = args;
25
- validateAddress(validatorAddress, 'validator address');
26
- const { amount, denom } = parseAmount(amountStr);
27
-
28
- const msg = {
29
- typeUrl: '/cosmos.staking.v1beta1.MsgDelegate',
30
- value: MsgDelegate.fromPartial({
31
- delegatorAddress: senderAddress,
32
- validatorAddress,
33
- amount: { denom, amount },
34
- }),
35
- };
36
-
37
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
38
- return buildTxResult('staking', 'delegate', result, waitForConfirmation);
39
- }
40
-
41
- case 'unbond':
42
- case 'undelegate': {
43
- requireArgs(args, 2, ['validator-address', 'amount'], 'staking unbond');
44
- const [validatorAddress, amountStr] = args;
45
- validateAddress(validatorAddress, 'validator address');
46
- const { amount, denom } = parseAmount(amountStr);
47
-
48
- const msg = {
49
- typeUrl: '/cosmos.staking.v1beta1.MsgUndelegate',
50
- value: MsgUndelegate.fromPartial({
51
- delegatorAddress: senderAddress,
52
- validatorAddress,
53
- amount: { denom, amount },
54
- }),
55
- };
56
-
57
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
58
- return buildTxResult('staking', 'unbond', result, waitForConfirmation);
59
- }
60
-
61
- case 'redelegate': {
62
- requireArgs(args, 3, ['src-validator', 'dst-validator', 'amount'], 'staking redelegate');
63
- const [srcValidatorAddress, dstValidatorAddress, amountStr] = args;
64
- validateAddress(srcValidatorAddress, 'source validator address');
65
- validateAddress(dstValidatorAddress, 'destination validator address');
66
- const { amount, denom } = parseAmount(amountStr);
67
-
68
- const msg = {
69
- typeUrl: '/cosmos.staking.v1beta1.MsgBeginRedelegate',
70
- value: MsgBeginRedelegate.fromPartial({
71
- delegatorAddress: senderAddress,
72
- validatorSrcAddress: srcValidatorAddress,
73
- validatorDstAddress: dstValidatorAddress,
74
- amount: { denom, amount },
75
- }),
76
- };
77
-
78
- const result = await client.signAndBroadcast(senderAddress, [msg], 'auto');
79
- return buildTxResult('staking', 'redelegate', result, waitForConfirmation);
80
- }
81
-
82
- default:
83
- throwUnsupportedSubcommand('tx', 'staking', subcommand);
84
- }
85
- }