@notifi-network/fusion-sdk 0.1.0 → 0.1.2

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 ADDED
@@ -0,0 +1,188 @@
1
+ # Fusion SDK
2
+
3
+ Fusion SDK provides TypeScript/JavaScript wrappers and types for interacting with Notifi Fusion blockchain services, including EVM, Sui, Solana, storage management, and subscriptions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install fusion-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import {
15
+ EvmRpc,
16
+ SuiRpc,
17
+ SolanaRpc,
18
+ PersistentStorage,
19
+ EphemeralStorage,
20
+ Subscriptions,
21
+ BlockchainType,
22
+ HttpMethod,
23
+ Region,
24
+ getParserBlobInput
25
+ } from "fusion-sdk";
26
+
27
+ const evm = new EvmRpc("your-context-id");
28
+ const sui = new SuiRpc("your-context-id");
29
+ const solana = new SolanaRpc("your-context-id");
30
+ const persistentStorage = new PersistentStorage("your-context-id");
31
+ const ephemeralStorage = new EphemeralStorage("your-context-id");
32
+ const subscriptions = new Subscriptions("your-context-id");
33
+ ```
34
+
35
+ ## API Reference
36
+
37
+ ### Classes
38
+
39
+ #### EvmRpc
40
+ EVM-specific blockchain operations.
41
+
42
+ **Methods:**
43
+ - `runEthCall(request)`: Executes an Ethereum call operation.
44
+ - `getAccountBalance(request)`: Retrieves the account balance for an Ethereum address.
45
+
46
+ ```typescript
47
+ const evm = new EvmRpc("your-context-id");
48
+ const balance = await evm.getAccountBalance({ address: "0x..." });
49
+ ```
50
+
51
+ #### SuiRpc
52
+ Sui blockchain operations.
53
+
54
+ **Methods:**
55
+ - `getSuiAccountBalance(request)`: Retrieves the account balance for a Sui address.
56
+ - `runSuiTransaction(request)`: Executes a Sui transaction.
57
+ - `getSuiObject(request)`: Retrieves a Sui object.
58
+
59
+ ```typescript
60
+ const sui = new SuiRpc("your-context-id");
61
+ const balance = await sui.getSuiAccountBalance({ address: "0x..." });
62
+ ```
63
+
64
+ #### SolanaRpc
65
+ Solana blockchain operations.
66
+
67
+ **Methods:**
68
+ - `getSolanaBalance(request)`: Retrieves the balance for a Solana address.
69
+ - `getSolanaAccountInfo(request)`: Retrieves account information for a Solana address.
70
+ - `getSolanaSlot(request)`: Retrieves the current Solana slot.
71
+
72
+ ```typescript
73
+ const solana = new SolanaRpc("your-context-id");
74
+ const balance = await solana.getSolanaBalance({ address: "..." });
75
+ ```
76
+
77
+ #### PersistentStorage
78
+ CRUD operations for persistent storage.
79
+
80
+ **Methods:**
81
+ - `put(request)`: Stores a string value in persistent storage.
82
+ - `get(request)`: Retrieves a value from persistent storage.
83
+ - `delete(request)`: Deletes a value from persistent storage.
84
+
85
+ ```typescript
86
+ const persistentStorage = new PersistentStorage("your-context-id");
87
+ await persistentStorage.put({ key: "foo", value: "bar" });
88
+ const value = await persistentStorage.get({ key: "foo" });
89
+ ```
90
+
91
+ **Optimistic Concurrency Example:**
92
+ Fetch a value, increment its version, update, and retry on exception (optimistic locking with 100ms jitter):
93
+
94
+ ```typescript
95
+ function sleep(ms: number) {
96
+ return new Promise(resolve => setTimeout(resolve, ms));
97
+ }
98
+
99
+ async function updateWithOptimisticLock(key: string, newValue: string, maxRetries = 3) {
100
+ let attempt = 0;
101
+ while (attempt < maxRetries) {
102
+ try {
103
+ // Fetch current value and version
104
+ const current = await persistentStorage.get({ key });
105
+ const currentVersion = current.version ?? 0;
106
+ // Attempt to update with incremented version
107
+ await persistentStorage.put({ key, value: newValue, version: currentVersion + 1 });
108
+ return true;
109
+ } catch (err) {
110
+ attempt++;
111
+ if (attempt >= maxRetries) throw err;
112
+ // Add 100ms jitter before retrying
113
+ await sleep(100 + Math.floor(Math.random() * 100));
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+
119
+ // Usage
120
+ await updateWithOptimisticLock("foo", "newBar");
121
+ ```
122
+
123
+ This pattern helps ensure updates are atomic and consistent, retrying if another process updates the value concurrently.
124
+
125
+ #### EphemeralStorage
126
+ Operations for ephemeral storage.
127
+
128
+ **Methods:**
129
+ - `put(request)`: Stores a string value in ephemeral storage.
130
+ - `get(request)`: Retrieves a value from ephemeral storage.
131
+ - `delete(request)`: Deletes a value from ephemeral storage.
132
+ - `peek(request)`: Peeks at the next value in a queue in ephemeral storage.
133
+ - `enqueue(request)`: Enqueues a value into a queue in ephemeral storage.
134
+ - `dequeue(request)`: Dequeues a value from a queue in ephemeral storage.
135
+ - `getModuleExecutionParams(request)`: Retrieves module execution parameters.
136
+ - `getOnChainBlock(request)`: Retrieves an on-chain block.
137
+
138
+ ```typescript
139
+ const ephemeralStorage = new EphemeralStorage("your-context-id");
140
+ await ephemeralStorage.put({ key: "temp", value: "baz" });
141
+ const value = await ephemeralStorage.get({ key: "temp" });
142
+ ```
143
+
144
+ #### Subscriptions
145
+ Manage and retrieve subscription data.
146
+
147
+ **Methods:**
148
+ - `getSubscriptions(request)`: Retrieves subscription data.
149
+
150
+ ```typescript
151
+ const subscriptions = new Subscriptions("your-context-id");
152
+ const subs = await subscriptions.getSubscriptions({ eventTypeId: "event-type-id" });
153
+ ```
154
+
155
+ All wrappers require a `contextId` string for gRPC requests. This is provided as an argument in the parse function in the Fusion system.
156
+
157
+ ### Types & Enums
158
+ - `BlockchainType`: Enum for supported blockchains (EVM, Solana, Sui, etc.)
159
+
160
+ ### Utility Functions
161
+ - `getParserBlobInput(contextId: string, urlForBlob: string)`: Fetches and parses block data from storage. The response can be typed as:
162
+ - `EvmBlockAndLogs` for EVM chains
163
+ - `SolanaBlockAndLogs` for Solana
164
+ - `SuiCheckpointTransactions` for Sui
165
+ This allows you to safely cast and work with chain-specific block data structures in your application. Not applicable to OffChain parsers.
166
+
167
+ ## Environment Variables (SDK developer usage)
168
+ - `EVM_RPC_ADDRESS`: EVM gRPC endpoint (default: localhost:50054)
169
+ - `SUI_RPC_ADDRESS`: Sui gRPC endpoint (default: localhost:50057)
170
+ - `SOLANA_RPC_ADDRESS`: Solana gRPC endpoint (default: localhost:50055)
171
+ - `PERSISTENT_STORAGE_ADDRESS`: Persistent storage gRPC endpoint (default: localhost:50053)
172
+ - `EPHEMERAL_STORAGE_ADDRESS`: Ephemeral storage gRPC endpoint (default: localhost:50052)
173
+ - `SUBSCRIPTION_MANAGER_ADDRESS`: Subscriptions gRPC endpoint (default: localhost:50056)
174
+ - `GRPC_INSECURE`: Set to "true" for insecure local connections
175
+
176
+ ## Publishing
177
+
178
+ To publish to npm:
179
+
180
+ ```bash
181
+ npm publish
182
+ ```
183
+
184
+ Ensure your documentation and API are up to date before publishing.
185
+
186
+ ## License
187
+
188
+ See [LICENSE](./LICENSE).
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export { SubscriptionsWrapper as Subscriptions } from './fusion_wrappers/subscri
8
8
  export { BlockchainType } from './protos_gen/notifi/common/v1/types.js';
9
9
  export { HttpMethod, Region } from './protos_gen/services/fetch_proxy/v1/fetch_proxy.js';
10
10
  export { getParserBlobInput } from './utils/execution_param_fetch.js';
11
+ export type { EvmBlock, EvmLogs, EvmBlockAndLogs, EvmTransactions, SolanaBlockAndLogs, SuiCheckpointTransactions } from './types/parserInputTypes.js';
@@ -61,5 +61,5 @@ export interface SuiCheckpointTransactions {
61
61
  transactions: any[];
62
62
  }
63
63
  export interface SolanaBlockAndLogs {
64
- block: any;
64
+ solanaBlock: any;
65
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notifi-network/fusion-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "SDK utils for Notifi Fusion parser development. This includes types and helpers for accessing ephemeral/persistent storage, RPCs for different chains, and other utilities.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",