Skip to content

Conversation

@hieronx
Copy link
Contributor

@hieronx hieronx commented Nov 18, 2025

This PR standardizes the SDK to use centrifugeId (the protocol's internal network ID) instead of chainId (EVM chain ID) throughout the public API, aligning with the Centrifuge protocol architecture, and preparing for support of non-EVM chains.

  1. New CentrifugeId type - Type alias for network identification

  2. Core API updates:

    • getClient(centrifugeId) - Now accepts centrifugeId, looks up chainId internally
    • _transact(callback, centrifugeId) - Transaction system uses centrifugeId
    • createPool(), currency(), balance(), valuations(), restrictionHooks() - All accept centrifugeId
  3. Entity improvements:

    • Added centrifugeId getters to Pool and PoolNetwork entities
    • Updated all entity methods: Pool.network(), Pool.vault(), ShareClass.member(), ShareClass.freezeMember(), Investor.investment(), etc.
  4. ID utilities:

    • PoolId, ShareClassId, AssetId - Getters now return CentrifugeId type
    • New _chainToId() helper for reverse lookups

@hieronx hieronx added the minor label Nov 18, 2025
@github-actions
Copy link

Auto-bumped version for release, this cannot be the last commit as bots can't trigger the workflows to pass the PR checks

@hieronx hieronx changed the title refactor: use centrifugeId as input param primarily refactor: use centrifugeId instead of chainId in most places Nov 18, 2025

#clients = new Map<number, Client>()
getClient(chainId: number): Client {
getClient(centrifugeId: CentrifugeId): Client {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be cleaner to turn this into a Query and use it with combineLatest wherever it's needed

return this._query(['balance', currency, owner, chainId], () => {
return this.currency(currency, chainId).pipe(
return this._query(['balance', currency, owner, centrifugeId], () => {
return this.currency(currency, centrifugeId).pipe(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return combineLatest([
  this.currency(currency, centrifugeId),
  this._idToChain(centrifugeId)
]).pipe(...)

makeThenable($tx, true)
Object.assign($tx, {
chainId,
chainId: resolvedChainId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be changed to centrifugeId, as it needs to be known before transact runs. it's only used in _experimental_batch

return this._query(['balanceSheet', chainId], () =>
balanceSheet(centrifugeId: CentrifugeId) {
return this._query(['balanceSheet', centrifugeId], () =>
this.pool.activeNetworks().pipe(
Copy link
Collaborator

@onnovisser onnovisser Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combineLatest([
  this.pool.activeNetworks(),
  this._root._idToChain(centrifugeId)
]).pipe(...)

switchMap((networks) =>
this._root._idToChain(centrifugeId).pipe(
map((chainId) => {
const network = networks.find((n) => n.chainId === chainId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this._root._idToChain(centrifugeId), can check n.centrifugeId === centrifugeId

this._restrictionManager(network.chainId).pipe(catchError(() => of(null))),
of(network),
])
this._root.id(network.chainId).pipe(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

return this._query(['investmentsByVault', centrifugeId], () =>
this._root._idToChain(centrifugeId).pipe(
switchMap((chainId) =>
combineLatest([this._investorOrders(), this.vaults(chainId), this.pendingAmounts()]).pipe(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like vaults() is still using chainId

public pool: Pool,
public chainId: number
) {
super(_root, ['poolnetwork', pool.id.toString(), chainId])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably take centrifugeId as argument

}

get centrifugeId(): CentrifugeId {
return this.pool.centrifugeId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the centrifugeId of the PoolNetwork (e.g. Spoke), not the Hub

@github-actions
Copy link

Auto-bumped version for release, this cannot be the last commit as bots can't trigger the workflows to pass the PR checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants