@nexusmutual/sdk 0.6.6 → 0.7.0-rc2

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 CHANGED
@@ -12,7 +12,7 @@ This package only exports CommonJS modules. You can import it like this:
12
12
 
13
13
  ```js
14
14
  // Usage with ES6 modules
15
- import { products, productTypes } from '@nexusmutual/sdk'
15
+ import { products, productTypes } from '@nexusmutual/sdk';
16
16
  ```
17
17
 
18
18
  ## Nexus Mutual contract addresses and abis
@@ -25,6 +25,7 @@ The `products` folder contains all protocols listed on Nexus Mutual.
25
25
 
26
26
  If you're a protocol owner and want to update any details (i.e. logo, website, etc), please submit a PR.
27
27
  Logos should meet the following criteria:
28
+
28
29
  - svg format, with 1:1 ratio
29
30
  - no fixed width or height
30
31
  - the image should reach the edge of the viewbox
@@ -41,9 +42,95 @@ npm ci
41
42
 
42
43
  Copy the `.env.example` file into `.env` and populate with the required values.
43
44
 
44
-
45
45
  ### Build locally
46
46
 
47
47
  ```
48
48
  npm build
49
- ```
49
+ ```
50
+
51
+ ## IPFS Upload Utils
52
+
53
+ Use the `uploadIPFSContent` function from `src/ipfs/uploadIPFSContent.ts` to upload the content to IPFS. The function takes the following parameters:
54
+
55
+ - `type`: The type of the content. Based on ContentType enum.
56
+ - `content`: The content to be uploaded to IPFS as IPFSContentTypes.
57
+
58
+ The function returns the IPFS hash of the uploaded content.
59
+
60
+ ### Example
61
+
62
+ ```typescript
63
+ import { uploadIPFSContent, ContentType, IPFSContentTypes } from '@nexusmutual/sdk';
64
+
65
+ const content: IPFSContentTypes = {
66
+ version: '2.0.',
67
+ walletAddresses: ['0x1234567890'],
68
+ };
69
+
70
+ const ipfsHash = await uploadIPFSContent(ContentType.coverWalletAddresses, content);
71
+
72
+ console.log(ipfsHash);
73
+ ```
74
+
75
+ ## getQuoteAndBuyCoverInputs
76
+
77
+ Use the `getQuoteAndBuyCoverInputs` function from `src/cover/getQuoteAndBuyCoverInputs.ts` to get the inputs required to get a quote and buy cover. The function has 2 overloads. One allows you to pass an IPFS Cid for the cover metadata, and the other allows you to pass the cover metadata directly. The function returns the inputs required to get a quote and buy cover.
78
+
79
+ ### Example
80
+
81
+ 1st overload:
82
+
83
+ ```typescript
84
+ import { getQuoteAndBuyCoverInputs } from '@nexusmutual/sdk';
85
+
86
+ const productId = 1;
87
+ const coverAmount = '100';
88
+ const coverPeriod = 30;
89
+ const coverAsset = CoverAsset.ETH;
90
+ const buyerAddress = '0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5';
91
+ const ipfsCid = 'QmYfSDbuQLqJ2MAG3ATRjUPVFQubAhAM5oiYuuu9Kfs8RY';
92
+
93
+ const quoteAndBuyCoverInputs = await getQuoteAndBuyCoverInputs(
94
+ productId,
95
+ coverAmount,
96
+ coverPeriod,
97
+ coverAsset,
98
+ buyerAddress,
99
+ undefined,
100
+ ipfsCid,
101
+ );
102
+
103
+ console.log(quoteAndBuyCoverInputs);
104
+ ```
105
+
106
+ 2nd overload:
107
+
108
+ ```typescript
109
+ import { getQuoteAndBuyCoverInputs, IPFSContentTypes } from '@nexusmutual/sdk';
110
+
111
+ const productId = 247;
112
+ const coverAmount = '100';
113
+ const coverPeriod = 30;
114
+ const coverAsset = CoverAsset.ETH;
115
+ const buyerAddress = '0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5';
116
+ const ipfsContent: IPFSContentTypes = {
117
+ version: '2.0.',
118
+ walletAddresses: ['0x1234567890'],
119
+ };
120
+
121
+ const quoteAndBuyCoverInputs = await getQuoteAndBuyCoverInputs(
122
+ productId,
123
+ coverAmount,
124
+ coverPeriod,
125
+ coverAsset,
126
+ buyerAddress,
127
+ ipfsContent,
128
+ );
129
+
130
+ console.log(quoteAndBuyCoverInputs);
131
+ ```
132
+
133
+ If you pass The `ipfsContent` param, the function will upload the content to IPFS and use the IPFS hash returned for the buy cover inputs `ipfsData` param. If you pass the `ipfsCid` param, the function will use the IPFS hash directly.
134
+
135
+ The `ipfsCid` param must be a valid IPFS Cid.
136
+ The `ipfsContent` param must be a valid `IPFSContentTypes` - the allowed types can be found in `src/types/ipfs.ts`.
@@ -2797,7 +2797,7 @@
2797
2797
  "ETH"
2798
2798
  ],
2799
2799
  "isPrivate": false,
2800
- "timestamp": 1723127459,
2800
+ "timestamp": 1731583079,
2801
2801
  "minPrice": 100
2802
2802
  },
2803
2803
  {
@@ -3065,7 +3065,7 @@
3065
3065
  "USDC"
3066
3066
  ],
3067
3067
  "isPrivate": false,
3068
- "timestamp": 1734557999,
3068
+ "timestamp": 1731583079,
3069
3069
  "minPrice": 100
3070
3070
  },
3071
3071
  {
@@ -4049,7 +4049,7 @@
4049
4049
  "USDC"
4050
4050
  ],
4051
4051
  "isPrivate": false,
4052
- "timestamp": 1722950807,
4052
+ "timestamp": 1723127459,
4053
4053
  "minPrice": 100
4054
4054
  },
4055
4055
  {
@@ -4084,7 +4084,7 @@
4084
4084
  "cbBTC"
4085
4085
  ],
4086
4086
  "isPrivate": false,
4087
- "timestamp": 1731583079,
4087
+ "timestamp": 1734557999,
4088
4088
  "minPrice": 100
4089
4089
  },
4090
4090
  {
@@ -4143,7 +4143,7 @@
4143
4143
  "cbBTC"
4144
4144
  ],
4145
4145
  "isPrivate": false,
4146
- "timestamp": 1734557999,
4146
+ "timestamp": 1726227311,
4147
4147
  "minPrice": 100
4148
4148
  },
4149
4149
  {
@@ -4181,7 +4181,7 @@
4181
4181
  "cbBTC"
4182
4182
  ],
4183
4183
  "isPrivate": false,
4184
- "timestamp": 1734557999,
4184
+ "timestamp": 1725264851,
4185
4185
  "minPrice": 100
4186
4186
  },
4187
4187
  {
@@ -4201,7 +4201,7 @@
4201
4201
  "cbBTC"
4202
4202
  ],
4203
4203
  "isPrivate": true,
4204
- "timestamp": 1726227311,
4204
+ "timestamp": 1725264851,
4205
4205
  "minPrice": 100
4206
4206
  },
4207
4207
  {
@@ -4239,7 +4239,7 @@
4239
4239
  "cbBTC"
4240
4240
  ],
4241
4241
  "isPrivate": false,
4242
- "timestamp": 1734557999,
4242
+ "timestamp": 1731583079,
4243
4243
  "minPrice": 100
4244
4244
  },
4245
4245
  {
@@ -4368,7 +4368,7 @@
4368
4368
  "USDC"
4369
4369
  ],
4370
4370
  "isPrivate": false,
4371
- "timestamp": 1734557999,
4371
+ "timestamp": 1726758407,
4372
4372
  "minPrice": 100
4373
4373
  },
4374
4374
  {
@@ -4552,7 +4552,7 @@
4552
4552
  "USDC"
4553
4553
  ],
4554
4554
  "isPrivate": true,
4555
- "timestamp": 1733326763,
4555
+ "timestamp": 1733753135,
4556
4556
  "minPrice": 100
4557
4557
  },
4558
4558
  {
@@ -4571,7 +4571,7 @@
4571
4571
  "cbBTC"
4572
4572
  ],
4573
4573
  "isPrivate": false,
4574
- "timestamp": 1734557999,
4574
+ "timestamp": 1733326763,
4575
4575
  "minPrice": 100
4576
4576
  },
4577
4577
  {
package/dist/index.d.mts CHANGED
@@ -124,21 +124,127 @@ type GetQuoteResponse = {
124
124
  };
125
125
  type GetQuoteApiResponse = ApiResponse<GetQuoteResponse, undefined>;
126
126
 
127
- /**
128
- * Retrieves a quote for buying cover and prepares the necessary inputs for CoverBroker.buyCover method
129
- * The cover must be purchased using the same asset as the cover
130
- *
131
- * @param {Integer} productId - The ID of the product for which cover is being purchased.
132
- * @param {IntString} coverAmount - The amount of cover in smallest unit of currency (i.e. wei)
133
- * @param {Integer} coverPeriod - The duration of the cover in days (28-365).
134
- * @param {CoverAsset} coverAsset - The asset for which cover is being purchased; the purchase must use the same asset.
135
- * @param {Address} coverBuyerAddress - The Ethereum address of the buyer.
136
- * @param {number} slippage - The acceptable slippage percentage. Must be between 0-1 (Defaults to 0.001 ~ 0.1%)
137
- * @param {string} ipfsCid - The IPFS CID for additional data (optional).
138
- * @param {string} coverRouterUrl - Used to override the default CoverRouter URL which is bundled this library.
139
- * @return {Promise<GetQuoteApiResponse | ErrorApiResponse>} Returns a successful quote response or an error response.
140
- */
127
+ declare enum ContentType {
128
+ coverValidators = "coverValidators",
129
+ coverQuotaShare = "coverQuotaShare",
130
+ coverAumCoverAmountPercentage = "coverAumCoverAmountPercentage",
131
+ coverWalletAddress = "coverWalletAddress",
132
+ coverWalletAddresses = "coverWalletAddresses",
133
+ coverFreeText = "coverFreeText",
134
+ stakingPoolDetails = "stakingPoolDetails",
135
+ claimProof = "claimProof",
136
+ assessmentCriteriaAnswers = "assessmentCriteriaAnswers",
137
+ governanceProposal = "governanceProposal",
138
+ governanceCategory = "governanceCategory"
139
+ }
140
+ type CoverValidators = {
141
+ version: '1.0';
142
+ validators: string[];
143
+ };
144
+ type CoverQuotaShare = {
145
+ version: '1.0';
146
+ quotaShare: number;
147
+ };
148
+ type CoverAumCoverAmountPercentage = {
149
+ version: '1.0';
150
+ aumCoverAmountPercentage: number;
151
+ };
152
+ type CoverWalletAddress = {
153
+ version: '1.0';
154
+ walletAddress: string;
155
+ };
156
+ type CoverWalletAddresses = {
157
+ version: '1.0';
158
+ walletAddresses: string;
159
+ } | {
160
+ version: '2.0';
161
+ walletAddresses: string[];
162
+ };
163
+ type CoverFreeText = {
164
+ version: '1.0';
165
+ freeText: string;
166
+ };
167
+ type StakingPoolDetails = {
168
+ version: '1.0';
169
+ poolName: string;
170
+ poolDescription: string;
171
+ };
172
+ type ClaimProof = {
173
+ version: '1.0';
174
+ coverId: number;
175
+ affectedAddresses: string[];
176
+ affectedChain: string;
177
+ incidentDescription: string;
178
+ incidentTransactionHashes: string[];
179
+ incidentEvidenceLinks: string[];
180
+ attachedFilesHashes: string[];
181
+ };
182
+ type AssessmentCriteriaAnswers = {
183
+ version: '1.0';
184
+ answers: Record<string, string>;
185
+ };
186
+ type GovernanceProposal = {
187
+ version: '1.0';
188
+ proposal: string;
189
+ };
190
+ type GovernanceCategory = {
191
+ version: '1.0';
192
+ category: string;
193
+ };
194
+ type IPFSContentTypes = CoverValidators | CoverQuotaShare | CoverAumCoverAmountPercentage | CoverWalletAddress | CoverWalletAddresses | CoverFreeText | StakingPoolDetails | ClaimProof | AssessmentCriteriaAnswers | GovernanceProposal | GovernanceCategory;
195
+ type IPFSContentAndType = [type: ContentType.coverValidators, content: CoverValidators] | [type: ContentType.coverQuotaShare, content: CoverQuotaShare] | [type: ContentType.coverAumCoverAmountPercentage, content: CoverAumCoverAmountPercentage] | [type: ContentType.coverWalletAddress, content: CoverWalletAddress] | [type: ContentType.coverWalletAddresses, content: CoverWalletAddresses] | [type: ContentType.coverFreeText, content: CoverFreeText] | [type: ContentType.stakingPoolDetails, content: StakingPoolDetails] | [type: ContentType.claimProof, content: ClaimProof] | [type: ContentType.assessmentCriteriaAnswers, content: AssessmentCriteriaAnswers] | [type: ContentType.governanceProposal, content: GovernanceProposal] | [type: ContentType.governanceCategory, content: GovernanceCategory];
196
+ declare const IPFS_CONTENT_TYPE_BY_PRODUCT_TYPE: {
197
+ 6: ContentType;
198
+ 5: ContentType;
199
+ 4: ContentType;
200
+ 7: ContentType;
201
+ 10: ContentType;
202
+ 16: ContentType;
203
+ 19: ContentType;
204
+ 17: ContentType;
205
+ 14: ContentType;
206
+ 20: ContentType;
207
+ 0: undefined;
208
+ 1: undefined;
209
+ 2: undefined;
210
+ 3: undefined;
211
+ 8: undefined;
212
+ 9: undefined;
213
+ 11: undefined;
214
+ 12: undefined;
215
+ 13: undefined;
216
+ 15: undefined;
217
+ 18: undefined;
218
+ };
219
+ interface IPFSContentForProductType {
220
+ [ProductTypes.ethSlashing]: CoverValidators;
221
+ [ProductTypes.liquidCollectiveEthStaking]: CoverValidators;
222
+ [ProductTypes.stakewiseEthStaking]: CoverValidators;
223
+ [ProductTypes.sherlockQuotaShare]: CoverQuotaShare;
224
+ [ProductTypes.unoReQuotaShare]: CoverQuotaShare;
225
+ [ProductTypes.deFiPass]: CoverWalletAddress;
226
+ [ProductTypes.nexusMutual]: CoverWalletAddresses;
227
+ [ProductTypes.followOn]: CoverFreeText;
228
+ [ProductTypes.fundPortfolio]: CoverAumCoverAmountPercentage;
229
+ [ProductTypes.generalisedFundPortfolio]: CoverAumCoverAmountPercentage;
230
+ [ProductTypes.protocol]: undefined;
231
+ [ProductTypes.custody]: undefined;
232
+ [ProductTypes.yieldToken]: undefined;
233
+ [ProductTypes.sherlockExcess]: undefined;
234
+ [ProductTypes.nativeProtocol]: undefined;
235
+ [ProductTypes.theRetailMutual]: undefined;
236
+ [ProductTypes.bundledProtocol]: undefined;
237
+ [ProductTypes.ethSlashingUmbrella]: undefined;
238
+ [ProductTypes.openCoverTransaction]: undefined;
239
+ [ProductTypes.sherlockBugBounty]: undefined;
240
+ [ProductTypes.immunefiBugBounty]: undefined;
241
+ }
242
+ type IPFSUploadServiceResponse = {
243
+ ipfsHash: string;
244
+ };
245
+
141
246
  declare function getQuoteAndBuyCoverInputs(productId: Integer, coverAmount: IntString, coverPeriod: Integer, coverAsset: CoverAsset, coverBuyerAddress: Address, slippage?: number, ipfsCid?: string, coverRouterUrl?: string): Promise<GetQuoteApiResponse | ErrorApiResponse>;
247
+ declare function getQuoteAndBuyCoverInputs<ProductTypes extends keyof IPFSContentForProductType>(productId: Integer, coverAmount: IntString, coverPeriod: Integer, coverAsset: CoverAsset, coverBuyerAddress: Address, slippage?: number, ipfsContent?: IPFSContentForProductType[ProductTypes], coverRouterUrl?: string): Promise<GetQuoteApiResponse | ErrorApiResponse>;
142
248
 
143
249
  type Reserves = {
144
250
  ethReserve: bigint;
@@ -3117,7 +3223,7 @@ var products = [
3117
3223
  "ETH"
3118
3224
  ],
3119
3225
  isPrivate: false,
3120
- timestamp: 1723127459,
3226
+ timestamp: 1731583079,
3121
3227
  minPrice: 100
3122
3228
  },
3123
3229
  {
@@ -3386,7 +3492,7 @@ var products = [
3386
3492
  "USDC"
3387
3493
  ],
3388
3494
  isPrivate: false,
3389
- timestamp: 1734557999,
3495
+ timestamp: 1731583079,
3390
3496
  minPrice: 100
3391
3497
  },
3392
3498
  {
@@ -4385,7 +4491,7 @@ var products = [
4385
4491
  "USDC"
4386
4492
  ],
4387
4493
  isPrivate: false,
4388
- timestamp: 1722950807,
4494
+ timestamp: 1723127459,
4389
4495
  minPrice: 100
4390
4496
  },
4391
4497
  {
@@ -4420,7 +4526,7 @@ var products = [
4420
4526
  "cbBTC"
4421
4527
  ],
4422
4528
  isPrivate: false,
4423
- timestamp: 1731583079,
4529
+ timestamp: 1734557999,
4424
4530
  minPrice: 100
4425
4531
  },
4426
4532
  {
@@ -4479,7 +4585,7 @@ var products = [
4479
4585
  "cbBTC"
4480
4586
  ],
4481
4587
  isPrivate: false,
4482
- timestamp: 1734557999,
4588
+ timestamp: 1726227311,
4483
4589
  minPrice: 100
4484
4590
  },
4485
4591
  {
@@ -4518,7 +4624,7 @@ var products = [
4518
4624
  "cbBTC"
4519
4625
  ],
4520
4626
  isPrivate: false,
4521
- timestamp: 1734557999,
4627
+ timestamp: 1725264851,
4522
4628
  minPrice: 100
4523
4629
  },
4524
4630
  {
@@ -4538,7 +4644,7 @@ var products = [
4538
4644
  "cbBTC"
4539
4645
  ],
4540
4646
  isPrivate: true,
4541
- timestamp: 1726227311,
4647
+ timestamp: 1725264851,
4542
4648
  minPrice: 100
4543
4649
  },
4544
4650
  {
@@ -4576,7 +4682,7 @@ var products = [
4576
4682
  "cbBTC"
4577
4683
  ],
4578
4684
  isPrivate: false,
4579
- timestamp: 1734557999,
4685
+ timestamp: 1731583079,
4580
4686
  minPrice: 100
4581
4687
  },
4582
4688
  {
@@ -4709,7 +4815,7 @@ var products = [
4709
4815
  "USDC"
4710
4816
  ],
4711
4817
  isPrivate: false,
4712
- timestamp: 1734557999,
4818
+ timestamp: 1726758407,
4713
4819
  minPrice: 100
4714
4820
  },
4715
4821
  {
@@ -4897,7 +5003,7 @@ var products = [
4897
5003
  "USDC"
4898
5004
  ],
4899
5005
  isPrivate: true,
4900
- timestamp: 1733326763,
5006
+ timestamp: 1733753135,
4901
5007
  minPrice: 100
4902
5008
  },
4903
5009
  {
@@ -4916,7 +5022,7 @@ var products = [
4916
5022
  "cbBTC"
4917
5023
  ],
4918
5024
  isPrivate: false,
4919
- timestamp: 1734557999,
5025
+ timestamp: 1733326763,
4920
5026
  minPrice: 100
4921
5027
  },
4922
5028
  {
@@ -5165,7 +5271,33 @@ declare const nexusSdk: {
5165
5271
  productCategoryMap: {
5166
5272
  [productId: number]: ProductCategoryEnum;
5167
5273
  };
5274
+ uploadIPFSContent: (...[type, content]: IPFSContentAndType) => Promise<string>;
5275
+ validateIPFSCid: (ipfsCid: string) => void;
5168
5276
  getQuoteAndBuyCoverInputs: typeof getQuoteAndBuyCoverInputs;
5277
+ ContentType: typeof ContentType;
5278
+ IPFS_CONTENT_TYPE_BY_PRODUCT_TYPE: {
5279
+ 6: ContentType;
5280
+ 5: ContentType;
5281
+ 4: ContentType;
5282
+ 7: ContentType;
5283
+ 10: ContentType;
5284
+ 16: ContentType;
5285
+ 19: ContentType;
5286
+ 17: ContentType;
5287
+ 14: ContentType;
5288
+ 20: ContentType;
5289
+ 0: undefined;
5290
+ 1: undefined;
5291
+ 2: undefined;
5292
+ 3: undefined;
5293
+ 8: undefined;
5294
+ 9: undefined;
5295
+ 11: undefined;
5296
+ 12: undefined;
5297
+ 13: undefined;
5298
+ 15: undefined;
5299
+ 18: undefined;
5300
+ };
5169
5301
  calculatePremiumWithCommissionAndSlippage: (premium: bigint, commission?: number, slippage?: number) => bigint;
5170
5302
  calculateExactNxmForEth: (ethIn: bigint, reserves: Reserves) => bigint;
5171
5303
  calculateExactEthForNxm: (nxmIn: bigint, reserves: Reserves) => bigint;
@@ -42099,4 +42231,4 @@ declare const productsMap: Record<number, {
42099
42231
  minPrice: number;
42100
42232
  }>;
42101
42233
 
42102
- export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, CoverAsset, CoverId, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, FloatString, GetQuoteApiResponse, GetQuoteResponse, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, ProductCategoryEnum, ProductTypes, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, allPrivateProductsIds, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, categoryLabelByEnum, nexusSdk as default, getQuoteAndBuyCoverInputs, productCategoryMap, productTypes, products, productsMap };
42234
+ export { Address, ApiResponse, BuyCoverInput, BuyCoverParams, COMMISSION_DENOMINATOR, Capacity, ContentType, CoverAsset, CoverId, CoverRouterProductCapacityResponse, CoverRouterQuoteResponse, DEFAULT_COMMISSION_RATIO, DEFAULT_SLIPPAGE, ErrorApiResponse, ErrorResponse, FloatString, GetQuoteApiResponse, GetQuoteResponse, IPFSContentAndType, IPFSContentForProductType, IPFSContentTypes, IPFSUploadServiceResponse, IPFS_CONTENT_TYPE_BY_PRODUCT_TYPE, IntString, Integer, LogoFileName, LogoName, MAXIMUM_COVER_PERIOD, MINIMUM_COVER_PERIOD, NEXUS_MUTUAL_DAO_TREASURY_ADDRESS, PoolAllocationRequest, PoolCapacity, ProductCategoryEnum, ProductTypes, Quote, QuoteDisplayInfo, Reserves, SLIPPAGE_DENOMINATOR, TARGET_PRICE_DENOMINATOR, allLogoFileNames, allLogoNames, allPrivateProductsIds, calculateEthForExactNxm, calculateExactEthForNxm, calculateExactNxmForEth, calculateNxmForExactEth, calculatePremiumWithCommissionAndSlippage, calculatePriceImpactA, calculatePriceImpactB, calculateSpotPrice, categoryLabelByEnum, nexusSdk as default, getQuoteAndBuyCoverInputs, productCategoryMap, productTypes, products, productsMap };