离心式 SDK

一个完全输入的 JavaScript 客户端可以与该客户端交互 离心器 生态系统。 用它来管理集合,投资,赎回,财务报告等等.
目录
特征
- 已键入 JavaScript/ TypeScript 客户端
- 支持主网和测试网环境
- 完整查询接口( 只读) + 订阅支持
- 交易支持(等待或可观察更新)
- 处理股票类、金库和ERC-7540象征性金库
- 报表:资产负债表、损益、现金流量
安装
npm install @centrifuge/sdk
开始
初始化配置( C)
import Centrifuge from '@centrifuge/sdk'
const centrifuge = new Centrifuge({
environment: 'mainnet' | 'testnet', // optional, defaults to 'mainnet'
rpcUrls?: { [chainId: number]: string }, // optional RPC endpoints
indexerUrl?: string, // optional indexer API URL
ipfsUrl?: string // optional IPFS gateway, default: https://centrifuge-files.mypinata.cloud
})
查询
查询返回可观测值(rxjs),可以是:
- 等待(一个值),或
- 已订阅( 当链上数据变化时接收更新)
const pools = await centrifuge.pools()
// Or subscribe
const subscription = centrifuge.pools().subscribe(
(pools) => console.log(pools),
(error) => console.error(error)
)
// Later, to stop updates:
subscription.unsubscribe()
交易
- 在调用交易方法之前,在离心机实例上设置一个签名符.
- 签名者可以是:
- EIP-1193兼容供应商
- Viem 本地账户
- 交易和查询一样,支持等待完成或签署状态更新.
centrifuge.setSigner(signer)
const poolId = PoolId.from(1, 1)
const pool = await centrifuge.pool(poolId)
const tx = await pool.updatePoolManagers([
{
address: '0xAddress',
canManage: true,
},
])
console.log(tx.hash)
// or, subscribe to transaction lifecycle:
const sub = pool.pool
.updatePoolManagers([
{
address: '0xAddress',
canManage: true,
},
])
.subscribe(
(status) => console.log(status),
(error) => console.error(error),
() => console.log('Done')
)
投资
SDK 支持 ERC-7540 (中文(简体) ) 象征性的金库。 每股分级,连锁,和货币,都会产生空档.
const pool = await centrifuge.pool(poolId)
const scId = ShareClassId.from(poolId, 1)
const assetId = AssetId.from(centId, 1)
// Get a vault
const vault = await pool.vault(11155111, scId, assetId)
默认类型
根据池的配置, 跳槽行为会有所不同 :
-
同步存款金库 这些金库采用ERC-4626和ERC-7540两种混合模型. 存款使用 ERC-4626 行为立即执行,允许用户立即接收股票. 然而,救赎通过ERC-7540同步处理,使用Hub来排队和管理取还请求.
-
同步金库 同步金库完全基于请求,并遵循ERC-7540标准. 它们允许通过同步工作流程处理存款和赎回行动,利用离心枢纽管理请求.
您可以查询个人投资者的状态:
const inv = await vault.investment('0xInvestorAddress')
// Example returned fields include:
// isAllowedToInvest
// investmentCurrency, investmentCurrencyBalance, investmentCurrencyAllowance
// shareCurrency, shareBalance
// claimableInvestShares, claimableInvestCurrencyEquivalent
// claimableRedeemCurrency, claimableRedeemSharesEquivalent
// pendingInvestCurrency, pendingRedeemShares
// hasPendingCancelInvestRequest, hasPendingCancelRedeemRequest
投资:
const { investmentCurrency } = await vault.details()
const amount = Balance.fromFloat(1000, investmentCurrency.decimals)
const tx = await vault.increaseInvestOrder(amount)
console.log(result.hash)
任何可索赔的股票或货币一经处理,即可索赔:
const claimResult = await vault.claim()
报告
您可以基于链式+API数据为集合生成财务报告.
可用报告类型 :
- 价 价 额
支持过滤 :
type ReportFilter = {
from?: string // e.g. '2024-01-01'
to?: string // e.g. '2024-01-31'
groupBy?: 'day' | 'month' | 'quarter' | 'year'
}
const fromNum = toUTCEpoch(filters.from, unit)
const toNum = toUTCEpoch(filters.to, unit)
const report = await pool.reports.sharePrices({
from: fromNum,
to: toNum,
groupBy: 'day',
})
开发者指南
发展模式
pnpm dev
大楼
pnpm build
测试
pnpm test # full test suite
pnpm test:single <file> # test specific file
pnpm test:simple:single <file>
# (runs faster excluding setup files)
调试
该项目为在本地运行Indexer(api-v3)和Anvil叉(Foundry)提供了完全多克化的环境. 为准备您的测试环境进行链上调试, 首先设置调试脚本 :
./src/debugIssues.mjs
// @ts-check
import { catchError, combineLatest, lastValueFrom, map, of, switchMap, tap } from 'rxjs'
import { parseAbiItem } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { AssetId, Balance, Centrifuge, PoolId, Price, ShareClass, ShareClassId } from './dist/index.js'
const abiItem = parseAbiItem('function balanceOf(address owner) view returns (uint256)')
const chainId = 1
const cent = new Centrifuge({
environment: 'mainnet',
pinJson: async () => 'test',
rpcUrls: {
1: 'http://127.0.0.1:8545',
},
inexerPollingInterval: 2000,
indexerUrl: 'http://localhost:8000',
})
const account = privateKeyToAccount('0xPrivateKey')
cent.setSigner(account)
async function main() {
const client = cent.getClient(centrifugeId)
const pool = await cent.pool(new PoolId('PoolId'))
const scId = new ShareClassId('0x00010000000000010000000000000001')
const shareClass = new ShareClass(cent, pool, scId)
const assetId = new AssetId('AssetId')
const result = await shareClass.approveDepositsAndIssueShares([
{
assetId,
approveAssetAmount: Balance.fromFloat(10, 6),
issuePricePerShare: Price.fromFloat(1.0),
},
])
}
main()
* 警告 在运行调试脚本之前, 请评论您想要测试的交易, 如果您不想执行 . 记住在本地运行此脚本将执行与测试网或主网相同的交易逻辑. * :
然后,建造和启动 Docker 容器:
docker compose up -d
完成后,将环境拆卸并删除相关量:
docker compose down -v
捐款
文档
页:1 文件存储库。 。 。 .
PR 命名公约和版本
公关标题和承诺应当遵循常规承诺风格.
使用语义化的版本:标记/放出应该是主要,次要,补丁之一.
如果不需要释放,则标为不释放.
许可证
该项目根据LGPL-3.0获得许可. 见 自由主义 详细文件.