@noosphere/contracts 0.1.0-alpha.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/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # @noosphere/contracts
2
+
3
+ TypeScript wrappers and ABIs for Noosphere smart contracts.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @noosphere/contracts
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Example
14
+
15
+ ```typescript
16
+ import { RouterContract, CoordinatorContract, SubscriptionBatchReaderContract } from '@noosphere/contracts';
17
+ import { ethers } from 'ethers';
18
+
19
+ // Setup provider
20
+ const provider = new ethers.JsonRpcProvider('https://sepolia.hpp.io');
21
+
22
+ // Create contract instances
23
+ const router = new RouterContract(
24
+ '0x89c76ee71E9cC8D57BEE3d414478B630AE41fF43',
25
+ provider
26
+ );
27
+
28
+ const coordinator = new CoordinatorContract(
29
+ '0x244D87a7CAe0D557C223C13a90Ae845e56430A50',
30
+ provider
31
+ );
32
+
33
+ // Read subscription
34
+ const subscription = await router.getComputeSubscription(1n);
35
+ console.log('Subscription:', subscription);
36
+
37
+ // Check redundancy
38
+ const redundancy = await coordinator.redundancyCount('0x123...');
39
+ console.log('Redundancy count:', redundancy);
40
+ ```
41
+
42
+ ### SubscriptionBatchReader
43
+
44
+ ```typescript
45
+ import { SubscriptionBatchReaderContract } from '@noosphere/contracts';
46
+
47
+ // Get BatchReader address from coordinator
48
+ const batchReaderAddress = await coordinator.raw.getSubscriptionBatchReader();
49
+
50
+ // Create BatchReader instance
51
+ const batchReader = new SubscriptionBatchReaderContract(
52
+ batchReaderAddress,
53
+ provider
54
+ );
55
+
56
+ // Read subscriptions in batch
57
+ const subscriptions = await batchReader.getSubscriptions(
58
+ 0n, // startId
59
+ 100n, // endId
60
+ await provider.getBlockNumber() // optional: specific block
61
+ );
62
+
63
+ console.log(`Loaded ${subscriptions.length} subscriptions`);
64
+ ```
65
+
66
+ ### Event Listening
67
+
68
+ ```typescript
69
+ // Listen for RequestStarted events
70
+ router.on('RequestStarted', (requestId, subscriptionId, containerId, commitment, event) => {
71
+ console.log('New request:', {
72
+ requestId,
73
+ subscriptionId,
74
+ containerId,
75
+ commitment,
76
+ });
77
+ });
78
+
79
+ // Query past events
80
+ const events = await router.queryFilter(
81
+ router.filters.RequestStarted(),
82
+ 1000, // from block
83
+ 'latest'
84
+ );
85
+
86
+ console.log(`Found ${events.length} RequestStarted events`);
87
+ ```
88
+
89
+ ### Write Operations (requires Signer)
90
+
91
+ ```typescript
92
+ import { ethers } from 'ethers';
93
+
94
+ // Create signer
95
+ const wallet = new ethers.Wallet(privateKey, provider);
96
+
97
+ // Create contract with signer
98
+ const coordinatorWithSigner = new CoordinatorContract(
99
+ coordinatorAddress,
100
+ wallet
101
+ );
102
+
103
+ // Prepare next interval
104
+ const tx = await coordinatorWithSigner.prepareNextInterval(
105
+ 1n, // subscriptionId
106
+ 5, // nextInterval
107
+ walletAddress // nodeWallet
108
+ );
109
+
110
+ await tx.wait();
111
+ console.log('Transaction confirmed:', tx.hash);
112
+ ```
113
+
114
+ ## API
115
+
116
+ ### RouterContract
117
+
118
+ **Read Methods:**
119
+ - `getComputeSubscription(subscriptionId)` - Get subscription details
120
+ - `hasSubscriptionNextInterval(subscriptionId, currentInterval)` - Check if next interval exists
121
+ - `getLastSubscriptionId()` - Get last subscription ID
122
+ - `getContractById(id)` - Get contract address by ID
123
+ - `getWalletFactory()` - Get WalletFactory address
124
+ - `isValidWallet(address)` - Check if address is valid wallet
125
+
126
+ **Write Methods:**
127
+ - `sendRequest(subscriptionId, interval)` - Create new request
128
+ - `fulfill(...)` - Fulfill request
129
+ - `timeoutRequest(requestId, subscriptionId, interval)` - Timeout request
130
+
131
+ **Events:**
132
+ - `RequestStarted`
133
+ - `SubscriptionCreated`
134
+ - `SubscriptionCancelled`
135
+
136
+ ### CoordinatorContract
137
+
138
+ **Read Methods:**
139
+ - `getCommitment(subscriptionId, interval)` - Get commitment
140
+ - `redundancyCount(requestId)` - Get redundancy count
141
+ - `requestCommitments(requestId)` - Get request ID
142
+
143
+ **Write Methods:**
144
+ - `startRequest(...)` - Start new request
145
+ - `cancelRequest(requestId)` - Cancel request
146
+ - `reportComputeResult(...)` - Report compute result
147
+ - `prepareNextInterval(subscriptionId, interval, wallet)` - Prepare interval
148
+
149
+ **Events:**
150
+ - `RequestStarted`
151
+ - `RequestCancelled`
152
+ - `ComputeDelivered`
153
+ - `ProofVerified`
154
+
155
+ ### SubscriptionBatchReaderContract
156
+
157
+ **Read Methods:**
158
+ - `getSubscriptions(startId, endId, blockNumber?)` - Get batch of subscriptions
159
+ - `getIntervalStatuses(ids, intervals)` - Get interval statuses
160
+
161
+ ## Types
162
+
163
+ All TypeScript types are exported:
164
+
165
+ ```typescript
166
+ import type {
167
+ ComputeSubscription,
168
+ Commitment,
169
+ Payment,
170
+ ProofVerificationRequest,
171
+ IntervalStatus,
172
+ FulfillResult,
173
+ RequestStartedEvent,
174
+ } from '@noosphere/contracts';
175
+ ```
176
+
177
+ ## ABIs
178
+
179
+ Access raw ABIs:
180
+
181
+ ```typescript
182
+ import { ABIs } from '@noosphere/contracts';
183
+
184
+ console.log(ABIs.Router);
185
+ console.log(ABIs.Coordinator);
186
+ console.log(ABIs.SubscriptionBatchReader);
187
+ ```
188
+
189
+ ## License
190
+
191
+ MIT