@paylobster/cli 4.0.2 → 4.1.0

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 (44) hide show
  1. package/dist/src/commands/cascade.d.ts +3 -0
  2. package/dist/src/commands/cascade.d.ts.map +1 -0
  3. package/dist/src/commands/cascade.js +242 -0
  4. package/dist/src/commands/cascade.js.map +1 -0
  5. package/dist/src/commands/compliance.d.ts +3 -0
  6. package/dist/src/commands/compliance.d.ts.map +1 -0
  7. package/dist/src/commands/compliance.js +121 -0
  8. package/dist/src/commands/compliance.js.map +1 -0
  9. package/dist/src/commands/credit-score.d.ts +3 -0
  10. package/dist/src/commands/credit-score.d.ts.map +1 -0
  11. package/dist/src/commands/credit-score.js +174 -0
  12. package/dist/src/commands/credit-score.js.map +1 -0
  13. package/dist/src/commands/dispute.d.ts +3 -0
  14. package/dist/src/commands/dispute.d.ts.map +1 -0
  15. package/dist/src/commands/dispute.js +241 -0
  16. package/dist/src/commands/dispute.js.map +1 -0
  17. package/dist/src/commands/intent.d.ts +3 -0
  18. package/dist/src/commands/intent.d.ts.map +1 -0
  19. package/dist/src/commands/intent.js +227 -0
  20. package/dist/src/commands/intent.js.map +1 -0
  21. package/dist/src/commands/oracle.d.ts +3 -0
  22. package/dist/src/commands/oracle.d.ts.map +1 -0
  23. package/dist/src/commands/oracle.js +114 -0
  24. package/dist/src/commands/oracle.js.map +1 -0
  25. package/dist/src/commands/revenue-share.d.ts +3 -0
  26. package/dist/src/commands/revenue-share.d.ts.map +1 -0
  27. package/dist/src/commands/revenue-share.js +185 -0
  28. package/dist/src/commands/revenue-share.js.map +1 -0
  29. package/dist/src/commands/stream.d.ts +3 -0
  30. package/dist/src/commands/stream.d.ts.map +1 -0
  31. package/dist/src/commands/stream.js +213 -0
  32. package/dist/src/commands/stream.js.map +1 -0
  33. package/dist/src/index.js +16 -0
  34. package/dist/src/index.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/commands/cascade.ts +280 -0
  37. package/src/commands/compliance.ts +123 -0
  38. package/src/commands/credit-score.ts +193 -0
  39. package/src/commands/dispute.ts +274 -0
  40. package/src/commands/intent.ts +261 -0
  41. package/src/commands/oracle.ts +116 -0
  42. package/src/commands/revenue-share.ts +213 -0
  43. package/src/commands/stream.ts +244 -0
  44. package/src/index.ts +16 -0
