@bigmaxwatermelon/sdk 0.4.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 +326 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +5845 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +580 -0
- package/dist/index.js +4802 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# @isometry/sdk
|
|
2
|
+
|
|
3
|
+
> TypeScript SDK for the Isometry DeFi protocol — Ethereum Sepolia.
|
|
4
|
+
|
|
5
|
+
**npm:** `@isometry/sdk`
|
|
6
|
+
**version:** `0.4.0`
|
|
7
|
+
**network:** Ethereum Sepolia (chain ID 11155111)
|
|
8
|
+
**registry:** npm
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @isometry/sdk ethers
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node.js ≥ 20.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createClient } from '@isometry/sdk'
|
|
26
|
+
|
|
27
|
+
const client = createClient({
|
|
28
|
+
rpcUrl: process.env.SEPOLIA_RPC_URL,
|
|
29
|
+
graphUrl: process.env.GRAPH_URL,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Read token info
|
|
33
|
+
const info = await client.rpc.getTokenInfo('0xd0473e07c68797f387fbe6c23981f7997d3ed5e3')
|
|
34
|
+
console.log(info)
|
|
35
|
+
// { name: 'Test USDC', symbol: 'USDC', decimals: 6, totalSupply: ..., paused: false }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## SDK — Complete Usage
|
|
41
|
+
|
|
42
|
+
### Initialize Client
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createClient } from '@isometry/sdk'
|
|
46
|
+
|
|
47
|
+
const client = createClient({
|
|
48
|
+
// Required for RPC calls
|
|
49
|
+
rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY',
|
|
50
|
+
|
|
51
|
+
// Optional: for write operations
|
|
52
|
+
privateKey: process.env.ISOMETRY_PRIVATE_KEY,
|
|
53
|
+
|
|
54
|
+
// Optional: defaults to Isometry's public subgraph
|
|
55
|
+
graphUrl: 'https://console.isometry.network/graph/subgraphs/name/isometry',
|
|
56
|
+
|
|
57
|
+
// Optional: override contract addresses
|
|
58
|
+
addresses: {
|
|
59
|
+
platform: '0x062B11C5Ed0F2b1f9B7dFaa7B95737dD221863F7',
|
|
60
|
+
factory: '0x73D6BC64f4f54F9dF05851216F70F42135d56864',
|
|
61
|
+
beacon: '0x99d6512B5483DFA003F73F737f87e7DAE9482F89',
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Read — RPC
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Platform state
|
|
70
|
+
const platform = await client.rpc.platform.getPlatformInfo()
|
|
71
|
+
console.log(platform.paused, platform.tokenCount)
|
|
72
|
+
|
|
73
|
+
// Token info
|
|
74
|
+
const info = await client.rpc.getTokenInfo('0xd0473e07c68797f387fbe6c23981f7997d3ed5e3')
|
|
75
|
+
|
|
76
|
+
// Account roles on a token
|
|
77
|
+
const roles = await client.rpc.platform.getAccountRoles(
|
|
78
|
+
'0xd0473e07c68797f387fbe6c23981f7997d3ed5e3',
|
|
79
|
+
'0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e'
|
|
80
|
+
)
|
|
81
|
+
// { isTokenOwner, isMasterMinter, isMinter, isPauser, isBlacklister, isBlacklisted }
|
|
82
|
+
|
|
83
|
+
// Factory info
|
|
84
|
+
const factory = await client.rpc.factory.getFactoryInfo()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Read — GraphQL (historical data)
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Mint history
|
|
91
|
+
const mints = await client.graph.token.mintHistory(
|
|
92
|
+
'0xd0473e07c68797f387fbe6c23981f7997d3ed5e3',
|
|
93
|
+
{ first: 100 }
|
|
94
|
+
)
|
|
95
|
+
console.log(mints[0].amount, mints[0].to, mints[0].blockNumber)
|
|
96
|
+
|
|
97
|
+
// Token stats
|
|
98
|
+
const stats = await client.graph.analytics.tokenStats('0xd0473e07c68797f387fbe6c23981f7997d3ed5e3')
|
|
99
|
+
console.log(stats.totalMints, stats.totalBurns, stats.holderCount)
|
|
100
|
+
|
|
101
|
+
// Platform stats
|
|
102
|
+
const platformStats = await client.graph.analytics.platformStats()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Write — Simulate Before Execute
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { WriteExecutor } from '@isometry/sdk'
|
|
109
|
+
|
|
110
|
+
// Create client with private key for signing
|
|
111
|
+
const writeClient = createClient({
|
|
112
|
+
rpcUrl: process.env.SEPOLIA_RPC_URL,
|
|
113
|
+
privateKey: process.env.ISOMETRY_PRIVATE_KEY,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const wallet = writeClient.rpc.getWallet()
|
|
117
|
+
const stablecoin = writeClient.rpc.getStableCoin('0xd0473e07c68797f387fbe6c23981f7997d3ed5e3')
|
|
118
|
+
const executor = new WriteExecutor({ wallet, contract: stablecoin })
|
|
119
|
+
|
|
120
|
+
// Step 1: Simulate (safe — no gas, no signature)
|
|
121
|
+
const sim = await executor.simulate({
|
|
122
|
+
method: 'mint',
|
|
123
|
+
args: ['0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e', 1000n, 'memo'],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (!sim.ok) {
|
|
127
|
+
console.error(`[${sim.code}] ${sim.message}`)
|
|
128
|
+
process.exit(1)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(`Gas estimate: ${sim.estimatedGas}`)
|
|
132
|
+
|
|
133
|
+
// Step 2: Execute (only after simulate succeeds)
|
|
134
|
+
const result = await executor.execute({
|
|
135
|
+
method: 'mint',
|
|
136
|
+
args: ['0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e', 1000n, 'memo'],
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
if (!result.ok) {
|
|
140
|
+
console.error(`[${result.code}] ${result.message}`)
|
|
141
|
+
process.exit(1)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
console.log(`Confirmed: ${result.receipt.txHash}`)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## CLI
|
|
150
|
+
|
|
151
|
+
The CLI is included in the same package.
|
|
152
|
+
|
|
153
|
+
### Install globally
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install -g @isometry/sdk
|
|
157
|
+
isometry --version
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Or run via npx
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npx @isometry/sdk token info 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Or link locally
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm link
|
|
170
|
+
isometry token info 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Environment
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Required for write commands
|
|
177
|
+
ISOMETRY_PRIVATE_KEY=0x...
|
|
178
|
+
|
|
179
|
+
# Required for RPC commands
|
|
180
|
+
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
|
|
181
|
+
|
|
182
|
+
# Optional (defaults to Isometry's public subgraph)
|
|
183
|
+
GRAPH_URL=https://console.isometry.network/graph/subgraphs/name/isometry
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### CLI Examples
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Read token info
|
|
190
|
+
isometry token info 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3
|
|
191
|
+
|
|
192
|
+
# Read token history (GraphQL — no RPC key needed)
|
|
193
|
+
isometry token history 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3 --json
|
|
194
|
+
|
|
195
|
+
# Simulate mint (safe, no gas)
|
|
196
|
+
isometry token mint 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3 \
|
|
197
|
+
0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e 1000 \
|
|
198
|
+
--simulate --json
|
|
199
|
+
|
|
200
|
+
# Execute mint (real transaction)
|
|
201
|
+
isometry token mint 0xd0473e07c68797f387fbe6c23981f7997d3ed5e3 \
|
|
202
|
+
0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e 1000 \
|
|
203
|
+
--json
|
|
204
|
+
|
|
205
|
+
# Add platform admin
|
|
206
|
+
isometry platform admin add 0x6BacA041C42edB76660F399fA0f4a7Dd0Cfb361e --simulate --json
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## API Reference
|
|
212
|
+
|
|
213
|
+
Full API reference at [docs/API.md](docs/API.md).
|
|
214
|
+
|
|
215
|
+
### Public Exports
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// Client
|
|
219
|
+
import { createClient } from '@isometry/sdk'
|
|
220
|
+
import type { IsometryClient, IsometryConfig } from '@isometry/sdk'
|
|
221
|
+
|
|
222
|
+
// Wallet
|
|
223
|
+
import { createWallet, ReadOnlyWallet, PrivateKeyWallet } from '@isometry/sdk'
|
|
224
|
+
import type { IWallet, WalletMode } from '@isometry/sdk'
|
|
225
|
+
|
|
226
|
+
// Write executor
|
|
227
|
+
import { WriteExecutor, makeWriteMeta } from '@isometry/sdk'
|
|
228
|
+
import type { WriteResult, SimulateResult, ExecuteResult, WriteError, WriteOpts, WriteMeta, TxReceipt } from '@isometry/sdk'
|
|
229
|
+
|
|
230
|
+
// Error decoding
|
|
231
|
+
import { decodeError, ERROR_SELECTOR_MAP } from '@isometry/sdk'
|
|
232
|
+
import type { DecodedError } from '@isometry/sdk'
|
|
233
|
+
|
|
234
|
+
// Graph
|
|
235
|
+
import { createGraphClient, GraphClient, GraphError } from '@isometry/sdk'
|
|
236
|
+
import type { IsometryGraphConfig } from '@isometry/sdk'
|
|
237
|
+
import { TokenHistoryService, PlatformHistoryService, AnalyticsService } from '@isometry/sdk'
|
|
238
|
+
|
|
239
|
+
// Contract helpers
|
|
240
|
+
import { getContracts, getStableCoin } from '@isometry/sdk'
|
|
241
|
+
import type { ContractAddresses } from '@isometry/sdk'
|
|
242
|
+
|
|
243
|
+
// Types
|
|
244
|
+
import type { PlatformInfo, PlatformRoles, TokenInfo, TokenStats, TokenRoles } from '@isometry/sdk'
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Write Result Contract
|
|
250
|
+
|
|
251
|
+
All write operations return a typed `WriteResult`:
|
|
252
|
+
|
|
253
|
+
### Simulate — success
|
|
254
|
+
```typescript
|
|
255
|
+
{ ok: true, estimatedGas: 123456n, functionFragment: 'mint(address,uint256,string)', params: {...} }
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Execute — success
|
|
259
|
+
```typescript
|
|
260
|
+
{ ok: true, receipt: { txHash: '0x...', blockNumber: 10609809, status: 1, gasUsed: 121791n, from: '0x...', to: '0x...', logs: [...] } }
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Error
|
|
264
|
+
```typescript
|
|
265
|
+
{ ok: false, code: 'ACCESS_DENIED', message: 'Missing MASTER_MINTER_ROLE' }
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Error Codes
|
|
269
|
+
|
|
270
|
+
| Code | Meaning |
|
|
271
|
+
|------|---------|
|
|
272
|
+
| `NO_SIGNER` | `privateKey` not set |
|
|
273
|
+
| `INVALID_KEY` | Key format invalid |
|
|
274
|
+
| `ACCESS_DENIED` | Missing required role |
|
|
275
|
+
| `SIMULATION_FAILED` | `estimateGas` reverted |
|
|
276
|
+
| `REVERT` | On-chain revert |
|
|
277
|
+
| `INSUFFICIENT_BALANCE` | Not enough tokens or ETH |
|
|
278
|
+
| `PAUSED` | Token is paused |
|
|
279
|
+
| `RPC_ERROR` | Network error |
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Known Contract Addresses (Sepolia)
|
|
284
|
+
|
|
285
|
+
| Contract | Address |
|
|
286
|
+
|----------|---------|
|
|
287
|
+
| Platform | `0x062B11C5Ed0F2b1f9B7dFaa7B95737dD221863F7` |
|
|
288
|
+
| Factory | `0x73D6BC64f4f54F9dF05851216F70F42135d56864` |
|
|
289
|
+
| Beacon | `0x99d6512B5483DFA003F73F737f87e7DAE9482F89` |
|
|
290
|
+
| Test Token | `0xd0473e07c68797f387fbe6c23981f7997d3ed5e3` |
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Design Principles
|
|
295
|
+
|
|
296
|
+
1. **SDK returns objects, CLI returns text** — SDK methods return native JS objects; CLI outputs formatted strings
|
|
297
|
+
2. **Simulate before execute** — always estimate gas first to validate inputs and permissions
|
|
298
|
+
3. **Read-only by default** — private key is optional; most use cases need reads only
|
|
299
|
+
4. **Typed errors** — all errors have a `code` field for programmatic handling
|
|
300
|
+
5. **No magic** — no hidden state; everything is explicit
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Architecture
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
@isometry/sdk
|
|
308
|
+
├── dist/index.js # SDK entry
|
|
309
|
+
├── dist/cli.js # CLI entry (bin: isometry)
|
|
310
|
+
└── docs/
|
|
311
|
+
├── API.md # Full API reference
|
|
312
|
+
└── examples/ # CLI, SDK, Agent examples
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**RPC channel** — real-time state (balances, roles, pause status)
|
|
316
|
+
**GraphQL channel** — historical data (events, mint/burn history, snapshots)
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Links
|
|
321
|
+
|
|
322
|
+
- [API Reference](docs/API.md)
|
|
323
|
+
- [CLI Examples](docs/examples/CLI.md)
|
|
324
|
+
- [SDK Examples](docs/examples/SDK.md)
|
|
325
|
+
- [Agent Examples](docs/examples/AGENT.md)
|
|
326
|
+
- [Gitee Repository](https://gitee.com/middear/isometry-cli)
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|