@centrifuge/sdk 0.4.0 → 0.4.2

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
@@ -1,198 +1,219 @@
1
1
  # Centrifuge SDK [![Codecov](https://codecov.io/gh/centrifuge/sdk/graph/badge.svg?token=Q2yU8QfefP)](https://codecov.io/gh/centrifuge/sdk) [![Build CI status](https://github.com/centrifuge/sdk/actions/workflows/build-test-report.yml/badge.svg)](https://github.com/centrifuge/sdk/actions/workflows/build-test-report.yml) [![Latest Release](https://img.shields.io/github/v/release/centrifuge/sdk?sort=semver)](https://github.com/centrifuge/sdk/releases/latest)
2
2
 
3
- The Centrifuge SDK is a JavaScript client for interacting with the [Centrifuge](https://centrifuge.io) ecosystem. It provides a comprehensive, fully typed library to integrate investments and redemptions, generate financial reports, manage pools, and much more.
3
+ # Centrifuge SDK
4
+
5
+ A fully typed JavaScript client to interact with the [Centrifuge](https://centrifuge.io) ecosystem. Use it to manage pools, investments, redemptions, financial reports, and more.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Features](#features)
12
+ 2. [Installation](#installation)
13
+ 3. [Getting Started](#getting-started)
14
+ - [Initialization & Configuration](#initialization--configuration)
15
+ - [Queries](#queries)
16
+ - [Transactions](#transactions)
17
+ - [Investments](#investments)
18
+ - [Reports](#reports)
19
+ 4. [Developer Guide](#developer-guide)
20
+ - [Development Mode](#development-mode)
21
+ - [Building](#building)
22
+ - [Testing](#testing)
23
+ 5. [Contributing](#contributing)
24
+ - [Docs](#docs)
25
+ - [PR Conventions & Versioning](#pr-naming-convention--versioning)
26
+ 6. [License](#license)
27
+
28
+ ---
29
+
30
+ ## Features
31
+
32
+ - Typed JavaScript/TypeScript client
33
+ - Support for mainnet & testnet environments
34
+ - Full querying interface (readonly) + subscription support
35
+ - Transaction support (awaitable or observable for updates)
36
+ - Handling of share classes, vaults, and ERC-7540 tokenized vaults
37
+ - Reports: balance sheet, profit & loss, cash flow
38
+
39
+ ---
4
40
 
5
41
  ## Installation
6
42
 
7
43
  ```bash
8
- npm install --save @centrifuge/sdk
44
+ npm install @centrifuge/sdk
9
45
  ```
10
46
 
11
- ## Init and config
47
+ ## Getting Started
12
48
 
13
- Create an instance and pass optional configuration
49
+ ### Initialization & Configuration
14
50
 
15
- ```js
51
+ ```typescript
16
52
  import Centrifuge from '@centrifuge/sdk'
17
53
 
18
- const centrifuge = new Centrifuge()
54
+ const centrifuge = new Centrifuge({
55
+ environment: 'mainnet' | 'testnet', // optional, defaults to 'mainnet'
56
+ rpcUrls?: { [chainId: number]: string }, // optional RPC endpoints
57
+ indexerUrl?: string, // optional indexer API URL
58
+ ipfsUrl?: string // optional IPFS gateway, default: https://centrifuge.mypinata.cloud
59
+ })
19
60
  ```
20
61
 
21
- The following config options can be passed on initialization of the SDK:
22
-
23
- - `environment: 'mainnet' | 'testnet'`
24
- - Optional
25
- - Default value: `mainnet`
26
- - `rpcUrls: Record<number, string>`
27
- - Optional
28
- - A object mapping chain ids to RPC URLs
29
- - `indexerUrl: string`
30
- - Optional
31
- - A URL for the indexer
32
- - `ipfsUrl: string`
33
- - Optional
34
- - A URL for an IPFS gateway
35
- - Default value: `https://centrifuge.mypinata.cloud`
36
-
37
- ## Queries
38
-
39
- Queries return Promise-like [Observables](https://rxjs.dev/guide/observable). They can be either awaited to get a single value, or subscribed to to get fresh data whenever on-chain data changes.
40
-
41
- ```js
42
- try {
43
- const pool = await centrifuge.pools()
44
- } catch (error) {
45
- console.error(error)
46
- }
47
- ```
62
+ ### Queries
63
+
64
+ Queries return Observables (rxjs), which can be:
65
+
66
+ - awaited (for one value), or
67
+ - subscribed to (to receive updates when on-chain data changes)
68
+
69
+ ```typescript
70
+ const pools = await centrifuge.pools()
48
71
 
49
- ```js
72
+ // Or subscribe
50
73
  const subscription = centrifuge.pools().subscribe(
51
- (pool) => console.log(pool),
74
+ (pools) => console.log(pools),
52
75
  (error) => console.error(error)
53
76
  )
77
+
78
+ // Later, to stop updates:
54
79
  subscription.unsubscribe()
55
80
  ```
56
81
 
57
- The returned results are either immutable values, or entities that can be further queried.
58
-
59
- ## Transactions
82
+ ### Transactions
60
83
 
61
- To perform transactions, you need to set a signer on the `centrifuge` instance.
84
+ - Before calling transaction methods, set a signer on the centrifuge instance.
85
+ - The signer can be:
86
+ - An EIP-1193-compatible provider
87
+ - A Viem LocalAccount
88
+ - Transactions, like queries, support either awaiting for completion or subscribing for status updates.
62
89
 
63
- ```js
90
+ ```typescript
64
91
  centrifuge.setSigner(signer)
65
- ```
66
-
67
- `signer` can be either a [EIP1193](https://eips.ethereum.org/EIPS/eip-1193)-compatible provider or a Viem [LocalAccount](https://viem.sh/docs/accounts/local).
68
92
 
69
- With this you can call transaction methods. Similar to queries they can be awaited to get their final result, or subscribed to get get status updates.
70
-
71
- ```js
72
93
  const pool = await centrifuge.pool('1')
73
- try {
74
- const status = await pool.closeEpoch()
75
- console.log(status)
76
- } catch (error) {
77
- console.error(error)
78
- }
79
- ```
94
+ const tx = await pool.closeEpoch()
95
+ console.log(tx.hash)
80
96
 
81
- ```js
82
- const pool = await centrifuge.pool('1')
83
- const subscription = pool.closeEpoch().subscribe(
84
- (status) => console.log(pool),
97
+ // or, subscribe to transaction lifecycle:
98
+ const sub = pool.closeEpoch().subscribe(
99
+ (status) => console.log(status),
85
100
  (error) => console.error(error),
86
- () => console.log('complete')
101
+ () => console.log('Done')
87
102
  )
88
103
  ```
89
104
 
90
- ## Investments
91
-
92
- Investments for a pool are done via [ERC-7540 Tokenized Vaults](https://eips.ethereum.org/EIPS/eip-7540). Vaults can be deployed for a share class on any supported network, for any supported currency
105
+ ### Investments
93
106
 
94
- Retrieve a vault by querying it from the pool:
107
+ The SDK supports [ERC-7540](https://eips.ethereum.org/EIPS/eip-7540) tokenized vaults. Vaults are created per share class, chain, and currency.
95
108
 
96
- ```js
109
+ ```typescript
97
110
  const pool = await centrifuge.pool('1')
98
- const vault = await pool.vault(1, '0xabc...', '0xdef...') // Chain ID, share class ID, investment currency address
111
+ const vault = await pool.vault(1, '0xShareClassAddress', '0xInvestmentCurrencyAddress')
99
112
  ```
100
113
 
101
- Query the state of an investment on the vault for an investor:
102
-
103
- ```js
104
- const investment = await vault.investment('0x123...')
105
- // Will return an object containing:
106
- // isAllowedToInvest - Whether an investor is allowed to invest in the share class
107
- // investmentCurrency - The ERC20 token that is used to invest in the vault
108
- // investmentCurrencyBalance - The balance of the investor of the investment currency
109
- // investmentCurrencyAllowance - The allowance of the vault
110
- // shareCurrency - The ERC20 token that is issued to investors to account for their share in the share class
111
- // shareBalance - The number of shares the investor has in the share class
112
- // claimableInvestShares - The number of shares an investor can claim after their invest order has been processed (partially or not)
113
- // claimableInvestCurrencyEquivalent - The equivalent value of the claimable shares denominated in the invest currency
114
- // claimableRedeemCurrency - The amout of money an investor can claim after their redeem order has been processed (partially or not)
115
- // claimableRedeemSharesEquivalent - The amount of shares that have been redeemed for which the investor can claim money
116
- // pendingInvestCurrency - The amount of money that the investor wants to invest in the share class that has not been processed yet
117
- // pendingRedeemShares - The amount of shares that the investor wants to redeem from the share class that has not been processed yet
118
- // claimableCancelInvestCurrency - The amount of money an investor can claim after an invest order cancellation has been processed
119
- // claimableCancelRedeemShares - The amount of shares an investor can claim after a redeem order cancellation has been processed
120
- // hasPendingCancelInvestRequest - Whether the investor has an invest order that is in the process of being cancelled
121
- // hasPendingCancelRedeemRequest - Whether the investor has a redeem order that is in the process of being cancelled
114
+ #### Vault Types
115
+
116
+ Vaults can behave differently depending on how the pool is configured:
117
+
118
+ - Synchronous deposit vaults
119
+ These vaults follow a hybrid model using both ERC-4626 and ERC-7540. Deposits are executed instantly using ERC-4626 behavior, allowing users to receive shares immediately. However, redemptions are handled asynchronously through ERC-7540, using the Hub to queue and manage the withdrawal requests.
120
+
121
+ - Asynchronous vaults
122
+ Asynchronous vaults are fully request-based and follow the ERC-7540 standard. They allow both deposit and redemption actions to be handled through an asynchronous workflow, using the Centrifuge Hub to manage requests.
123
+
124
+ You can query an individual investor’s state:
125
+
126
+ ```typescript
127
+ const inv = await vault.investment('0xInvestorAddress')
128
+
129
+ // Example returned fields include:
130
+ //   isAllowedToInvest
131
+ //   investmentCurrency, investmentCurrencyBalance, investmentCurrencyAllowance
132
+ //   shareCurrency, shareBalance
133
+ //   claimableInvestShares, claimableInvestCurrencyEquivalent
134
+ //   claimableRedeemCurrency, claimableRedeemSharesEquivalent
135
+ //   pendingInvestCurrency, pendingRedeemShares
136
+ //   hasPendingCancelInvestRequest, hasPendingCancelRedeemRequest
122
137
  ```
123
138
 
124
- Invest in a vault:
139
+ To invest:
125
140
 
126
- ```js
141
+ ```typescript
127
142
  const result = await vault.increaseInvestOrder(1000)
128
143
  console.log(result.hash)
129
144
  ```
130
145
 
131
- Once an order has been processed, `claimableInvestShares` will positive and shares can be claimed with:
146
+ Once processed, any claimable shares or currencies can be claimed:
132
147
 
133
- ```js
134
- const result = await vault.claim()
148
+ ```typescript
149
+ const claimResult = await vault.claim()
135
150
  ```
136
151
 
137
- ## Reports
152
+ ### Reports
138
153
 
139
- Reports are generated from data from the Centrifuge API and are combined with pool metadata to provide a comprehensive view of the pool's financials.
154
+ You can generate financial reports for a pool based on on-chain + API data.
140
155
 
141
- Available reports are:
156
+ Available report types:
142
157
 
143
- - `balanceSheet`
144
- - `profitAndLoss`
145
- - `cashflow`
146
-
147
- ```ts
148
- const pool = await centrifuge.pool('<pool-id>')
149
- const balanceSheetReport = await pool.reports.balanceSheet()
150
- ```
158
+ - token price
151
159
 
152
- ### Report Filtering
160
+ Filtering is supported:
153
161
 
154
- Reports can be filtered using the `ReportFilter` type.
162
+ ```typescript
163
+ type ReportFilter = {
164
+ from?: string // e.g. '2024-01-01'
165
+ to?: string // e.g. '2024-01-31'
166
+ groupBy?: 'day' | 'month' | 'quarter' | 'year'
167
+ }
155
168
 
156
- ```ts
157
- type GroupBy = 'day' | 'month' | 'quarter' | 'year'
169
+ const fromNum = toUTCEpoch(filters.from, unit)
170
+ const toNum = toUTCEpoch(filters.to, unit)
158
171
 
159
- const balanceSheetReport = await pool.reports.balanceSheet({
160
- from: '2024-01-01',
161
- to: '2024-01-31',
162
- groupBy: 'month',
172
+ const report = await pool.reports.sharePrices({
173
+ from: fromNum,
174
+ to: toNum,
175
+ groupBy: 'day',
163
176
  })
164
177
  ```
165
178
 
166
- ## Developer Docs
179
+ ### Developer Guide
167
180
 
168
- ### Dev server
181
+ #### Development Mode
169
182
 
170
183
  ```bash
171
184
  yarn dev
172
185
  ```
173
186
 
174
- ### Build
187
+ #### Building
175
188
 
176
189
  ```bash
177
190
  yarn build
178
191
  ```
179
192
 
180
- ### Test
193
+ #### Testing
181
194
 
182
195
  ```bash
183
- yarn test
184
- yarn test:single <path-to-file>
185
- yarn test:simple:single <path-to-file> # without setup file, faster and without tenderly setup
196
+ yarn test # full test suite
197
+ yarn test:single <file> # test specific file
198
+ yarn test:simple:single <file>
199
+ # (runs faster excluding setup files)
186
200
  ```
187
201
 
188
- ## User Docs
202
+ ### Contributing
203
+
204
+ #### Docs
205
+
206
+ Detailed user & developer documentation is maintained in the [documentation repository](https://github.com/centrifuge/documentation/tree/main/docs/developer/centrifuge-sdk).
207
+
208
+ #### PR Naming Convention & Versioning
189
209
 
190
- User docs are written and maintained in the [sdk-docs](https://github.com/centrifuge/sdk-docs) repository.
210
+ PR titles & commits should follow Conventional Commits style.
191
211
 
192
- ### PR Naming Convention
212
+ Use semantic versioning: tags/releases should be one of major, minor, patch.
193
213
 
194
- PR naming should follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
214
+ If no release is needed, label as no-release.
195
215
 
196
- ### Semantic Versioning
216
+ ### License
197
217
 
198
- PRs should be marked with the appropriate type: `major`, `minor`, `patch`, `no-release`.
218
+ This project is licensed under LGPL-3.0.
219
+ See the [LICENSE](./LICENSE) file for details.