@usepiper/sdk 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Piper-Org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # 🧰 Piper TypeScript SDK
2
+
3
+ The official **TypeScript SDK** for the [Piper Protocol](https://github.com/piper-protocol) — a programmable payment streaming primitive on Sui.
4
+
5
+ `@usepiper/sdk` provides a clean, typed interface for building **Programmable Transaction Blocks (PTBs)** that interact with the Piper Move contracts. No need to manually construct Move calls or juggle `Coin` objects — the SDK handles the entire flow, enabling you to integrate per‑second streaming, DCA, and pay‑per‑use billing into your dApp with just a few lines of code.
6
+
7
+ ---
8
+
9
+ ## 📦 Installation
10
+
11
+ ```bash
12
+ npm install @usepiper/sdk @mysten/sui
13
+ ```
14
+
15
+ > **Note:** The SDK depends on `@mysten/sui` (the standard Sui TypeScript library) for `Transaction`, `TransactionArgument`, and other core types.
16
+
17
+ ---
18
+
19
+ ## 🚀 Quick Start
20
+
21
+ ### 1. Configure the Piper Package ID
22
+
23
+ Before using any function, set the package ID of the deployed Piper Move contract. You only need to do this **once** at application startup. The SDK ships with the testnet package ID as a default.
24
+
25
+ ```typescript
26
+ import { Piper } from '@usepiper/sdk';
27
+
28
+ // Optional — testnet is pre-configured
29
+ Piper.setPackageId('0xYOUR_MAINNET_PACKAGE_ID');
30
+ ```
31
+
32
+ ### 2. Import and Use in a Transaction
33
+
34
+ All SDK functions operate on a `Transaction` object from `@mysten/sui`. You build up a transaction, add Piper commands, and then sign & execute it with your wallet.
35
+
36
+ ```typescript
37
+ import { Transaction } from '@mysten/sui/transactions';
38
+ import { Piper } from '@usepiper/sdk';
39
+
40
+ const tx = new Transaction();
41
+
42
+ // Create a continuous stream
43
+ const stream = Piper.createContinuousStream(tx, {
44
+ coin: myUsdcCoinObject,
45
+ coinType: '0x<usdc_package>::usdc::USDC',
46
+ flowRate: 38, // 38 microunits/second → ~100 USDC/month
47
+ recipient: '0xRecipientAddress',
48
+ });
49
+
50
+ // The returned stream must be transferred or shared
51
+ tx.transferObjects([stream], tx.pure.address(senderAddress));
52
+
53
+ // Sign and execute via wallet
54
+ const result = await client.signAndExecuteTransaction({
55
+ signer: keypair,
56
+ transaction: tx,
57
+ });
58
+ ```
59
+
60
+ All functions are **pure** — they don't submit transactions or manage state. They simply append Move calls to the transaction you provide. The SDK automatically injects the Sui `Clock` object where required.
61
+
62
+ ---
63
+
64
+ ## 📘 API Reference
65
+
66
+ ### `Piper.setPackageId(packageId: string)`
67
+ Sets the Move package ID for all subsequent calls. Call this early in your app. Defaults to the Piper testnet package.
68
+
69
+ ---
70
+
71
+ ### `Piper.createContinuousStream(tx, config): TransactionArgument`
72
+ Creates a new continuous (time‑based) stream.
73
+
74
+ **Parameters:**
75
+ - `tx` – The `Transaction` to add the command to.
76
+ - `config`:
77
+ - `coin` (`TransactionArgument | string`): The coin object (or its ID) to deposit.
78
+ - `coinType` (`string`): Full coin type, e.g., `'0x2::sui::SUI'`.
79
+ - `flowRate` (`number | bigint`): Tokens (in smallest units) to stream **per second**.
80
+ - `recipient` (`string`): Sui address of the primary receiver.
81
+
82
+ **Returns:** A `TransactionArgument` representing the created `Stream<T>` object. You must transfer or share this object in the same transaction.
83
+
84
+ **Example:**
85
+ ```typescript
86
+ const stream = Piper.createContinuousStream(tx, {
87
+ coin: '0xMyUSDC',
88
+ coinType: '0x<pkg>::usdc::USDC',
89
+ flowRate: 1_000_000, // 1 USDC per second (if USDC has 6 decimals)
90
+ recipient: '0xBossWallet',
91
+ });
92
+ tx.transferObjects([stream], tx.pure.address(senderAddress));
93
+ ```
94
+
95
+ ---
96
+
97
+ ### `Piper.createOnDemandStream(tx, config): TransactionArgument`
98
+ Creates a pay‑per‑use stream (flow rate = 0). Only the designated `authorizedSpender` can call `pay`.
99
+
100
+ **Parameters:**
101
+ - `config`:
102
+ - `coin` (`TransactionArgument | string`): The deposited budget.
103
+ - `coinType` (`string`): Full coin type.
104
+ - `recipient` (`string`): Address that receives payments.
105
+ - `authorizedSpender` (`string`): The Sui address allowed to call `pay`.
106
+
107
+ **Returns:** A `TransactionArgument` representing the created `Stream<T>` object.
108
+
109
+ **Example:**
110
+ ```typescript
111
+ const stream = Piper.createOnDemandStream(tx, {
112
+ coin: '0xPrepaidUSDC',
113
+ coinType: '0x<pkg>::usdc::USDC',
114
+ recipient: '0xServiceWallet',
115
+ authorizedSpender: '0xBackendHotWallet',
116
+ });
117
+ tx.transferObjects([stream], tx.pure.address(senderAddress));
118
+ ```
119
+
120
+ ---
121
+
122
+ ### `Piper.tick(tx, config): void`
123
+ Triggers a payment tick on a continuous stream. This function is **permissionless** — anyone can call it. The stream calculates the owed amount since `last_tick_at`, deducts it, applies splits, and transfers funds to all recipients on-chain.
124
+
125
+ **Parameters:**
126
+ - `config`:
127
+ - `streamId` (`string | TransactionArgument`): The ID of the stream to tick.
128
+ - `coinType` (`string`): The token type of the stream.
129
+
130
+ **Note:** Unlike the creation functions, `tick` does not return a value. The Move contract handles all coin transfers internally — funds are sent directly to the primary recipient and any split recipients on-chain.
131
+
132
+ **Example:**
133
+ ```typescript
134
+ Piper.tick(tx, {
135
+ streamId: '0xMyStreamId',
136
+ coinType: '0x<pkg>::usdc::USDC',
137
+ });
138
+ ```
139
+
140
+ ---
141
+
142
+ ### `Piper.pay(tx, config): void`
143
+ Performs an on‑demand payment from a pay‑per‑use stream. **Must be called by the `authorizedSpender`** — the transaction must be signed by the spender's key.
144
+
145
+ **Parameters:**
146
+ - `config`:
147
+ - `streamId` (`string | TransactionArgument`): The stream ID.
148
+ - `coinType` (`string`): The token type of the stream.
149
+ - `amount` (`number | bigint`): How many tokens (in smallest units) to deduct.
150
+
151
+ **Example:**
152
+ ```typescript
153
+ // Inside your backend service (the authorized spender)
154
+ const tx = new Transaction();
155
+ Piper.pay(tx, {
156
+ streamId: '0xMyStreamId',
157
+ coinType: '0x<pkg>::usdc::USDC',
158
+ amount: 500_000,
159
+ });
160
+ const result = await client.signAndExecuteTransaction({
161
+ signer: backendKeypair,
162
+ transaction: tx,
163
+ });
164
+ ```
165
+
166
+ > ⚠️ **Security:** This function does **not** send the transaction. You must sign and submit it with the spender's key. The SDK simply adds the Move call; the authorization check happens on‑chain based on `ctx.sender()`.
167
+
168
+ ---
169
+
170
+ ### `Piper.revoke(tx, config): TransactionArgument`
171
+ Stops a stream and returns all remaining balance as a `Coin<T>`. Only the creator can call this (enforced on‑chain). The returned coin must be transferred or consumed in the same transaction.
172
+
173
+ **Parameters:**
174
+ - `config`:
175
+ - `streamId` (`string | TransactionArgument`): The stream to revoke.
176
+ - `coinType` (`string`): The token type of the stream.
177
+
178
+ **Returns:** A `TransactionArgument` representing the remaining `Coin<T>`.
179
+
180
+ **Example:**
181
+ ```typescript
182
+ const remainingCoin = Piper.revoke(tx, {
183
+ streamId: '0xMyStreamId',
184
+ coinType: '0x<pkg>::usdc::USDC',
185
+ });
186
+ // Transfer the remaining funds back to yourself
187
+ tx.transferObjects([remainingCoin], tx.pure.address(myAddress));
188
+ ```
189
+
190
+ ---
191
+
192
+ ### `Piper.topUp(tx, config): void`
193
+ Adds additional funds to an existing stream. Anyone can top up a stream.
194
+
195
+ **Parameters:**
196
+ - `config`:
197
+ - `streamId` (`string | TransactionArgument`): The stream to top up.
198
+ - `coinType` (`string`): The token type of the stream.
199
+ - `coin` (`TransactionArgument | string`): The coin object (or its ID) to deposit.
200
+
201
+ **Example:**
202
+ ```typescript
203
+ Piper.topUp(tx, {
204
+ streamId: '0xMyStreamId',
205
+ coinType: '0x<pkg>::usdc::USDC',
206
+ coin: '0xAdditionalUSDC',
207
+ });
208
+ ```
209
+
210
+ ---
211
+
212
+ ### `Piper.addSplit(tx, config): void`
213
+ Adds a percentage-based split recipient to a stream. Only the stream creator can manage splits (enforced on-chain). Total split percentages cannot exceed 100%.
214
+
215
+ **Parameters:**
216
+ - `config`:
217
+ - `streamId` (`string | TransactionArgument`): The stream to configure.
218
+ - `coinType` (`string`): The token type of the stream.
219
+ - `recipient` (`string`): The Sui address that will receive this split.
220
+ - `percent` (`number`): Percentage share (1–100).
221
+
222
+ **Example:**
223
+ ```typescript
224
+ Piper.addSplit(tx, {
225
+ streamId: '0xMyStreamId',
226
+ coinType: '0x<pkg>::usdc::USDC',
227
+ recipient: '0xTaxWallet',
228
+ percent: 20,
229
+ });
230
+ ```
231
+
232
+ ---
233
+
234
+ ### `Piper.removeSplit(tx, config): void`
235
+ Removes a split by index. Only the stream creator can manage splits.
236
+
237
+ **Parameters:**
238
+ - `config`:
239
+ - `streamId` (`string | TransactionArgument`): The stream to modify.
240
+ - `coinType` (`string`): The token type of the stream.
241
+ - `index` (`number`): The index of the split to remove.
242
+
243
+ **Example:**
244
+ ```typescript
245
+ Piper.removeSplit(tx, {
246
+ streamId: '0xMyStreamId',
247
+ coinType: '0x<pkg>::usdc::USDC',
248
+ index: 0,
249
+ });
250
+ ```
251
+
252
+ ---
253
+
254
+ ### `Piper.destroyEmpty(tx, config): void`
255
+ Destroys an inactive stream with zero balance. This deletes the `Stream` object from on-chain storage.
256
+
257
+ **Parameters:**
258
+ - `config`:
259
+ - `streamId` (`string | TransactionArgument`): The stream to destroy.
260
+ - `coinType` (`string`): The token type of the stream.
261
+
262
+ **Example:**
263
+ ```typescript
264
+ Piper.destroyEmpty(tx, {
265
+ streamId: '0xMyStreamId',
266
+ coinType: '0x<pkg>::usdc::USDC',
267
+ });
268
+ ```
269
+
270
+ ---
271
+
272
+ ### Utility Functions
273
+
274
+ #### `extractStreamId(result): string`
275
+ Extracts the created `Stream` object ID from the transaction result after calling `createContinuousStream` or `createOnDemandStream`.
276
+
277
+ ```typescript
278
+ import { extractStreamId } from '@usepiper/sdk';
279
+
280
+ const result = await client.signAndExecuteTransaction({ signer, transaction: tx });
281
+ const streamId = extractStreamId(result);
282
+ ```
283
+
284
+ #### `calculateFlowRate(totalAmount, durationSeconds): bigint`
285
+ Computes the flow rate needed to stream a total amount evenly over a duration (in seconds).
286
+
287
+ ```typescript
288
+ import { calculateFlowRate } from '@usepiper/sdk';
289
+
290
+ const flowRate = calculateFlowRate(100_000_000n, 30 * 24 * 3600); // 100 USDC over 30 days
291
+ ```
292
+
293
+ ---
294
+
295
+ ## 🧩 Integration with Sui dApp Kit
296
+
297
+ The SDK works seamlessly with `@mysten/dapp-kit`:
298
+
299
+ ```tsx
300
+ import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
301
+ import { Piper, extractStreamId } from '@usepiper/sdk';
302
+
303
+ function MyComponent() {
304
+ const { mutate: signAndExecute } = useSignAndExecuteTransaction();
305
+
306
+ const handleCreateStream = async () => {
307
+ const tx = new Transaction();
308
+ const stream = Piper.createContinuousStream(tx, {
309
+ coin: myCoinId,
310
+ coinType: '0x2::sui::SUI',
311
+ flowRate: 100,
312
+ recipient: recipientAddress,
313
+ });
314
+ tx.transferObjects([stream], tx.pure.address(myAddress));
315
+
316
+ signAndExecute({ transaction: tx }, {
317
+ onSuccess: (result) => {
318
+ const streamId = extractStreamId(result);
319
+ console.log('Stream created:', streamId);
320
+ },
321
+ });
322
+ };
323
+
324
+ return <button onClick={handleCreateStream}>Start Streaming</button>;
325
+ }
326
+ ```
327
+
328
+ ---
329
+
330
+ ## 🔐 Security Model
331
+
332
+ - **No key custody:** The SDK never asks for or stores private keys. Transactions are signed by the wallet (or your backend key).
333
+ - **All checks on‑chain:** Authorization (creator vs. spender) is enforced by the Move contract.
334
+ - **The SDK only constructs PTBs.** You remain in full control of signing and execution.
335
+
336
+ ---
337
+
338
+ ## 🧪 Testing & Development
339
+
340
+ Clone the repo and run:
341
+
342
+ ```bash
343
+ npm install
344
+ npm run test
345
+ ```
346
+
347
+ The tests are written with `vitest` and verify that the SDK constructs correct Move calls.
348
+
349
+ To contribute, see `CONTRIBUTING.md`.
350
+
351
+ ---
352
+
353
+ ## 📚 More Resources
354
+
355
+ - **Piper Protocol Docs** – [piper-docs](https://github.com/piper-protocol/piper-docs)
356
+ - **Move Contracts** – [piper-move](https://github.com/piper-protocol/piper-move)
357
+ - **Frontend PWA** – [piper-app](https://github.com/piper-protocol/piper-app)
358
+ - **Indexer** – [piper-indexer](https://github.com/piper-protocol/piper-indexer)
359
+
360
+ ---
361
+
362
+ ## 📄 License
363
+
364
+ MIT
365
+
366
+ ---
367
+
368
+ **Piper SDK** — *Plug programmability into your payments.*
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Piper SDK Constants
3
+ *
4
+ * Package IDs, module names, and system object IDs used across the SDK.
5
+ */
6
+ /** Piper testnet package ID (from Published.toml) */
7
+ export declare const PIPER_TESTNET_PACKAGE_ID = "0x8f33eecb14d7990f19374499622f8ac4f9d493ace3368209f3969ccc149d3da7";
8
+ /** Sui system Clock object ID */
9
+ export declare const CLOCK_OBJECT_ID = "0x6";
10
+ /** Piper Move module name for stream operations */
11
+ export declare const STREAM_MODULE = "stream";
12
+ /** Piper Move package name */
13
+ export declare const PACKAGE_NAME = "piper";
14
+ /**
15
+ * Fully qualified Move function target.
16
+ * Format: `{packageId}::{module}::{function}`
17
+ */
18
+ export declare function target(packageId: string, fn: string, module?: string): `${string}::${string}::${string}`;
19
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,uEACiC,CAAC;AAEvE,iCAAiC;AACjC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,mDAAmD;AACnD,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,8BAA8B;AAC9B,eAAO,MAAM,YAAY,UAAU,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,MAAM,GAAE,MAAsB,GAC7B,GAAG,MAAM,KAAK,MAAM,KAAK,MAAM,EAAE,CAEnC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Piper SDK Constants
3
+ *
4
+ * Package IDs, module names, and system object IDs used across the SDK.
5
+ */
6
+ /** Piper testnet package ID (from Published.toml) */
7
+ export const PIPER_TESTNET_PACKAGE_ID = '0x8f33eecb14d7990f19374499622f8ac4f9d493ace3368209f3969ccc149d3da7';
8
+ /** Sui system Clock object ID */
9
+ export const CLOCK_OBJECT_ID = '0x6';
10
+ /** Piper Move module name for stream operations */
11
+ export const STREAM_MODULE = 'stream';
12
+ /** Piper Move package name */
13
+ export const PACKAGE_NAME = 'piper';
14
+ /**
15
+ * Fully qualified Move function target.
16
+ * Format: `{packageId}::{module}::{function}`
17
+ */
18
+ export function target(packageId, fn, module = STREAM_MODULE) {
19
+ return `${packageId}::${module}::${fn}`;
20
+ }
21
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GACnC,oEAAoE,CAAC;AAEvE,iCAAiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC,mDAAmD;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AAEtC,8BAA8B;AAC9B,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,MAAM,CACpB,SAAiB,EACjB,EAAU,EACV,SAAiB,aAAa;IAE9B,OAAO,GAAG,SAAS,KAAK,MAAM,KAAK,EAAE,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @usepiper/sdk — Piper Protocol TypeScript SDK
3
+ *
4
+ * A clean, typed interface for building Programmable Transaction Blocks (PTBs)
5
+ * that interact with the Piper Move contracts on Sui.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Transaction } from '@mysten/sui/transactions';
10
+ * import { Piper, extractStreamId } from '@usepiper/sdk';
11
+ *
12
+ * const tx = new Transaction();
13
+ * const stream = Piper.createContinuousStream(tx, {
14
+ * coin: myCoinId,
15
+ * coinType: '0x2::sui::SUI',
16
+ * flowRate: 100,
17
+ * recipient: '0xRecipient',
18
+ * });
19
+ * tx.transferObjects([stream], tx.pure.address(myAddress));
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ export { Piper } from './piper.js';
25
+ export { extractStreamId, calculateFlowRate, parsePiperEvents, } from './utils.js';
26
+ export { PIPER_TESTNET_PACKAGE_ID, CLOCK_OBJECT_ID, } from './constants.js';
27
+ export type { CreateContinuousStreamConfig, CreateOnDemandStreamConfig, TickConfig, PayConfig, RevokeConfig, TopUpConfig, AddSplitConfig, RemoveSplitConfig, DestroyEmptyConfig, StreamCreatedEvent, PaymentSentEvent, StreamRevokedEvent, StreamToppedUpEvent, SplitPaymentSentEvent, SplitAddedEvent, SplitRemovedEvent, PiperEvent, } from './types.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,wBAAwB,EACxB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EAEV,4BAA4B,EAC5B,0BAA0B,EAC1B,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAElB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @usepiper/sdk — Piper Protocol TypeScript SDK
3
+ *
4
+ * A clean, typed interface for building Programmable Transaction Blocks (PTBs)
5
+ * that interact with the Piper Move contracts on Sui.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Transaction } from '@mysten/sui/transactions';
10
+ * import { Piper, extractStreamId } from '@usepiper/sdk';
11
+ *
12
+ * const tx = new Transaction();
13
+ * const stream = Piper.createContinuousStream(tx, {
14
+ * coin: myCoinId,
15
+ * coinType: '0x2::sui::SUI',
16
+ * flowRate: 100,
17
+ * recipient: '0xRecipient',
18
+ * });
19
+ * tx.transferObjects([stream], tx.pure.address(myAddress));
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ // Core class
25
+ export { Piper } from './piper.js';
26
+ // Utility functions
27
+ export { extractStreamId, calculateFlowRate, parsePiperEvents, } from './utils.js';
28
+ // Constants
29
+ export { PIPER_TESTNET_PACKAGE_ID, CLOCK_OBJECT_ID, } from './constants.js';
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,aAAa;AACb,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,oBAAoB;AACpB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,YAAY;AACZ,OAAO,EACL,wBAAwB,EACxB,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Piper SDK — Core Class
3
+ *
4
+ * Static methods that append Move calls to a Sui `Transaction`.
5
+ * Each method maps directly to a public function in the piper::stream Move module.
6
+ *
7
+ * Move function signatures (from piper-move/sources/stream.move):
8
+ *
9
+ * create_stream<T>(coin: Coin<T>, flow_rate: u64, recipient: address, clock: &Clock, ctx: &mut TxContext): Stream<T>
10
+ * create_on_demand_stream<T>(coin: Coin<T>, recipient: address, authorized_spender: address, clock: &Clock, ctx: &mut TxContext): Stream<T>
11
+ * tick<T>(stream: &mut Stream<T>, clock: &Clock, ctx: &mut TxContext)
12
+ * pay<T>(stream: &mut Stream<T>, amount: u64, clock: &Clock, ctx: &mut TxContext)
13
+ * revoke<T>(stream: &mut Stream<T>, ctx: &mut TxContext): Coin<T>
14
+ * top_up<T>(stream: &mut Stream<T>, coin: Coin<T>)
15
+ * add_split<T>(stream: &mut Stream<T>, recipient: address, percent: u8, ctx: &mut TxContext)
16
+ * remove_split<T>(stream: &mut Stream<T>, index: u64, ctx: &mut TxContext)
17
+ * destroy_empty<T>(stream: Stream<T>)
18
+ */
19
+ import { Transaction } from '@mysten/sui/transactions';
20
+ import type { TransactionResult } from '@mysten/sui/transactions';
21
+ import type { CreateContinuousStreamConfig, CreateOnDemandStreamConfig, TickConfig, PayConfig, RevokeConfig, TopUpConfig, AddSplitConfig, RemoveSplitConfig, DestroyEmptyConfig } from './types.js';
22
+ /**
23
+ * The main Piper SDK class.
24
+ *
25
+ * All methods are static — there's no instance state.
26
+ * Call `Piper.setPackageId()` once at startup (or use the testnet default),
27
+ * then use any method to append Move calls to a `Transaction`.
28
+ */
29
+ export declare class Piper {
30
+ /** The configured Move package ID */
31
+ private static _packageId;
32
+ /**
33
+ * Sets the Move package ID for all subsequent calls.
34
+ * Defaults to the Piper testnet package.
35
+ */
36
+ static setPackageId(packageId: string): void;
37
+ /**
38
+ * Returns the currently configured package ID.
39
+ * @throws if no package ID has been set and the default has been cleared.
40
+ */
41
+ static getPackageId(): string;
42
+ /**
43
+ * Creates a continuous (time-based) stream.
44
+ *
45
+ * Move: `piper::stream::create_stream<T>(coin, flow_rate, recipient, clock, ctx): Stream<T>`
46
+ *
47
+ * @returns A `TransactionResult` representing the created `Stream<T>` object.
48
+ * You must transfer or share this object in the same transaction.
49
+ */
50
+ static createContinuousStream(tx: Transaction, config: CreateContinuousStreamConfig): TransactionResult;
51
+ /**
52
+ * Creates an on-demand (pay-per-use) stream.
53
+ *
54
+ * Move: `piper::stream::create_on_demand_stream<T>(coin, recipient, authorized_spender, clock, ctx): Stream<T>`
55
+ *
56
+ * @returns A `TransactionResult` representing the created `Stream<T>` object.
57
+ * You must transfer or share this object in the same transaction.
58
+ */
59
+ static createOnDemandStream(tx: Transaction, config: CreateOnDemandStreamConfig): TransactionResult;
60
+ /**
61
+ * Shares a stream object so it can be autonomously ticked by anyone.
62
+ * This is the recommended way to handle newly created continuous streams.
63
+ *
64
+ * @param tx The Transaction
65
+ * @param stream The TransactionResult from createContinuousStream
66
+ * @param coinType The type of the coin in the stream
67
+ */
68
+ static shareStream(tx: Transaction, stream: TransactionResult, coinType: string): void;
69
+ /**
70
+ * Triggers a payment tick on a continuous stream.
71
+ * Permissionless — anyone can call this.
72
+ *
73
+ * Move: `piper::stream::tick<T>(stream, clock, ctx)`
74
+ *
75
+ * The Move function handles all coin transfers internally.
76
+ * Funds are sent directly to the primary recipient and any split recipients on-chain.
77
+ */
78
+ static tick(tx: Transaction, config: TickConfig): void;
79
+ /**
80
+ * Performs an on-demand payment from a pay-per-use stream.
81
+ * Must be called by the `authorizedSpender` — the transaction must be
82
+ * signed by the spender's key.
83
+ *
84
+ * Move: `piper::stream::pay<T>(stream, amount, clock, ctx)`
85
+ */
86
+ static pay(tx: Transaction, config: PayConfig): void;
87
+ /**
88
+ * Revokes a stream and returns the remaining balance as a `Coin<T>`.
89
+ * Only the stream creator can call this (enforced on-chain).
90
+ *
91
+ * Move: `piper::stream::revoke<T>(stream, clock, ctx): Coin<T>`
92
+ *
93
+ * @returns A `TransactionResult` representing the remaining `Coin<T>`.
94
+ * You must transfer or consume this coin in the same transaction.
95
+ */
96
+ static revoke(tx: Transaction, config: RevokeConfig): TransactionResult;
97
+ /**
98
+ * Adds additional funds to an existing stream.
99
+ * Anyone can top up a stream.
100
+ *
101
+ * Move: `piper::stream::top_up<T>(stream, coin)`
102
+ */
103
+ static topUp(tx: Transaction, config: TopUpConfig): void;
104
+ /**
105
+ * Adds a percentage-based split recipient to a stream.
106
+ * Only the stream creator can manage splits (enforced on-chain).
107
+ * Total split percentages cannot exceed 100%.
108
+ *
109
+ * Move: `piper::stream::add_split<T>(stream, recipient, percent, ctx)`
110
+ */
111
+ static addSplit(tx: Transaction, config: AddSplitConfig): void;
112
+ /**
113
+ * Removes a split by index.
114
+ * Only the stream creator can manage splits (enforced on-chain).
115
+ *
116
+ * Move: `piper::stream::remove_split<T>(stream, index, ctx)`
117
+ */
118
+ static removeSplit(tx: Transaction, config: RemoveSplitConfig): void;
119
+ /**
120
+ * Destroys an inactive stream with zero balance.
121
+ * Deletes the `Stream` object from on-chain storage.
122
+ *
123
+ * Move: `piper::stream::destroy_empty<T>(stream)`
124
+ *
125
+ * Note: The stream is consumed by value — if you pass a string ID,
126
+ * the SDK resolves it as an owned object.
127
+ */
128
+ static destroyEmpty(tx: Transaction, config: DestroyEmptyConfig): void;
129
+ }
130
+ //# sourceMappingURL=piper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"piper.d.ts","sourceRoot":"","sources":["../src/piper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAuB,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEvF,OAAO,KAAK,EACV,4BAA4B,EAC5B,0BAA0B,EAC1B,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAiBpB;;;;;;GAMG;AACH,qBAAa,KAAK;IAChB,qCAAqC;IACrC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAoC;IAI7D;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI5C;;;OAGG;IACH,MAAM,CAAC,YAAY,IAAI,MAAM;IAW7B;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CAC3B,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,4BAA4B,GACnC,iBAAiB;IAepB;;;;;;;OAOG;IACH,MAAM,CAAC,oBAAoB,CACzB,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,0BAA0B,GACjC,iBAAiB;IAepB;;;;;;;OAOG;IACH,MAAM,CAAC,WAAW,CAChB,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,MAAM,GACf,IAAI;IAWP;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI;IAatD;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI;IAcpD;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CACX,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,YAAY,GACnB,iBAAiB;IAapB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI;IAexD;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI;IAc9D;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAepE;;;;;;;;OAQG;IACH,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI;CAWvE"}