@nexusmutual/sdk 0.6.5 → 0.7.0-rc1

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`.