@nexusmutual/sdk 2.1.1 → 3.0.0-rc.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 +123 -112
- package/dist/index.d.mts +247 -227
- package/dist/index.d.ts +247 -227
- package/dist/index.js +259 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -186
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ npm install @nexusmutual/sdk
|
|
|
8
8
|
|
|
9
9
|
## Requirements
|
|
10
10
|
|
|
11
|
-
- Node.js
|
|
11
|
+
- Node.js 22 or newer
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
@@ -42,49 +42,11 @@ const product = await productApi.getProductById(247);
|
|
|
42
42
|
console.log(productTypes.length, product.name);
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Install dependencies
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
npm ci
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### ENV variables setup
|
|
54
|
-
|
|
55
|
-
Copy the `.env.example` file into `.env` and populate with the required values.
|
|
56
|
-
|
|
57
|
-
### Build locally
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
npm build
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## IPFS Upload
|
|
64
|
-
|
|
65
|
-
Use the `uploadIPFSContent` method in `Ipfs` class to upload the content to IPFS. The function takes the following parameters:
|
|
66
|
-
|
|
67
|
-
- `type`: The type of the content. Based on ContentType enum.
|
|
68
|
-
- `content`: The content to be uploaded to IPFS as IPFSContentTypes.
|
|
69
|
-
|
|
70
|
-
The function returns the IPFS hash of the uploaded content.
|
|
71
|
-
|
|
72
|
-
For claims submission and assessment IPFS data, use the `get32BytesIPFSHash` method in `Ipfs` class to convert the IPFS hash you get from `uploadIPFSContent` to 32 bytes format. Use the `getIPFSCidFromHexBytes` method to convert back to standard IPFS hash.
|
|
73
|
-
|
|
74
|
-
### Example
|
|
45
|
+
`getProductById` and `getProductTypeById` accept an optional `params` array to include additional attributes:
|
|
75
46
|
|
|
76
47
|
```typescript
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const content: IPFSContentTypes = {
|
|
80
|
-
version: '2.0',
|
|
81
|
-
walletAddresses: ['0x1234567890'],
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const ipfs = new Ipfs(config: NexusSDKConfig = {});
|
|
85
|
-
const ipfsHash = await ipfs.uploadIPFSContent([ContentType.coverWalletAddresses, content]);
|
|
86
|
-
|
|
87
|
-
console.log(ipfsHash);
|
|
48
|
+
const product = await productApi.getProductById(247, ['proofOfLossInputTypes']);
|
|
49
|
+
const productType = await productApi.getProductTypeById(1, ['buyCoverForm']);
|
|
88
50
|
```
|
|
89
51
|
|
|
90
52
|
## Quote
|
|
@@ -98,11 +60,11 @@ interface NexusSDKConfig {
|
|
|
98
60
|
```
|
|
99
61
|
|
|
100
62
|
```typescript
|
|
101
|
-
const nexusSDK = new NexusSDK(config: NexusSDKConfig = {}
|
|
63
|
+
const nexusSDK = new NexusSDK(config: NexusSDKConfig = {})
|
|
102
64
|
```
|
|
103
65
|
|
|
104
66
|
```typescript
|
|
105
|
-
const quote = new Quote(config: NexusSDKConfig = {}
|
|
67
|
+
const quote = new Quote(config: NexusSDKConfig = {})
|
|
106
68
|
```
|
|
107
69
|
|
|
108
70
|
### Params
|
|
@@ -148,9 +110,14 @@ export interface GetQuoteAndBuyCoverInputsParams {
|
|
|
148
110
|
slippage?: number;
|
|
149
111
|
|
|
150
112
|
/**
|
|
151
|
-
* Optional IPFS CID string
|
|
113
|
+
* Optional IPFS CID string
|
|
152
114
|
*/
|
|
153
|
-
|
|
115
|
+
ipfsCid?: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Optional cover metadata (proof of loss and/or public data)
|
|
119
|
+
*/
|
|
120
|
+
coverMetadata?: CoverMetadataInput;
|
|
154
121
|
|
|
155
122
|
/**
|
|
156
123
|
* Optional commission ratio
|
|
@@ -170,18 +137,48 @@ export interface GetQuoteAndBuyCoverInputsParams {
|
|
|
170
137
|
}
|
|
171
138
|
```
|
|
172
139
|
|
|
173
|
-
###
|
|
140
|
+
### Cover metadata
|
|
141
|
+
|
|
142
|
+
Products may require cover metadata (proof of loss data and/or public data like quota share or AUM percentage).
|
|
143
|
+
The SDK validates the required metadata based on the product's `proofOfLossInputTypes` and the product type's `buyCoverForm` field,
|
|
144
|
+
then uploads it via the cover metadata API automatically.
|
|
145
|
+
|
|
146
|
+
You can also pass an existing IPFS CID directly via the `ipfsCid` param if you've already uploaded metadata.
|
|
147
|
+
|
|
148
|
+
#### Proof of loss types
|
|
149
|
+
|
|
150
|
+
Each product may require one or more proof-of-loss entry types, specified in `product.proofOfLossInputTypes`.
|
|
151
|
+
The available types and their content structures are:
|
|
152
|
+
|
|
153
|
+
| Type | Content Structure |
|
|
154
|
+
| ----------- | ------------------------------------------------------- |
|
|
155
|
+
| `address` | `{ address: string, label?: string }` |
|
|
156
|
+
| `validator` | `{ value: string, label?: string, role?: string }` |
|
|
157
|
+
| `free_text` | `{ value: string, label?: string }` |
|
|
158
|
+
| `api_key` | `{ credential: string, label: string, role: string }` |
|
|
159
|
+
| `csv` | `{ address: string, amount: string, currency: string }` |
|
|
160
|
+
|
|
161
|
+
#### Public data
|
|
162
|
+
|
|
163
|
+
Some product types require public data to be set via the `coverMetadata.publicData` field:
|
|
164
|
+
|
|
165
|
+
| `buyCoverForm` value | Required field |
|
|
166
|
+
| -------------------- | --------------------------------------------- |
|
|
167
|
+
| `withQuotaShare` | `publicData.quotaShare` (0-100) |
|
|
168
|
+
| `withAUM` | `publicData.aumCoverAmountPercentage` (0-100) |
|
|
169
|
+
| `basic` | No public data required |
|
|
170
|
+
|
|
171
|
+
### Example
|
|
174
172
|
|
|
175
173
|
```typescript
|
|
176
|
-
import { NexusSDK } from '@nexusmutual/sdk';
|
|
174
|
+
import { NexusSDK, CoverAsset } from '@nexusmutual/sdk';
|
|
177
175
|
|
|
178
|
-
const productId = 247;
|
|
176
|
+
const productId = 247;
|
|
179
177
|
const amount = '100';
|
|
180
178
|
const period = 30;
|
|
181
179
|
const coverAsset = CoverAsset.ETH;
|
|
182
180
|
const paymentAsset = CoverAsset.ETH;
|
|
183
181
|
const buyerAddress = '0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5';
|
|
184
|
-
const ipfsCidOrContent = 'QmXUzXDMbeKSCewUie34vPD7mCAGnshi4ULRy4h7DLmoRS';
|
|
185
182
|
|
|
186
183
|
const nexusSDK = new NexusSDK();
|
|
187
184
|
|
|
@@ -192,81 +189,95 @@ const { result, error } = await nexusSDK.quote.getQuoteAndBuyCoverInputs({
|
|
|
192
189
|
coverAsset,
|
|
193
190
|
paymentAsset,
|
|
194
191
|
buyerAddress,
|
|
195
|
-
|
|
192
|
+
ipfsCid,
|
|
193
|
+
coverMetadata: {
|
|
194
|
+
proofOfLoss: [{ type: 'address', content: [{ address: '0x...' }] }],
|
|
195
|
+
},
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
console.log(result);
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
See [examples/buy-cover.md](examples/buy-cover.md) for a full end-to-end example including on-chain transaction submission.
|
|
202
|
+
|
|
203
|
+
## Cover Metadata
|
|
204
|
+
|
|
205
|
+
Use the `CoverData` class (or `nexusSDK.cover`) to fetch covers, view cover metadata, and edit proof-of-loss data.
|
|
206
|
+
|
|
207
|
+
- **Get cover** — `sdk.cover.getCover(coverId)` returns cover details including `coverMetadataId`.
|
|
208
|
+
- **View metadata** — `sdk.cover.viewCoverMetadata({ coverMetadataId })` returns public data. Pass an EIP-712 signature to also retrieve private proof-of-loss data.
|
|
209
|
+
- **Edit metadata** — `sdk.cover.editCoverMetadata({ coverMetadataId, proofOfLoss, signature })` updates proof-of-loss entries. Requires an EIP-712 signature from the cover owner.
|
|
210
|
+
|
|
211
|
+
See the full walkthroughs:
|
|
212
|
+
|
|
213
|
+
- [examples/buy-cover.md](examples/buy-cover.md) — get a quote and submit a buy cover transaction
|
|
214
|
+
- [examples/view-cover-metadata.md](examples/view-cover-metadata.md) — view public and private metadata
|
|
215
|
+
- [examples/edit-cover-metadata.md](examples/edit-cover-metadata.md) — edit proof-of-loss data
|
|
216
|
+
|
|
217
|
+
## Authentication
|
|
218
|
+
|
|
219
|
+
The SDK exports EIP-712 helpers for building typed data objects used to authenticate with the Nexus Mutual API.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { buildAuthTypedData, buildCoverMetadataAuthMessage } from '@nexusmutual/sdk';
|
|
223
|
+
|
|
224
|
+
// Generic auth typed data
|
|
225
|
+
const typedData = buildAuthTypedData('Custom message');
|
|
226
|
+
|
|
227
|
+
// Cover metadata specific auth
|
|
228
|
+
const coverAuthTypedData = buildCoverMetadataAuthMessage();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Pass the returned object to your wallet's `signTypedData` method (viem, ethers, etc.).
|
|
232
|
+
|
|
233
|
+
## IPFS Upload
|
|
234
|
+
|
|
235
|
+
Use the `uploadIPFSContent` method in `Ipfs` class to upload content to IPFS. The function takes the following parameters:
|
|
236
|
+
|
|
237
|
+
- `type`: The type of the content. Based on ContentType enum.
|
|
238
|
+
- `content`: The content to be uploaded to IPFS as IPFSContentTypes.
|
|
239
|
+
|
|
240
|
+
The function returns the IPFS hash of the uploaded content.
|
|
241
|
+
|
|
242
|
+
For claims submission and assessment IPFS data, use the `get32BytesIPFSHash` method in `Ipfs` class to convert the IPFS hash you get from `uploadIPFSContent` to 32 bytes format. Use the `getIPFSCidFromHexBytes` method to convert back to standard IPFS hash.
|
|
243
|
+
|
|
244
|
+
> **Note:** Cover-related content types (validators, quota share, wallet addresses, etc.) have been removed from the IPFS module.
|
|
245
|
+
> Cover metadata is now managed through the `CoverData` class and the cover metadata API. See the [Cover Metadata](#cover-metadata) section.
|
|
246
|
+
|
|
247
|
+
### Example
|
|
202
248
|
|
|
203
249
|
```typescript
|
|
204
|
-
import {
|
|
250
|
+
import { Ipfs, ContentType } from '@nexusmutual/sdk';
|
|
205
251
|
|
|
206
|
-
const
|
|
207
|
-
const amount = '100';
|
|
208
|
-
const period = 30;
|
|
209
|
-
const coverAsset = CoverAsset.ETH;
|
|
210
|
-
const paymentAsset = CoverAsset.ETH;
|
|
211
|
-
const buyerAddress = '0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5';
|
|
212
|
-
const ipfsCidOrContent = 'QmXUzXDMbeKSCewUie34vPD7mCAGnshi4ULRy4h7DLmoRS';
|
|
252
|
+
const ipfs = new Ipfs();
|
|
213
253
|
|
|
214
|
-
const
|
|
254
|
+
const ipfsHash = await ipfs.uploadIPFSContent([
|
|
255
|
+
ContentType.stakingPoolDetails,
|
|
256
|
+
{ version: '1.0', poolName: 'My Pool' },
|
|
257
|
+
]);
|
|
215
258
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
amount,
|
|
219
|
-
period,
|
|
220
|
-
coverAsset,
|
|
221
|
-
paymentAsset,
|
|
222
|
-
buyerAddress,
|
|
223
|
-
ipfsCidOrContent,
|
|
224
|
-
});
|
|
259
|
+
console.log(ipfsHash);
|
|
260
|
+
```
|
|
225
261
|
|
|
226
|
-
|
|
262
|
+
## Development
|
|
263
|
+
|
|
264
|
+
### Install dependencies
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
npm ci
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### ENV variables setup
|
|
271
|
+
|
|
272
|
+
Copy the `.env.example` file into `.env` and populate with the required values.
|
|
273
|
+
|
|
274
|
+
### Build locally
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
npm build
|
|
227
278
|
```
|
|
228
279
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
The `ipfsCidOrContent` param must be a valid IPFS Cid or a valid `IPFSContentTypes` - the allowed types can be found in `src/types/ipfs.ts`.
|
|
232
|
-
|
|
233
|
-
### Product Types and IPFS Content Mapping
|
|
234
|
-
|
|
235
|
-
The following table shows the mapping between product types and their required IPFS content types:
|
|
236
|
-
|
|
237
|
-
| Product Type | Content Type | Content Structure | Description |
|
|
238
|
-
| -------------------------- | ----------------------------- | --------------------------------------------------------------- | ---------------------------- |
|
|
239
|
-
| ethSlashing | coverValidators | <pre>{ version: '1.0', validators: string[] }</pre> | Array of validator addresses |
|
|
240
|
-
| liquidCollectiveEthStaking | coverValidators | <pre>{ version: '1.0', validators: string[] }</pre> | Array of validator addresses |
|
|
241
|
-
| stakewiseEthStaking | coverValidators | <pre>{ version: '1.0', validators: string[] }</pre> | Array of validator addresses |
|
|
242
|
-
| sherlockQuotaShare | coverQuotaShare | <pre>{ version: '1.0', quotaShare: number }</pre> | Percentage value, 0 to 100 |
|
|
243
|
-
| unoReQuotaShare | coverQuotaShare | <pre>{ version: '1.0', quotaShare: number }</pre> | Percentage value, 0 to 100 |
|
|
244
|
-
| deFiPass | coverWalletAddress | <pre>{ version: '1.0', walletAddress: string }</pre> | Single wallet address |
|
|
245
|
-
| nexusMutual | coverWalletAddresses | <pre>{ version: '1.0', walletAddresses: string }</pre> | Single wallet address |
|
|
246
|
-
| nexusMutual | coverWalletAddresses | <pre>{ version: '2.0', walletAddresses: string[] }</pre> | Array of wallet addresses |
|
|
247
|
-
| followOn | coverFreeText | <pre>{ version: '1.0', freeText: string }</pre> | Free text description |
|
|
248
|
-
| fundPortfolio | coverAumCoverAmountPercentage | <pre>{ version: '1.0', aumCoverAmountPercentage: number }</pre> | Percentage value, 0 to 100 |
|
|
249
|
-
| generalizedFundPortfolio | coverAumCoverAmountPercentage | <pre>{ version: '1.0', aumCoverAmountPercentage: number }</pre> | Percentage value, 0 to 100 |
|
|
250
|
-
|
|
251
|
-
Note: The following product types do not require IPFS content:
|
|
252
|
-
|
|
253
|
-
- singleProtocol
|
|
254
|
-
- custody
|
|
255
|
-
- yieldToken
|
|
256
|
-
- sherlockExcess
|
|
257
|
-
- nativeProtocol
|
|
258
|
-
- theRetailMutual
|
|
259
|
-
- multiProtocol
|
|
260
|
-
- ethSlashingUmbrella
|
|
261
|
-
- openCoverTransaction
|
|
262
|
-
- sherlockBugBounty
|
|
263
|
-
- immunefiBugBounty
|
|
264
|
-
|
|
265
|
-
For a complete list of products and product types, use the API endpoints:
|
|
266
|
-
`GET https://api.nexusmutual.io/v2/products` and `GET https://api.nexusmutual.io/v2/product-types`,
|
|
267
|
-
or the `ProductAPI.getAllProducts()` and `ProductAPI.getAllProductTypes()` helpers.
|
|
268
|
-
|
|
269
|
-
### Validation Errors
|
|
280
|
+
## Validation Errors
|
|
270
281
|
|
|
271
282
|
IPFS content is validated using [Zod schemas](https://www.npmjs.com/package/zod), if validation fails, the error response will contain a stringified array of Zod validation errors in the `error.message` field. These errors provide detailed information about what went wrong during validation.
|
|
272
283
|
|