@reserve-protocol/sdk 0.0.1
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 +106 -0
- package/dist/index.d.mts +131645 -0
- package/dist/index.mjs +26525 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @reserve-protocol/sdk
|
|
2
|
+
|
|
3
|
+
Core TypeScript SDK for DTF integrations.
|
|
4
|
+
|
|
5
|
+
This package is environment-agnostic. It should work in modern Node, browser apps, React wrappers, scripts, and bots.
|
|
6
|
+
|
|
7
|
+
Supported products and chains:
|
|
8
|
+
|
|
9
|
+
- Index DTFs: Ethereum mainnet, Base, BSC.
|
|
10
|
+
- Yield DTFs: Ethereum mainnet, Base.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createDtfSdk } from "@reserve-protocol/sdk";
|
|
16
|
+
|
|
17
|
+
const sdk = createDtfSdk();
|
|
18
|
+
|
|
19
|
+
const dtf = await sdk.index.get({
|
|
20
|
+
address: "0x...",
|
|
21
|
+
chainId: 8453,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const cmc20 = sdk.index.ref({
|
|
25
|
+
address: "0x...",
|
|
26
|
+
chainId: 8453,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const proposals = await cmc20.proposals();
|
|
30
|
+
const price = await cmc20.getPrice();
|
|
31
|
+
const brand = await cmc20.getBrand();
|
|
32
|
+
const basketAtBlock = await cmc20.basket(123n);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
With explicit configuration:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createDtfSdk } from "@reserve-protocol/sdk";
|
|
39
|
+
|
|
40
|
+
const sdk = createDtfSdk({
|
|
41
|
+
apiBaseUrl: "https://api.reserve.org",
|
|
42
|
+
chains: {
|
|
43
|
+
1: {
|
|
44
|
+
rpcUrls: ["https://eth-mainnet.example"],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const dtfs = await sdk.index.list({ chainId: 1 });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## GraphQL Codegen
|
|
53
|
+
|
|
54
|
+
The SDK imports typed GraphQL documents from generated source files. After changing `.graphql` files or `codegen.yml`, regenerate them before running the SDK, build, or typecheck:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
pnpm graphql:codegen
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Generated GraphQL files are checked in so consumers do not need to run codegen after installing the package.
|
|
61
|
+
|
|
62
|
+
## Playground
|
|
63
|
+
|
|
64
|
+
Run a live Index DTF fetch and print real data:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
pnpm playground:index
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
You can also pass `address chainId`:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
pnpm playground:index 0x4da9a0f397db1397902070f93a4d6ddbc0e0e6e8 8453
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This is intentionally not part of the normal test suite or CI path.
|
|
77
|
+
|
|
78
|
+
## Errors
|
|
79
|
+
|
|
80
|
+
SDK errors use stable machine-readable codes:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { isSdkError } from "@reserve-protocol/sdk";
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await sdk.index.get({ address, chainId });
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (isSdkError(error) && error.code === "RECORD_NOT_FOUND") {
|
|
89
|
+
// handle known SDK error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Design
|
|
95
|
+
|
|
96
|
+
The SDK uses a small domain facade over a runtime client. One-off methods take plain inputs like `{ address, chainId }`. Repeated DTF workflows can use `sdk.index.ref({ address, chainId })`, which only binds identity and does not fetch by itself.
|
|
97
|
+
|
|
98
|
+
Do not add a class-based SDK surface unless there is a strong reason.
|
|
99
|
+
|
|
100
|
+
The intended model:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
namespace methods -> client -> small transports -> mappers
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
See [../../docs/sdk-architecture.md](../../docs/sdk-architecture.md).
|