hive-stream 3.0.3 → 3.0.4

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 CHANGED
@@ -54,6 +54,7 @@ CamelCase config keys are recommended for readability. Legacy uppercase keys are
54
54
 
55
55
  ```
56
56
  const options = {
57
+ env: true,
57
58
  activeKey: '',
58
59
  postingKey: '',
59
60
  jsonId: 'hivestream',
@@ -77,6 +78,8 @@ const options = {
77
78
  const ss = new Streamer(options);
78
79
  ```
79
80
 
81
+ If you prefer loading credentials from environment variables, pass `env: true`. Hive Stream will read canonical keys like `ACTIVE_KEY` and `USERNAME`, plus Hive-friendly aliases like `HIVE_ACCOUNT` and `HIVE_ACTIVE_KEY`.
82
+
80
83
  If you want the built-in API without starting block streaming yet:
81
84
 
82
85
  ```javascript
@@ -102,8 +105,9 @@ These event subscriptions and contract actions are separate paths: subscriptions
102
105
  #### Watch for transfers
103
106
 
104
107
  ```javascript
105
- ss.onTransfer('myaccount', (op, { sender, amount, asset, memo }, blockNumber, blockId, prevBlockId, trxId, blockTime) => {
108
+ ss.onTransfer('myaccount', (op, blockNumber, blockId, prevBlockId, trxId, blockTime) => {
106
109
  // Fires only when op.to === 'myaccount'
110
+ // Parse op.amount yourself, for example: "1.000 HIVE"
107
111
  });
108
112
  ```
109
113
 
@@ -180,6 +184,20 @@ transferHiveTokens(from, to, amount, symbol, memo = '') {
180
184
  }
181
185
  ```
182
186
 
187
+ ### Burn Hive (HIVE or HBD)
188
+ ```javascript
189
+ burnHiveTokens(from, amount, symbol, memo = '') {
190
+
191
+ }
192
+ ```
193
+
194
+ ### Burn A Percentage Of An Incoming Transfer
195
+ ```javascript
196
+ burnTransferPercentage(from, transferOrAmount, percentage, memo = '', allowedSymbols = ['HIVE', 'HBD']) {
197
+
198
+ }
199
+ ```
200
+
183
201
  ### Transfer Hive Engine Tokens
184
202
  ```javascript
185
203
  transferHiveEngineTokens(from, to, symbol, quantity, memo = '') {
@@ -187,6 +205,13 @@ transferHiveEngineTokens(from, to, symbol, quantity, memo = '') {
187
205
  }
188
206
  ```
189
207
 
208
+ ### Burn Hive Engine Tokens
209
+ ```javascript
210
+ burnHiveEngineTokens(from, symbol, quantity, memo = '') {
211
+
212
+ }
213
+ ```
214
+
190
215
  ### Transfer Hive Engine Tokens to Multiple Accounts
191
216
  ```javascript
192
217
  transferHiveEngineTokensMultiple(from, accounts = [], symbol, memo = '', amount = '0') {
@@ -194,6 +219,150 @@ transferHiveEngineTokensMultiple(from, accounts = [], symbol, memo = '', amount
194
219
  }
195
220
  ```
196
221
 
222
+ ### Burn part of an inbound transfer safely
223
+ ```javascript
224
+ const { Streamer } = require('hive-stream');
225
+
226
+ const ss = new Streamer({ env: true });
227
+
228
+ ss.flows.autoBurnIncomingTransfers({
229
+ percentage: 67,
230
+ memo: ({ transaction }) => `Auto-burn 67% of ${transaction.id}`
231
+ });
232
+
233
+ ss.start();
234
+ ```
235
+
236
+ ### Forward inbound transfers automatically
237
+ ```javascript
238
+ const { Streamer } = require('hive-stream');
239
+
240
+ const ss = new Streamer({ env: true });
241
+
242
+ ss.flows.autoForwardIncomingTransfers({
243
+ to: 'treasury',
244
+ percentage: 100,
245
+ memo: ({ transaction }) => `Forwarded from ${transaction.id}`
246
+ });
247
+
248
+ ss.start();
249
+ ```
250
+
251
+ ### Split inbound transfers across multiple accounts
252
+ ```javascript
253
+ const { Streamer } = require('hive-stream');
254
+
255
+ const ss = new Streamer({ env: true });
256
+
257
+ ss.flows.autoSplitIncomingTransfers({
258
+ recipients: [
259
+ { account: 'null', percentage: 69, memo: 'Feel the burn' },
260
+ { account: 'treasury' }
261
+ ]
262
+ });
263
+
264
+ ss.start();
265
+ ```
266
+
267
+ ### Refund inbound transfers automatically
268
+ ```javascript
269
+ const { Streamer } = require('hive-stream');
270
+
271
+ const ss = new Streamer({ env: true });
272
+
273
+ ss.flows.autoRefundIncomingTransfers({
274
+ memo: ({ transfer }) => `Refunded ${transfer.rawAmount} to ${transfer.from}`
275
+ });
276
+
277
+ ss.start();
278
+ ```
279
+
280
+ ### Route inbound transfers with one flow
281
+ ```javascript
282
+ const { Streamer } = require('hive-stream');
283
+
284
+ const ss = new Streamer({ env: true });
285
+
286
+ ss.flows.autoRouteIncomingTransfers({
287
+ routes: [
288
+ { type: 'burn', percentage: 67, memo: 'Auto-burn 67%' },
289
+ { to: 'treasury', memo: 'Treasury remainder' }
290
+ ]
291
+ });
292
+
293
+ ss.start();
294
+ ```
295
+
296
+ ### Route grouped payouts with an optional on-top donation
297
+ ```javascript
298
+ const { Streamer } = require('hive-stream');
299
+
300
+ const ss = new Streamer({ env: true });
301
+
302
+ ss.flows.autoRouteIncomingTransfers({
303
+ account: 'tweet-backup',
304
+ routes: [
305
+ { to: 'tweet-catcher', percentage: 20, memo: 'Tweet watcher share' },
306
+ { group: [{ account: 'node-1' }, { account: 'node-2' }], percentage: 4, memo: 'Node operator share' },
307
+ { group: [{ account: 'wit-1' }, { account: 'wit-2' }], percentage: 6, memo: 'Witness share' },
308
+ { type: 'burn', percentage: 70, memo: 'Burn share' },
309
+ { to: 'platform-op', mode: 'onTop', percentage: 8, memo: 'Optional platform donation' }
310
+ ]
311
+ });
312
+
313
+ ss.start();
314
+ ```
315
+
316
+ ### Chain inbound transfer flows with a builder
317
+ ```javascript
318
+ const { Streamer } = require('hive-stream');
319
+
320
+ const ss = new Streamer({ env: true });
321
+
322
+ ss.flows
323
+ .incomingTransfers()
324
+ .burn(69, 'Feel the burn')
325
+ .remainderTo('treasury', 'Treasury remainder')
326
+ .start();
327
+
328
+ ss.start();
329
+ ```
330
+
331
+ ### Preview a payout plan before the flow starts
332
+ ```javascript
333
+ const { Streamer } = require('hive-stream');
334
+
335
+ const ss = new Streamer({ env: true });
336
+
337
+ const plan = ss.flows
338
+ .incomingTransfers('tweet-backup')
339
+ .forwardTo('tweet-catcher', 20, 'Tweet watcher share')
340
+ .forwardGroup([{ account: 'node-1' }, { account: 'node-2' }], 4, { memo: 'Node operator share' })
341
+ .remainderToGroup([{ account: 'wit-1' }, { account: 'wit-2' }], { memo: 'Witness share' })
342
+ .burn(70, 'Burn share')
343
+ .donateOnTop('platform-op', 8, 'Optional platform donation')
344
+ .plan({ from: 'buyer', to: 'tweet-backup', amount: '1.080 HBD', memo: 'Archive this tweet' });
345
+
346
+ console.log(plan.baseAmount); // "1.000"
347
+ console.log(plan.onTopAmount); // "0.080"
348
+ console.log(plan.routes);
349
+ ```
350
+
351
+ `flows.autoBurnIncomingTransfers()` is the quickest high-level option for the burn case. `flows.autoForwardIncomingTransfers()` covers treasury forwarding, `flows.autoSplitIncomingTransfers()` handles common revenue-sharing, and `flows.autoRefundIncomingTransfers()` is useful for rejecting unsupported payments. `flows.autoRouteIncomingTransfers()` is the general router for mixed burn/transfer/group routes, and `flows.planIncomingTransferRoutes()` previews the same math without broadcasting. In base routes, one destination can omit `percentage`/`basisPoints` and automatically receive the remainder. Routes with `mode: 'onTop'` are treated as a surcharge on the base payout amount, so a `1.000 HBD` base payout with an `8%` donation should arrive as `1.080 HBD`.
352
+
353
+ `flows.incomingTransfers()` is the chainable version of the same idea. Single-step builders compile down to `autoBurnIncomingTransfers()`, `autoForwardIncomingTransfers()`, or `autoRefundIncomingTransfers()`. Multi-step builders compile down to `autoRouteIncomingTransfers()`, and `.plan(...)` gives you the exact rounded output before any transfer is sent.
354
+
355
+ ### Money Namespace
356
+ ```javascript
357
+ const ss = new Streamer();
358
+
359
+ ss.money.parseAssetAmount('1.000 HIVE');
360
+ ss.money.formatAmount('1.2399'); // "1.239"
361
+ ss.money.calculatePercentageAmount('10.000', 12.5); // "1.250"
362
+ ss.money.splitAmountByBasisPoints('1.000', [6900, 3100]); // ["0.690", "0.310"]
363
+ ss.money.splitAmountByWeights('1.080', [10000, 800]); // ["1.000", "0.080"]
364
+ ```
365
+
197
366
  ### Issue Hive Engine Tokens
198
367
  ```javascript
199
368
  issueHiveEngineTokens(from, to, symbol, quantity, memo = '') {
@@ -244,6 +413,59 @@ updateProposalVotes({ voter, proposal_ids, approve }, signingKeys?)
244
413
  removeProposals({ proposal_owner, proposal_ids }, signingKeys?)
245
414
  ```
246
415
 
416
+ ### Operation Builders
417
+ ```javascript
418
+ const { Streamer } = require('hive-stream');
419
+
420
+ const ss = new Streamer({ env: true });
421
+
422
+ await ss.ops
423
+ .transfer()
424
+ .from('alice')
425
+ .to('bob')
426
+ .hive(1.25)
427
+ .memo('Builder transfer example')
428
+ .send();
429
+
430
+ await ss.ops
431
+ .createProposal()
432
+ .creator('alice')
433
+ .receiver('treasury')
434
+ .startDate(new Date('2026-04-01T00:00:00.000Z'))
435
+ .endDate(new Date('2026-05-01T00:00:00.000Z'))
436
+ .dailyHbd(12.5)
437
+ .subject('Builder proposal example')
438
+ .permlink('builder-proposal-example')
439
+ .send();
440
+ ```
441
+
442
+ Additional chainable write builders are available for Hive Engine token ops and governance/voting:
443
+
444
+ ```javascript
445
+ await ss.ops
446
+ .transferEngine()
447
+ .from('alice')
448
+ .to('bob')
449
+ .symbol('BEE')
450
+ .quantity('1.23456')
451
+ .memo('Engine transfer')
452
+ .send();
453
+
454
+ await ss.ops
455
+ .voteProposals()
456
+ .voter('alice')
457
+ .ids(1, 2, 3)
458
+ .approve()
459
+ .send();
460
+
461
+ await ss.ops
462
+ .upvote()
463
+ .author('bob')
464
+ .permlink('my-post')
465
+ .weight(25)
466
+ .send();
467
+ ```
468
+
247
469
  ### Upvote/Downvote Posts
248
470
  ```javascript
249
471
  upvote(votePercentage = '100.0', username, permlink) {
@@ -374,6 +596,21 @@ Sample snippets for the newest contracts live in `examples/contracts/`:
374
596
  - `examples/contracts/tipjar.ts`
375
597
  - `examples/contracts/exchange.ts`
376
598
 
599
+ Higher-level flow examples live in `examples/flows/`:
600
+
601
+ - `examples/flows/auto-burn.ts`
602
+ - `examples/flows/auto-forward.ts`
603
+ - `examples/flows/auto-split.ts`
604
+ - `examples/flows/auto-refund.ts`
605
+ - `examples/flows/builder-burn-route.ts`
606
+ - `examples/flows/grouped-route-on-top.ts`
607
+ - `examples/flows/builder-payout-plan.ts`
608
+
609
+ Chainable operation examples live in `examples/ops/`:
610
+
611
+ - `examples/ops/transfer-builder.ts`
612
+ - `examples/ops/proposal-builder.ts`
613
+
377
614
  ## Time-based Actions
378
615
 
379
616
  It's like a cron job for your contracts. Time-based actions allow you to execute contract functions over a wide variety of different periods. Want to call a function every 3 seconds block time or want to call a function once per day? Time-based actions are an easy way to run time code.
@@ -0,0 +1,176 @@
1
+ import type { Streamer } from './streamer';
2
+ import type { BurnOperationBuilder, EscrowTransferBuilder, FlowAllocationInput, FlowDedupeStore, FlowGroupRecipient, FlowGroupSplitStrategy, FlowMemoInput, FlowSubscriptionHandle, HiveEngineBurnBuilder, HiveEngineIssueBuilder, HiveEngineTransferBuilder, IncomingTransferFlowBuilder, PlannedIncomingTransferRoutes, ProposalBuilder, ProposalVotesBuilder, RemoveProposalsBuilder, RecurrentTransferBuilder, TransferEvent, TransferOperationBuilder, VoteBuilder } from './types/hive-stream';
3
+ export declare class IncomingTransfersBuilder implements IncomingTransferFlowBuilder {
4
+ private readonly streamer;
5
+ private account?;
6
+ private allowedSymbols?;
7
+ private dedupeStore?;
8
+ private ignoreZeroAmountValue?;
9
+ private errorHandler?;
10
+ private defaultMemo?;
11
+ private steps;
12
+ constructor(streamer: Streamer, account?: string);
13
+ forAccount(account: string): this;
14
+ allowSymbols(...symbols: string[]): this;
15
+ memo(memo: FlowMemoInput): this;
16
+ dedupeWith(store: FlowDedupeStore): this;
17
+ ignoreZeroAmount(ignore?: boolean): this;
18
+ onError(handler: (error: unknown, event: TransferEvent) => void | Promise<void>): this;
19
+ burn(allocation: FlowAllocationInput, memo?: FlowMemoInput): this;
20
+ burnOnTop(allocation: FlowAllocationInput, memo?: FlowMemoInput): this;
21
+ forwardTo(to: string, allocation?: FlowAllocationInput, memo?: FlowMemoInput): this;
22
+ forwardOnTop(to: string, allocation: FlowAllocationInput, memo?: FlowMemoInput): this;
23
+ donateOnTop(to: string, allocation: FlowAllocationInput, memo?: FlowMemoInput): this;
24
+ forwardGroup(recipients: FlowGroupRecipient[], allocation: FlowAllocationInput, options?: {
25
+ memo?: FlowMemoInput;
26
+ split?: FlowGroupSplitStrategy;
27
+ }): this;
28
+ forwardGroupOnTop(recipients: FlowGroupRecipient[], allocation: FlowAllocationInput, options?: {
29
+ memo?: FlowMemoInput;
30
+ split?: FlowGroupSplitStrategy;
31
+ }): this;
32
+ remainderTo(to: string, memo?: FlowMemoInput): this;
33
+ remainderToGroup(recipients: FlowGroupRecipient[], options?: {
34
+ memo?: FlowMemoInput;
35
+ split?: FlowGroupSplitStrategy;
36
+ }): this;
37
+ refund(memo?: FlowMemoInput): this;
38
+ refundPortion(allocation: FlowAllocationInput, memo?: FlowMemoInput): this;
39
+ remainderToSender(memo?: FlowMemoInput): this;
40
+ plan(transfer: string | TransferEvent | {
41
+ amount?: string;
42
+ from?: string;
43
+ to?: string;
44
+ memo?: string;
45
+ }): PlannedIncomingTransferRoutes;
46
+ start(): FlowSubscriptionHandle;
47
+ private buildRoutes;
48
+ }
49
+ export declare class HiveTransferBuilder implements TransferOperationBuilder {
50
+ private readonly streamer;
51
+ private state;
52
+ constructor(streamer: Streamer);
53
+ from(account: string): this;
54
+ to(account: string): this;
55
+ amount(amount: string | number, symbol?: string): this;
56
+ hive(amount: string | number): this;
57
+ hbd(amount: string | number): this;
58
+ memo(memo: string): this;
59
+ send(): any;
60
+ }
61
+ export declare class HiveBurnBuilder implements BurnOperationBuilder {
62
+ private readonly streamer;
63
+ private state;
64
+ constructor(streamer: Streamer);
65
+ from(account: string): this;
66
+ amount(amount: string | number, symbol?: string): this;
67
+ hive(amount: string | number): this;
68
+ hbd(amount: string | number): this;
69
+ memo(memo: string): this;
70
+ send(): any;
71
+ }
72
+ export declare class HiveEscrowTransferBuilder implements EscrowTransferBuilder {
73
+ private readonly streamer;
74
+ private state;
75
+ constructor(streamer: Streamer);
76
+ from(account: string): this;
77
+ to(account: string): this;
78
+ agent(account: string): this;
79
+ id(escrowId: number): this;
80
+ hive(amount: string | number): this;
81
+ hbd(amount: string | number): this;
82
+ fee(amount: string | number, symbol?: string): this;
83
+ ratificationDeadline(value: string | Date): this;
84
+ expiration(value: string | Date): this;
85
+ jsonMeta(meta: string | Record<string, any>): this;
86
+ send(signingKeys?: string | string[]): any;
87
+ }
88
+ export declare class HiveRecurrentTransferBuilder implements RecurrentTransferBuilder {
89
+ private readonly streamer;
90
+ private state;
91
+ constructor(streamer: Streamer);
92
+ from(account: string): this;
93
+ to(account: string): this;
94
+ amount(amount: string | number, symbol?: string): this;
95
+ hive(amount: string | number): this;
96
+ hbd(amount: string | number): this;
97
+ memo(memo: string): this;
98
+ recurrence(value: number): this;
99
+ executions(value: number): this;
100
+ send(signingKeys?: string | string[]): any;
101
+ }
102
+ export declare class HiveProposalBuilder implements ProposalBuilder {
103
+ private readonly streamer;
104
+ private state;
105
+ constructor(streamer: Streamer);
106
+ creator(account: string): this;
107
+ receiver(account: string): this;
108
+ startDate(value: string | Date): this;
109
+ endDate(value: string | Date): this;
110
+ dailyPay(amount: string | number, symbol?: string): this;
111
+ dailyHive(amount: string | number): this;
112
+ dailyHbd(amount: string | number): this;
113
+ subject(value: string): this;
114
+ permlink(value: string): this;
115
+ send(signingKeys?: string | string[]): any;
116
+ }
117
+ export declare class HiveEngineTokenTransferBuilder implements HiveEngineTransferBuilder {
118
+ private readonly streamer;
119
+ private state;
120
+ constructor(streamer: Streamer);
121
+ from(account: string): this;
122
+ to(account: string): this;
123
+ symbol(symbol: string): this;
124
+ quantity(quantity: string | number): this;
125
+ memo(memo: string): this;
126
+ send(): any;
127
+ }
128
+ export declare class HiveEngineTokenBurnBuilder implements HiveEngineBurnBuilder {
129
+ private readonly streamer;
130
+ private state;
131
+ constructor(streamer: Streamer);
132
+ from(account: string): this;
133
+ symbol(symbol: string): this;
134
+ quantity(quantity: string | number): this;
135
+ memo(memo: string): this;
136
+ send(): any;
137
+ }
138
+ export declare class HiveEngineTokenIssueBuilder implements HiveEngineIssueBuilder {
139
+ private readonly streamer;
140
+ private state;
141
+ constructor(streamer: Streamer);
142
+ from(account: string): this;
143
+ to(account: string): this;
144
+ symbol(symbol: string): this;
145
+ quantity(quantity: string | number): this;
146
+ memo(memo: string): this;
147
+ send(): any;
148
+ }
149
+ export declare class HiveProposalVotesBuilder implements ProposalVotesBuilder {
150
+ private readonly streamer;
151
+ private state;
152
+ constructor(streamer: Streamer);
153
+ voter(account: string): this;
154
+ ids(...proposalIds: number[]): this;
155
+ approve(value?: boolean): this;
156
+ reject(): this;
157
+ send(signingKeys?: string | string[]): any;
158
+ }
159
+ export declare class HiveRemoveProposalsBuilder implements RemoveProposalsBuilder {
160
+ private readonly streamer;
161
+ private state;
162
+ constructor(streamer: Streamer);
163
+ owner(account: string): this;
164
+ ids(...proposalIds: number[]): this;
165
+ send(signingKeys?: string | string[]): any;
166
+ }
167
+ export declare class HiveVoteBuilder implements VoteBuilder {
168
+ private readonly streamer;
169
+ private readonly direction;
170
+ private state;
171
+ constructor(streamer: Streamer, direction: 'upvote' | 'downvote');
172
+ author(account: string): this;
173
+ permlink(value: string): this;
174
+ weight(value: string | number): this;
175
+ send(): any;
176
+ }