@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 +143 -122
- package/dist/config/chains.d.ts +135 -115
- package/dist/config/chains.d.ts.map +1 -1
- package/dist/entities/Entity.js.map +1 -1
- package/dist/entities/OnOffRampManager.test.js +1 -1
- package/dist/entities/PoolNetwork.js +1 -1
- package/dist/entities/PoolNetwork.js.map +1 -1
- package/dist/entities/PoolNetwork.test.js +1 -1
- package/dist/entities/PoolNetwork.test.js.map +1 -1
- package/dist/entities/ShareClass.test.js +9 -9
- package/dist/entities/ShareClass.test.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,198 +1,219 @@
|
|
|
1
1
|
# Centrifuge SDK [](https://codecov.io/gh/centrifuge/sdk) [](https://github.com/centrifuge/sdk/actions/workflows/build-test-report.yml) [](https://github.com/centrifuge/sdk/releases/latest)
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
44
|
+
npm install @centrifuge/sdk
|
|
9
45
|
```
|
|
10
46
|
|
|
11
|
-
##
|
|
47
|
+
## Getting Started
|
|
12
48
|
|
|
13
|
-
|
|
49
|
+
### Initialization & Configuration
|
|
14
50
|
|
|
15
|
-
```
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
72
|
+
// Or subscribe
|
|
50
73
|
const subscription = centrifuge.pools().subscribe(
|
|
51
|
-
(
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
## Transactions
|
|
82
|
+
### Transactions
|
|
60
83
|
|
|
61
|
-
|
|
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
|
-
```
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
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('
|
|
101
|
+
() => console.log('Done')
|
|
87
102
|
)
|
|
88
103
|
```
|
|
89
104
|
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
109
|
+
```typescript
|
|
97
110
|
const pool = await centrifuge.pool('1')
|
|
98
|
-
const vault = await pool.vault(1, '
|
|
111
|
+
const vault = await pool.vault(1, '0xShareClassAddress', '0xInvestmentCurrencyAddress')
|
|
99
112
|
```
|
|
100
113
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
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
|
-
|
|
139
|
+
To invest:
|
|
125
140
|
|
|
126
|
-
```
|
|
141
|
+
```typescript
|
|
127
142
|
const result = await vault.increaseInvestOrder(1000)
|
|
128
143
|
console.log(result.hash)
|
|
129
144
|
```
|
|
130
145
|
|
|
131
|
-
Once
|
|
146
|
+
Once processed, any claimable shares or currencies can be claimed:
|
|
132
147
|
|
|
133
|
-
```
|
|
134
|
-
const
|
|
148
|
+
```typescript
|
|
149
|
+
const claimResult = await vault.claim()
|
|
135
150
|
```
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
### Reports
|
|
138
153
|
|
|
139
|
-
|
|
154
|
+
You can generate financial reports for a pool based on on-chain + API data.
|
|
140
155
|
|
|
141
|
-
Available
|
|
156
|
+
Available report types:
|
|
142
157
|
|
|
143
|
-
-
|
|
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
|
-
|
|
160
|
+
Filtering is supported:
|
|
153
161
|
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
|
|
169
|
+
const fromNum = toUTCEpoch(filters.from, unit)
|
|
170
|
+
const toNum = toUTCEpoch(filters.to, unit)
|
|
158
171
|
|
|
159
|
-
const
|
|
160
|
-
from:
|
|
161
|
-
to:
|
|
162
|
-
groupBy: '
|
|
172
|
+
const report = await pool.reports.sharePrices({
|
|
173
|
+
from: fromNum,
|
|
174
|
+
to: toNum,
|
|
175
|
+
groupBy: 'day',
|
|
163
176
|
})
|
|
164
177
|
```
|
|
165
178
|
|
|
166
|
-
|
|
179
|
+
### Developer Guide
|
|
167
180
|
|
|
168
|
-
|
|
181
|
+
#### Development Mode
|
|
169
182
|
|
|
170
183
|
```bash
|
|
171
184
|
yarn dev
|
|
172
185
|
```
|
|
173
186
|
|
|
174
|
-
|
|
187
|
+
#### Building
|
|
175
188
|
|
|
176
189
|
```bash
|
|
177
190
|
yarn build
|
|
178
191
|
```
|
|
179
192
|
|
|
180
|
-
|
|
193
|
+
#### Testing
|
|
181
194
|
|
|
182
195
|
```bash
|
|
183
|
-
yarn test
|
|
184
|
-
yarn test:single <
|
|
185
|
-
yarn test:simple:single <
|
|
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
|
-
|
|
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
|
-
|
|
210
|
+
PR titles & commits should follow Conventional Commits style.
|
|
191
211
|
|
|
192
|
-
|
|
212
|
+
Use semantic versioning: tags/releases should be one of major, minor, patch.
|
|
193
213
|
|
|
194
|
-
|
|
214
|
+
If no release is needed, label as no-release.
|
|
195
215
|
|
|
196
|
-
###
|
|
216
|
+
### License
|
|
197
217
|
|
|
198
|
-
|
|
218
|
+
This project is licensed under LGPL-3.0.
|
|
219
|
+
See the [LICENSE](./LICENSE) file for details.
|