@@ -0,0 +1,213 @@
1
+ import { Command } from 'commander';
2
+ import { success, error, info, warning, withSpinner, outputJSON, formatAddress, confirm, createTable } from '../lib/display';
3
+ import type { OutputOptions } from '../lib/types';
4
+
5
+ export function createRevenueShareCommand(): Command {
6
+ const cmd = new Command('revenue-share')
7
+ .description('Manage revenue sharing agreements');
8
+
9
+ // plob revenue-share create
10
+ cmd
11
+ .command('create')
12
+ .description('Create a revenue sharing agreement')
13
+ .requiredOption('--participants <addresses>', 'Comma-separated participant addresses')
14
+ .requiredOption('--splits <percentages>', 'Comma-separated split percentages (must sum to 100)')
15
+ .option('--json', 'Output as JSON')
16
+ .action(async (options: {
17
+ participants: string;
18
+ splits: string;
19
+ } & OutputOptions) => {
20
+ try {
21
+ const participants = options.participants.split(',').map(p => p.trim());
22
+ const splits = options.splits.split(',').map(s => parseFloat(s.trim()));
23
+
24
+ // Validate addresses
25
+ for (const participant of participants) {
26
+ if (!participant.startsWith('0x') || participant.length !== 42) {
27
+ error(`Invalid participant address: ${participant}`);
28
+ process.exit(1);
29
+ }
30
+ }
31
+
32
+ // Validate splits
33
+ if (participants.length !== splits.length) {
34
+ error('Number of participants must match number of splits');
35
+ process.exit(1);
36
+ }
37
+
38
+ for (const split of splits) {
39
+ if (isNaN(split) || split < 0 || split > 100) {
40
+ error('Each split must be between 0 and 100');
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+ const totalSplit = splits.reduce((a, b) => a + b, 0);
46
+ if (Math.abs(totalSplit - 100) > 0.01) {
47
+ error(`Splits must sum to 100 (current: ${totalSplit})`);
48
+ process.exit(1);
49
+ }
50
+
51
+ info('Creating revenue share agreement');
52
+ participants.forEach((p, i) => {
53
+ info(` ${formatAddress(p)}: ${splits[i]}%`);
54
+ });
55
+
56
+ const shareId = Math.floor(Math.random() * 1000000);
57
+
58
+ const txHash = await withSpinner(
59
+ 'Creating revenue share...',
60
+ async () => {
61
+ // Placeholder - implement actual contract call
62
+ await new Promise(resolve => setTimeout(resolve, 2000));
63
+ return '0x' + Math.random().toString(16).substring(2, 66);
64
+ }
65
+ );
66
+
67
+ if (outputJSON({
68
+ shareId,
69
+ participants,
70
+ splits,
71
+ txHash,
72
+ }, options)) {
73
+ return;
74
+ }
75
+
76
+ success('Revenue share created!');
77
+ info(`Share ID: ${shareId}`);
78
+ info(`Transaction: ${txHash}`);
79
+ } catch (err) {
80
+ error(`Failed to create revenue share: ${err}`);
81
+ process.exit(1);
82
+ }
83
+ });
84
+
85
+ // plob revenue-share deposit
86
+ cmd
87
+ .command('deposit')
88
+ .description('Deposit funds to revenue share')
89
+ .argument('<shareId>', 'Share ID')
90
+ .requiredOption('--amount <amount>', 'Amount in USDC')
91
+ .option('--json', 'Output as JSON')
92
+ .action(async (shareId: string, options: { amount: string } & OutputOptions) => {
93
+ try {
94
+ const amount = parseFloat(options.amount);
95
+ if (isNaN(amount) || amount <= 0) {
96
+ error('Invalid amount. Must be a positive number');
97
+ process.exit(1);
98
+ }
99
+
100
+ const txHash = await withSpinner(
101
+ `Depositing ${options.amount} USDC to revenue share...`,
102
+ async () => {
103
+ // Placeholder - implement actual contract call
104
+ await new Promise(resolve => setTimeout(resolve, 1500));
105
+ return '0x' + Math.random().toString(16).substring(2, 66);
106
+ }
107
+ );
108
+
109
+ if (outputJSON({
110
+ shareId,
111
+ amount: options.amount,
112
+ txHash,
113
+ }, options)) {
114
+ return;
115
+ }
116
+
117
+ success('Deposit successful!');
118
+ info(`Share ID: ${shareId}`);
119
+ info(`Amount: ${options.amount} USDC`);
120
+ info(`Transaction: ${txHash}`);
121
+ } catch (err) {
122
+ error(`Failed to deposit: ${err}`);
123
+ process.exit(1);
124
+ }
125
+ });
126
+
127
+ // plob revenue-share distribute
128
+ cmd
129
+ .command('distribute')
130
+ .description('Distribute revenue to participants')
131
+ .argument('<shareId>', 'Share ID')
132
+ .option('--yes', 'Skip confirmation')
133
+ .option('--json', 'Output as JSON')
134
+ .action(async (shareId: string, options: { yes?: boolean } & OutputOptions) => {
135
+ try {
136
+ if (!options.yes) {
137
+ const confirmed = await confirm(`Distribute revenue for share ${shareId}?`);
138
+ if (!confirmed) {
139
+ info('Cancelled');
140
+ process.exit(0);
141
+ }
142
+ }
143
+
144
+ const txHash = await withSpinner(
145
+ 'Distributing revenue...',
146
+ async () => {
147
+ // Placeholder - implement actual contract call
148
+ await new Promise(resolve => setTimeout(resolve, 2000));
149
+ return '0x' + Math.random().toString(16).substring(2, 66);
150
+ }
151
+ );
152
+
153
+ if (outputJSON({
154
+ shareId,
155
+ txHash,
156
+ }, options)) {
157
+ return;
158
+ }
159
+
160
+ success('Revenue distributed!');
161
+ info(`Share ID: ${shareId}`);
162
+ info(`Transaction: ${txHash}`);
163
+ } catch (err) {
164
+ error(`Failed to distribute: ${err}`);
165
+ process.exit(1);
166
+ }
167
+ });
168
+
169
+ // plob revenue-share get
170
+ cmd
171
+ .command('get')
172
+ .description('Get revenue share details')
173
+ .argument('<shareId>', 'Share ID')
174
+ .option('--json', 'Output as JSON')
175
+ .action(async (shareId: string, options: OutputOptions) => {
176
+ try {
177
+ // Placeholder data
178
+ const share = {
179
+ id: shareId,
180
+ totalDeposited: '1000 USDC',
181
+ totalDistributed: '600 USDC',
182
+ pending: '400 USDC',
183
+ participants: [
184
+ { address: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb', split: 60, received: '360 USDC' },
185
+ { address: '0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199', split: 40, received: '240 USDC' },
186
+ ],
187
+ createdAt: new Date().toISOString(),
188
+ };
189
+
190
+ if (outputJSON(share, options)) {
191
+ return;
192
+ }
193
+
194
+ console.log();
195
+ console.log('Share ID: ', share.id);
196
+ console.log('Total Deposited: ', share.totalDeposited);
197
+ console.log('Total Distributed: ', share.totalDistributed);
198
+ console.log('Pending: ', share.pending);
199
+ console.log('Created: ', share.createdAt);
200
+ console.log();
201
+ console.log('Participants:');
202
+ share.participants.forEach(p => {
203
+ console.log(` ${formatAddress(p.address)}: ${p.split}% (received ${p.received})`);
204
+ });
205
+ console.log();
206
+ } catch (err) {
207
+ error(`Failed to get revenue share: ${err}`);
208
+ process.exit(1);
209
+ }
210
+ });
211
+
212
+ return cmd;
213
+ }
@@ -0,0 +1,244 @@
1
+ import { Command } from 'commander';
2
+ import { success, error, info, withSpinner, outputJSON, formatAddress, confirm, createTable } from '../lib/display';
3
+ import type { OutputOptions } from '../lib/types';
4
+
5
+ export function createStreamCommand(): Command {
6
+ const cmd = new Command('stream')
7
+ .description('Manage payment streams');
8
+
9
+ // plob stream create
10
+ cmd
11
+ .command('create')
12
+ .description('Create a new payment stream')
13
+ .requiredOption('--to <address>', 'Recipient address')
14
+ .requiredOption('--amount <amount>', 'Total amount in USDC')
15
+ .requiredOption('--duration <duration>', 'Duration (e.g., 30d, 1h, 60m)')
16
+ .option('--interval <interval>', 'Payment interval (e.g., 1d, 1h)', '1d')
17
+ .option('--json', 'Output as JSON')
18
+ .action(async (options: {
19
+ to: string;
20
+ amount: string;
21
+ duration: string;
22
+ interval: string;
23
+ } & OutputOptions) => {
24
+ try {
25
+ // Validate address
26
+ if (!options.to.startsWith('0x') || options.to.length !== 42) {
27
+ error('Invalid recipient address format');
28
+ process.exit(1);
29
+ }
30
+
31
+ // Validate amount
32
+ const amount = parseFloat(options.amount);
33
+ if (isNaN(amount) || amount <= 0) {
34
+ error('Invalid amount. Must be a positive number');
35
+ process.exit(1);
36
+ }
37
+
38
+ info(`Creating stream: ${options.amount} USDC over ${options.duration}`);
39
+ info(`To: ${formatAddress(options.to)}`);
40
+ info(`Interval: ${options.interval}`);
41
+
42
+ // TODO: Implement actual stream creation
43
+ const streamId = Math.floor(Math.random() * 1000000); // Placeholder
44
+
45
+ const txHash = await withSpinner(
46
+ 'Creating payment stream...',
47
+ async () => {
48
+ // Placeholder - implement actual contract call
49
+ await new Promise(resolve => setTimeout(resolve, 2000));
50
+ return '0x' + Math.random().toString(16).substring(2, 66);
51
+ }
52
+ );
53
+
54
+ if (outputJSON({
55
+ streamId,
56
+ txHash,
57
+ to: options.to,
58
+ amount: options.amount,
59
+ duration: options.duration,
60
+ interval: options.interval,
61
+ }, options)) {
62
+ return;
63
+ }
64
+
65
+ success('Payment stream created!');
66
+ info(`Stream ID: ${streamId}`);
67
+ info(`Transaction: ${txHash}`);
68
+ } catch (err) {
69
+ error(`Failed to create stream: ${err}`);
70
+ process.exit(1);
71
+ }
72
+ });
73
+
74
+ // plob stream cancel
75
+ cmd
76
+ .command('cancel')
77
+ .description('Cancel a payment stream')
78
+ .argument('<streamId>', 'Stream ID')
79
+ .option('--yes', 'Skip confirmation')
80
+ .option('--json', 'Output as JSON')
81
+ .action(async (streamId: string, options: { yes?: boolean } & OutputOptions) => {
82
+ try {
83
+ if (!options.yes) {
84
+ const confirmed = await confirm(`Cancel stream ${streamId}?`);
85
+ if (!confirmed) {
86
+ info('Cancelled');
87
+ process.exit(0);
88
+ }
89
+ }
90
+
91
+ const txHash = await withSpinner(
92
+ 'Cancelling stream...',
93
+ async () => {
94
+ // Placeholder - implement actual contract call
95
+ await new Promise(resolve => setTimeout(resolve, 1500));
96
+ return '0x' + Math.random().toString(16).substring(2, 66);
97
+ }
98
+ );
99
+
100
+ if (outputJSON({ streamId, txHash }, options)) {
101
+ return;
102
+ }
103
+
104
+ success(`Stream ${streamId} cancelled!`);
105
+ info(`Transaction: ${txHash}`);
106
+ } catch (err) {
107
+ error(`Failed to cancel stream: ${err}`);
108
+ process.exit(1);
109
+ }
110
+ });
111
+
112
+ // plob stream list
113
+ cmd
114
+ .command('list')
115
+ .description('List your payment streams')
116
+ .option('--json', 'Output as JSON')
117
+ .action(async (options: OutputOptions) => {
118
+ try {
119
+ // Placeholder data
120
+ const streams = [
121
+ {
122
+ id: 1,
123
+ to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
124
+ amount: '1000 USDC',
125
+ streamed: '300 USDC',
126
+ remaining: '700 USDC',
127
+ status: 'active',
128
+ },
129
+ {
130
+ id: 2,
131
+ to: '0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199',
132
+ amount: '500 USDC',
133
+ streamed: '500 USDC',
134
+ remaining: '0 USDC',
135
+ status: 'completed',
136
+ },
137
+ ];
138
+
139
+ if (outputJSON(streams, options)) {
140
+ return;
141
+ }
142
+
143
+ if (streams.length === 0) {
144
+ info('No streams found');
145
+ return;
146
+ }
147
+
148
+ const table = createTable({
149
+ head: ['ID', 'To', 'Amount', 'Streamed', 'Remaining', 'Status'],
150
+ });
151
+
152
+ for (const stream of streams) {
153
+ table.push([
154
+ stream.id,
155
+ formatAddress(stream.to),
156
+ stream.amount,
157
+ stream.streamed,
158
+ stream.remaining,
159
+ stream.status,
160
+ ]);
161
+ }
162
+
163
+ console.log(table.toString());
164
+ } catch (err) {
165
+ error(`Failed to list streams: ${err}`);
166
+ process.exit(1);
167
+ }
168
+ });
169
+
170
+ // plob stream get
171
+ cmd
172
+ .command('get')
173
+ .description('Get stream details')
174
+ .argument('<streamId>', 'Stream ID')
175
+ .option('--json', 'Output as JSON')
176
+ .action(async (streamId: string, options: OutputOptions) => {
177
+ try {
178
+ // Placeholder data
179
+ const stream = {
180
+ id: streamId,
181
+ from: '0x1234567890123456789012345678901234567890',
182
+ to: '0x0987654321098765432109876543210987654321',
183
+ totalAmount: '1000 USDC',
184
+ streamedAmount: '300 USDC',
185
+ remainingAmount: '700 USDC',
186
+ startTime: new Date().toISOString(),
187
+ duration: '30 days',
188
+ interval: '1 day',
189
+ status: 'active',
190
+ };
191
+
192
+ if (outputJSON(stream, options)) {
193
+ return;
194
+ }
195
+
196
+ console.log();
197
+ console.log('Stream ID: ', stream.id);
198
+ console.log('From: ', stream.from);
199
+ console.log('To: ', stream.to);
200
+ console.log('Total Amount: ', stream.totalAmount);
201
+ console.log('Streamed: ', stream.streamedAmount);
202
+ console.log('Remaining: ', stream.remainingAmount);
203
+ console.log('Start Time: ', stream.startTime);
204
+ console.log('Duration: ', stream.duration);
205
+ console.log('Interval: ', stream.interval);
206
+ console.log('Status: ', stream.status);
207
+ console.log();
208
+ } catch (err) {
209
+ error(`Failed to get stream: ${err}`);
210
+ process.exit(1);
211
+ }
212
+ });
213
+
214
+ // plob stream withdraw
215
+ cmd
216
+ .command('withdraw')
217
+ .description('Withdraw from a stream')
218
+ .argument('<streamId>', 'Stream ID')
219
+ .option('--json', 'Output as JSON')
220
+ .action(async (streamId: string, options: OutputOptions) => {
221
+ try {
222
+ const txHash = await withSpinner(
223
+ 'Withdrawing from stream...',
224
+ async () => {
225
+ // Placeholder - implement actual contract call
226
+ await new Promise(resolve => setTimeout(resolve, 1500));
227
+ return '0x' + Math.random().toString(16).substring(2, 66);
228
+ }
229
+ );
230
+
231
+ if (outputJSON({ streamId, txHash }, options)) {
232
+ return;
233
+ }
234
+
235
+ success('Withdrawal successful!');
236
+ info(`Transaction: ${txHash}`);
237
+ } catch (err) {
238
+ error(`Failed to withdraw: ${err}`);
239
+ process.exit(1);
240
+ }
241
+ });
242
+
243
+ return cmd;
244
+ }
package/src/index.ts CHANGED
@@ -9,6 +9,14 @@ import { createEscrowCommand } from './commands/escrow';
9
9
  import { createMandateCommand } from './commands/mandate';
10
10
  import { createPayCommand } from './commands/pay';
11
11
  import { createReputationCommand } from './commands/reputation';
12
+ import { createStreamCommand } from './commands/stream';
13
+ import { createDisputeCommand } from './commands/dispute';
14
+ import { createCreditScoreCommand } from './commands/credit-score';
15
+ import { createCascadeCommand } from './commands/cascade';
16
+ import { createIntentCommand } from './commands/intent';
17
+ import { createComplianceCommand } from './commands/compliance';
18
+ import { createOracleCommand } from './commands/oracle';
19
+ import { createRevenueShareCommand } from './commands/revenue-share';
12
20
  import chalk from 'chalk';
13
21
 
14
22
  // Load environment variables from .env file if present
@@ -44,6 +52,14 @@ program.addCommand(createEscrowCommand());
44
52
  program.addCommand(createMandateCommand());
45
53
  program.addCommand(createPayCommand());
46
54
  program.addCommand(createReputationCommand());
55
+ program.addCommand(createStreamCommand());
56
+ program.addCommand(createDisputeCommand());
57
+ program.addCommand(createCreditScoreCommand());
58
+ program.addCommand(createCascadeCommand());
59
+ program.addCommand(createIntentCommand());
60
+ program.addCommand(createComplianceCommand());
61
+ program.addCommand(createOracleCommand());
62
+ program.addCommand(createRevenueShareCommand());
47
63
 
48
64
  // Handle errors
49
65
  program.exitOverride((err) => {