Skip to content

Commit a7a0003

Browse files
onnovisserhieronx
andauthored
docs: Expand readme for investments (#33)
* vault docs * Update README.md Co-authored-by: Jeroen <1748621+hieronx@users.noreply.github.com> * Update README.md Co-authored-by: Jeroen <1748621+hieronx@users.noreply.github.com> * fix test --------- Co-authored-by: Jeroen <1748621+hieronx@users.noreply.github.com>
1 parent e6a0cfd commit a7a0003

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,53 @@ const subscription = pool.closeEpoch().subscribe(
8484
)
8585
```
8686

87+
## Investments
88+
89+
Investments for a pool are done via [ERC-7540 Tokenized Vaults](https://eips.ethereum.org/EIPS/eip-7540). Vaults can be deployed for a tranche on any supported network, for any supported currency
90+
91+
Retrieve a vault by querying it from the pool:
92+
93+
```js
94+
const pool = await centrifuge.pool('1')
95+
const vault = await pool.vault(1, '0xabc...', '0xdef...') // Chain ID, tranche ID, investment currency address
96+
```
97+
98+
Query the state of an investment on the vault for an investor:
99+
100+
```js
101+
const investment = await vault.investment('0x123...')
102+
// Will return an object containing:
103+
// isAllowedToInvest - Whether an investor is allowed to invest in the tranche
104+
// investmentCurrency - The ERC20 token that is used to invest in the vault
105+
// investmentCurrencyBalance - The balance of the investor of the investment currency
106+
// investmentCurrencyAllowance - The allowance of the vault
107+
// shareCurrency - The ERC20 token that is issued to investors to account for their share in the tranche
108+
// shareBalance - The number of shares the investor has in the tranche
109+
// claimableInvestShares - The number of shares an investor can claim after their invest order has been processed (partially or not)
110+
// claimableInvestCurrencyEquivalent - The equivalent value of the claimable shares denominated in the invest currency
111+
// claimableRedeemCurrency - The amout of money an investor can claim after their redeem order has been processed (partially or not)
112+
// claimableRedeemSharesEquivalent - The amount of shares that have been redeemed for which the investor can claim money
113+
// pendingInvestCurrency - The amount of money that the investor wants to invest in the tranche that has not been processed yet
114+
// pendingRedeemShares - The amount of shares that the investor wants to redeem from the tranche that has not been processed yet
115+
// claimableCancelInvestCurrency - The amount of money an investor can claim after an invest order cancellation has been processed
116+
// claimableCancelRedeemShares - The amount of shares an investor can claim after a redeem order cancellation has been processed
117+
// hasPendingCancelInvestRequest - Whether the investor has an invest order that is in the process of being cancelled
118+
// hasPendingCancelRedeemRequest - Whether the investor has a redeem order that is in the process of being cancelled
119+
```
120+
121+
Invest in a vault:
122+
123+
```js
124+
const result = await vault.increaseInvestOrder(1000)
125+
console.log(result.hash)
126+
```
127+
128+
Once an order has been processed, `claimableInvestShares` will positive and shares can be claimed with:
129+
130+
```js
131+
const result = await vault.claim()
132+
```
133+
87134
## Reports
88135

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

src/Pool.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Pool } from './Pool.js'
33
import { context } from './tests/setup.js'
44

55
const poolId = '2779829532'
6+
const trancheId = '0xac6bffc5fd68f7772ceddec7b0a316ca'
7+
const asset = '0x8503b4452Bf6238cC76CdbEE223b46d7196b1c93'
68

79
describe('Pool', () => {
810
let pool: Pool
@@ -17,4 +19,9 @@ describe('Pool', () => {
1719
expect(networks[0]!.chainId).to.equal(11155111)
1820
expect(networks[1]!.chainId).to.equal(84532)
1921
})
22+
23+
it('can query a vault', async () => {
24+
const vault = await pool.vault(11155111, trancheId, asset)
25+
expect(vault).to.not.be.undefined
26+
})
2027
})

src/PoolNetwork.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from 'chai'
2-
import sinon from 'sinon'
32
import { Pool } from './Pool.js'
43
import { PoolNetwork } from './PoolNetwork.js'
54
import { context } from './tests/setup.js'
@@ -16,10 +15,6 @@ describe('PoolNetwork', () => {
1615
poolNetwork = new PoolNetwork(centrifuge, pool, 11155111)
1716
})
1817

19-
afterEach(() => {
20-
sinon.restore()
21-
})
22-
2318
it('should get whether a pool is deployed to a network', async () => {
2419
const isActive = await poolNetwork.isActive()
2520
expect(isActive).to.equal(true)
@@ -31,12 +26,9 @@ describe('PoolNetwork', () => {
3126
})
3227

3328
it('get vaults for a tranche', async () => {
34-
const fetchSpy = sinon.spy(globalThis, 'fetch')
3529
const vaults = await poolNetwork.vaults(trancheId)
3630
expect(vaults).to.have.length(1)
3731
expect(vaults[0]!.address.toLowerCase()).to.equal(vaultAddress)
38-
// Calls should get batched
39-
expect(fetchSpy.getCalls().length).to.equal(1)
4032
})
4133

4234
it('should deploy a tranche', async () => {

src/PoolNetwork.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,11 @@ export class PoolNetwork extends Entity {
211211
* @param asset - The investment currency address
212212
*/
213213
vault(trancheId: string, asset: string) {
214+
const assetAddress = asset.toLowerCase()
214215
return this._query(null, () =>
215216
this.vaults(trancheId).pipe(
216217
map((vaults) => {
217-
const vault = vaults.find((v) => v._asset === asset)
218+
const vault = vaults.find((v) => v._asset === assetAddress)
218219
if (!vault) throw new Error('Vault not found')
219220
return vault
220221
})

0 commit comments

Comments
 (0)