@centrifuge/sdk 0.55.2 → 1.0.0

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.
Files changed (183) hide show
  1. package/README.md +2 -2
  2. package/dist/Centrifuge.d.ts +6910 -22
  3. package/dist/Centrifuge.d.ts.map +1 -1
  4. package/dist/Centrifuge.js +139 -160
  5. package/dist/Centrifuge.js.map +1 -1
  6. package/dist/Centrifuge.test.js +24 -26
  7. package/dist/Centrifuge.test.js.map +1 -1
  8. package/dist/abi/Accounting.abi.d.ts +1 -1
  9. package/dist/abi/Accounting.abi.d.ts.map +1 -1
  10. package/dist/abi/Accounting.abi.js +23 -24
  11. package/dist/abi/Accounting.abi.js.map +1 -1
  12. package/dist/abi/AsyncRequestManager.abi.d.ts +1 -1
  13. package/dist/abi/AsyncRequestManager.abi.js +18 -18
  14. package/dist/abi/AsyncRequestManager.abi.js.map +1 -1
  15. package/dist/abi/AsyncVault.abi.d.ts +1 -1
  16. package/dist/abi/AsyncVault.abi.d.ts.map +1 -1
  17. package/dist/abi/AsyncVault.abi.js +1 -2
  18. package/dist/abi/AsyncVault.abi.js.map +1 -1
  19. package/dist/abi/BalanceSheet.abi.d.ts +1 -1
  20. package/dist/abi/BalanceSheet.abi.d.ts.map +1 -1
  21. package/dist/abi/BalanceSheet.abi.js +21 -20
  22. package/dist/abi/BalanceSheet.abi.js.map +1 -1
  23. package/dist/abi/BatchRequestManager.abi.d.ts +3 -0
  24. package/dist/abi/BatchRequestManager.abi.d.ts.map +1 -0
  25. package/dist/abi/BatchRequestManager.abi.js +74 -0
  26. package/dist/abi/BatchRequestManager.abi.js.map +1 -0
  27. package/dist/abi/GasService.abi.d.ts +1 -1
  28. package/dist/abi/GasService.abi.d.ts.map +1 -1
  29. package/dist/abi/GasService.abi.js +10 -6
  30. package/dist/abi/GasService.abi.js.map +1 -1
  31. package/dist/abi/Gateway.abi.d.ts +1 -1
  32. package/dist/abi/Gateway.abi.d.ts.map +1 -1
  33. package/dist/abi/Gateway.abi.js +33 -27
  34. package/dist/abi/Gateway.abi.js.map +1 -1
  35. package/dist/abi/Holdings.abi.d.ts +1 -1
  36. package/dist/abi/Holdings.abi.d.ts.map +1 -1
  37. package/dist/abi/Holdings.abi.js +10 -5
  38. package/dist/abi/Holdings.abi.js.map +1 -1
  39. package/dist/abi/Hub.abi.d.ts +1 -1
  40. package/dist/abi/Hub.abi.d.ts.map +1 -1
  41. package/dist/abi/Hub.abi.js +40 -38
  42. package/dist/abi/Hub.abi.js.map +1 -1
  43. package/dist/abi/HubRegistry.abi.d.ts +1 -1
  44. package/dist/abi/HubRegistry.abi.d.ts.map +1 -1
  45. package/dist/abi/HubRegistry.abi.js +22 -19
  46. package/dist/abi/HubRegistry.abi.js.map +1 -1
  47. package/dist/abi/MerkleProofManager.abi.d.ts.map +1 -1
  48. package/dist/abi/MerkleProofManager.abi.js +2 -4
  49. package/dist/abi/MerkleProofManager.abi.js.map +1 -1
  50. package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -1
  51. package/dist/abi/MessageDispatcher.abi.js +44 -38
  52. package/dist/abi/MessageDispatcher.abi.js.map +1 -1
  53. package/dist/abi/MultiAdapter.abi.d.ts +1 -1
  54. package/dist/abi/MultiAdapter.abi.d.ts.map +1 -1
  55. package/dist/abi/MultiAdapter.abi.js +14 -28
  56. package/dist/abi/MultiAdapter.abi.js.map +1 -1
  57. package/dist/abi/NAVManager.abi.d.ts +3 -0
  58. package/dist/abi/NAVManager.abi.d.ts.map +1 -0
  59. package/dist/abi/NAVManager.abi.js +41 -0
  60. package/dist/abi/NAVManager.abi.js.map +1 -0
  61. package/dist/abi/OnOffRampManager.abi.d.ts +1 -1
  62. package/dist/abi/OnOffRampManager.abi.d.ts.map +1 -1
  63. package/dist/abi/OnOffRampManager.abi.js +18 -20
  64. package/dist/abi/OnOffRampManager.abi.js.map +1 -1
  65. package/dist/abi/PoolEscrow.abi.d.ts +1 -1
  66. package/dist/abi/PoolEscrow.abi.d.ts.map +1 -1
  67. package/dist/abi/PoolEscrow.abi.js +1 -2
  68. package/dist/abi/PoolEscrow.abi.js.map +1 -1
  69. package/dist/abi/QueueManager.abi.d.ts +3 -0
  70. package/dist/abi/QueueManager.abi.d.ts.map +1 -0
  71. package/dist/abi/QueueManager.abi.js +21 -0
  72. package/dist/abi/QueueManager.abi.js.map +1 -0
  73. package/dist/abi/ShareClassManager.abi.d.ts +1 -1
  74. package/dist/abi/ShareClassManager.abi.d.ts.map +1 -1
  75. package/dist/abi/ShareClassManager.abi.js +11 -62
  76. package/dist/abi/ShareClassManager.abi.js.map +1 -1
  77. package/dist/abi/Spoke.abi.d.ts +1 -1
  78. package/dist/abi/Spoke.abi.d.ts.map +1 -1
  79. package/dist/abi/Spoke.abi.js +25 -21
  80. package/dist/abi/Spoke.abi.js.map +1 -1
  81. package/dist/abi/SyncManager.abi.d.ts +3 -0
  82. package/dist/abi/SyncManager.abi.d.ts.map +1 -0
  83. package/dist/abi/{SyncRequestManager.abi.js → SyncManager.abi.js} +10 -26
  84. package/dist/abi/SyncManager.abi.js.map +1 -0
  85. package/dist/abi/Valuation.abi.d.ts +1 -1
  86. package/dist/abi/Valuation.abi.d.ts.map +1 -1
  87. package/dist/abi/Valuation.abi.js +4 -1
  88. package/dist/abi/Valuation.abi.js.map +1 -1
  89. package/dist/abi/VaultRegistry.abi.d.ts +3 -0
  90. package/dist/abi/VaultRegistry.abi.d.ts.map +1 -0
  91. package/dist/abi/VaultRegistry.abi.js +35 -0
  92. package/dist/abi/VaultRegistry.abi.js.map +1 -0
  93. package/dist/abi/VaultRouter.abi.d.ts +1 -1
  94. package/dist/abi/VaultRouter.abi.d.ts.map +1 -1
  95. package/dist/abi/VaultRouter.abi.js +3 -0
  96. package/dist/abi/VaultRouter.abi.js.map +1 -1
  97. package/dist/abi/index.d.ts +1805 -1802
  98. package/dist/abi/index.d.ts.map +1 -1
  99. package/dist/abi/index.js +9 -5
  100. package/dist/abi/index.js.map +1 -1
  101. package/dist/entities/BalanceSheet.d.ts +8 -8
  102. package/dist/entities/BalanceSheet.d.ts.map +1 -1
  103. package/dist/entities/BalanceSheet.js +23 -21
  104. package/dist/entities/BalanceSheet.js.map +1 -1
  105. package/dist/entities/BalanceSheet.test.js +9 -4
  106. package/dist/entities/BalanceSheet.test.js.map +1 -1
  107. package/dist/entities/Investor.d.ts +11 -9
  108. package/dist/entities/Investor.d.ts.map +1 -1
  109. package/dist/entities/Investor.js +28 -35
  110. package/dist/entities/Investor.js.map +1 -1
  111. package/dist/entities/Investor.test.js +1 -1
  112. package/dist/entities/Investor.test.js.map +1 -1
  113. package/dist/entities/MerkleProofManager.d.ts +1 -2
  114. package/dist/entities/MerkleProofManager.d.ts.map +1 -1
  115. package/dist/entities/MerkleProofManager.js +24 -25
  116. package/dist/entities/MerkleProofManager.js.map +1 -1
  117. package/dist/entities/MerkleProofManager.test.js +10 -10
  118. package/dist/entities/MerkleProofManager.test.js.map +1 -1
  119. package/dist/entities/OnOffRampManager.d.ts.map +1 -1
  120. package/dist/entities/OnOffRampManager.js +35 -39
  121. package/dist/entities/OnOffRampManager.js.map +1 -1
  122. package/dist/entities/OnOffRampManager.test.js +14 -10
  123. package/dist/entities/OnOffRampManager.test.js.map +1 -1
  124. package/dist/entities/Pool.d.ts +33 -11
  125. package/dist/entities/Pool.d.ts.map +1 -1
  126. package/dist/entities/Pool.js +132 -65
  127. package/dist/entities/Pool.js.map +1 -1
  128. package/dist/entities/Pool.test.js +35 -12
  129. package/dist/entities/Pool.test.js.map +1 -1
  130. package/dist/entities/PoolNetwork.d.ts +26 -5
  131. package/dist/entities/PoolNetwork.d.ts.map +1 -1
  132. package/dist/entities/PoolNetwork.js +154 -115
  133. package/dist/entities/PoolNetwork.js.map +1 -1
  134. package/dist/entities/PoolNetwork.test.js +40 -34
  135. package/dist/entities/PoolNetwork.test.js.map +1 -1
  136. package/dist/entities/Reports/PoolSharePricesReport.d.ts.map +1 -1
  137. package/dist/entities/Reports/PoolSharePricesReport.js +3 -2
  138. package/dist/entities/Reports/PoolSharePricesReport.js.map +1 -1
  139. package/dist/entities/Reports/PoolSharePricesReport.test.js +1 -1
  140. package/dist/entities/Reports/PoolSharePricesReport.test.js.map +1 -1
  141. package/dist/entities/ShareClass.d.ts +59 -49
  142. package/dist/entities/ShareClass.d.ts.map +1 -1
  143. package/dist/entities/ShareClass.js +380 -300
  144. package/dist/entities/ShareClass.js.map +1 -1
  145. package/dist/entities/ShareClass.test.js +36 -32
  146. package/dist/entities/ShareClass.test.js.map +1 -1
  147. package/dist/entities/Vault.d.ts +1 -1
  148. package/dist/entities/Vault.d.ts.map +1 -1
  149. package/dist/entities/Vault.js +68 -55
  150. package/dist/entities/Vault.js.map +1 -1
  151. package/dist/entities/Vault.test.js +10 -10
  152. package/dist/entities/Vault.test.js.map +1 -1
  153. package/dist/tests/mocks/mockPoolMetadata.js +2 -2
  154. package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
  155. package/dist/types/index.d.ts +17 -2
  156. package/dist/types/index.d.ts.map +1 -1
  157. package/dist/types/transaction.d.ts +24 -32
  158. package/dist/types/transaction.d.ts.map +1 -1
  159. package/dist/types/transaction.js +26 -32
  160. package/dist/types/transaction.js.map +1 -1
  161. package/dist/utils/index.d.ts +7 -0
  162. package/dist/utils/index.d.ts.map +1 -1
  163. package/dist/utils/index.js +16 -0
  164. package/dist/utils/index.js.map +1 -1
  165. package/dist/utils/permit.d.ts +1 -1
  166. package/dist/utils/permit.d.ts.map +1 -1
  167. package/dist/utils/permit.js +11 -7
  168. package/dist/utils/permit.js.map +1 -1
  169. package/dist/utils/rx.d.ts +2 -1
  170. package/dist/utils/rx.d.ts.map +1 -1
  171. package/dist/utils/rx.js +2 -2
  172. package/dist/utils/rx.js.map +1 -1
  173. package/dist/utils/transaction.d.ts +2 -1
  174. package/dist/utils/transaction.d.ts.map +1 -1
  175. package/dist/utils/transaction.js +4 -3
  176. package/dist/utils/transaction.js.map +1 -1
  177. package/dist/utils/types.d.ts +10 -5
  178. package/dist/utils/types.d.ts.map +1 -1
  179. package/dist/utils/types.js.map +1 -1
  180. package/package.json +1 -1
  181. package/dist/abi/SyncRequestManager.abi.d.ts +0 -3
  182. package/dist/abi/SyncRequestManager.abi.d.ts.map +0 -1
  183. package/dist/abi/SyncRequestManager.abi.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { combineLatest, defer, filter, first, identity, isObservable, map, mergeMap, of, switchMap, timer, Observable, shareReplay, } from 'rxjs';
1
+ import { combineLatest, defer, filter, first, identity, isObservable, map, mergeMap, Observable, of, shareReplay, switchMap, timer, } from 'rxjs';
2
2
  import { fromFetch } from 'rxjs/fetch';
3
3
  import { createPublicClient, createWalletClient, custom, encodeFunctionData, fallback, getContract, http, keccak256, parseAbi, toHex, } from 'viem';
4
4
  import { ABI } from './abi/index.js';
@@ -8,7 +8,7 @@ import { Investor } from './entities/Investor.js';
8
8
  import { Pool } from './entities/Pool.js';
9
9
  import { emptyMessage, MessageType, } from './types/transaction.js';
10
10
  import { Balance } from './utils/BigInt.js';
11
- import { randomUint } from './utils/index.js';
11
+ import { generateShareClassSalt, randomUint } from './utils/index.js';
12
12
  import { createPinning, getUrlFromHash } from './utils/ipfs.js';
13
13
  import { hashKey } from './utils/query.js';
14
14
  import { makeThenable, repeatOnEvents, shareReplayWithDelayedReset } from './utils/rx.js';
@@ -18,12 +18,12 @@ const PINNING_API_DEMO = 'https://europe-central2-peak-vista-185616.cloudfunctio
18
18
  const envConfig = {
19
19
  mainnet: {
20
20
  indexerUrl: 'https://api.centrifuge.io',
21
- ipfsUrl: 'https://centrifuge.mypinata.cloud',
21
+ ipfsUrl: 'https://ipfs.centrifuge.io',
22
22
  ...createPinning(PINNING_API_DEMO),
23
23
  },
24
24
  testnet: {
25
25
  indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
26
- ipfsUrl: 'https://centrifuge.mypinata.cloud',
26
+ ipfsUrl: 'https://ipfs.centrifuge.io',
27
27
  ...createPinning(PINNING_API_DEMO),
28
28
  },
29
29
  };
@@ -37,17 +37,22 @@ export class Centrifuge {
37
37
  return this.#config;
38
38
  }
39
39
  #clients = new Map();
40
- getClient(chainId) {
41
- const client = this.#clients.get(chainId);
42
- if (!client)
43
- throw new Error(`No client found for chain ID "${chainId}"`);
44
- return client;
40
+ getClient(centrifugeId) {
41
+ return this._query(['client', centrifugeId], () => this._idToChain(centrifugeId).pipe(map((chainId) => {
42
+ const client = this.#clients.get(chainId);
43
+ if (!client)
44
+ throw new Error(`No client found for chain ID "${chainId}"`);
45
+ return client;
46
+ })));
45
47
  }
46
48
  get chains() {
47
49
  return [...this.#clients.keys()];
48
50
  }
49
- getChainConfig(chainId) {
50
- return this.getClient(chainId).chain;
51
+ get chainConfigs() {
52
+ return [...this.#clients.values()].map((client) => client.chain);
53
+ }
54
+ getChainConfig(centrifugeId) {
55
+ return this._query(['chainConfig', centrifugeId], () => this.getClient(centrifugeId).pipe(map((client) => client.chain)));
51
56
  }
52
57
  #signer = null;
53
58
  setSigner(signer) {
@@ -95,11 +100,11 @@ export class Centrifuge {
95
100
  * @param chainId - The chain ID to create the pool on
96
101
  * @param counter - The pool counter, used to create a unique pool ID (uint48)
97
102
  */
98
- createPool(metadataInput, currencyCode = 840, chainId, counter) {
103
+ createPool(metadataInput, currencyCode = 840, centrifugeId, counter) {
99
104
  const self = this;
100
105
  return this._transact(async function* (ctx) {
101
- const [addresses, id] = await Promise.all([self._protocolAddresses(chainId), self.id(chainId)]);
102
- const poolId = PoolId.from(id, counter ?? randomUint(48));
106
+ const addresses = await self._protocolAddresses(centrifugeId);
107
+ const poolId = PoolId.from(centrifugeId, counter ?? randomUint(48));
103
108
  const createPoolData = encodeFunctionData({
104
109
  abi: ABI.Hub,
105
110
  functionName: 'createPool',
@@ -177,7 +182,7 @@ export class Centrifuge {
177
182
  poolId.raw,
178
183
  sc.tokenName,
179
184
  sc.symbolName,
180
- sc.salt?.startsWith('0x') ? sc.salt : toHex(sc.salt ?? randomUint(256), { size: 32 }),
185
+ sc.salt?.startsWith('0x') ? sc.salt : generateShareClassSalt(poolId.raw),
181
186
  ],
182
187
  }));
183
188
  const accountIsDebitNormal = new Map();
@@ -203,7 +208,7 @@ export class Centrifuge {
203
208
  const createAccountsData = accountNumbers.map((account) => encodeFunctionData({
204
209
  abi: ABI.Hub,
205
210
  functionName: 'createAccount',
206
- args: [poolId.raw, account, accountIsDebitNormal.get(account)],
211
+ args: [poolId.raw, BigInt(account), accountIsDebitNormal.get(account)],
207
212
  }));
208
213
  yield* doTransaction('Create pool', ctx, () => {
209
214
  return ctx.walletClient.writeContract({
@@ -213,16 +218,10 @@ export class Centrifuge {
213
218
  args: [[createPoolData, setMetadataData, ...addScData, ...createAccountsData]],
214
219
  });
215
220
  });
216
- }, chainId);
221
+ }, centrifugeId);
217
222
  }
218
223
  id(chainId) {
219
- return this._query(['centrifugeId', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(({ messageDispatcher }) => {
220
- return this.getClient(chainId).readContract({
221
- address: messageDispatcher,
222
- abi: ABI.MessageDispatcher,
223
- functionName: 'localCentrifugeId',
224
- });
225
- })));
224
+ return this._chainToId(chainId);
226
225
  }
227
226
  /**
228
227
  * Get information about all supported blockchains from the indexer.
@@ -233,6 +232,7 @@ export class Centrifuge {
233
232
  items {
234
233
  explorer
235
234
  chainId
235
+ centrifugeId
236
236
  icon
237
237
  name
238
238
  network
@@ -242,6 +242,7 @@ export class Centrifuge {
242
242
  return data.blockchains.items.map((blockchain) => ({
243
243
  explorer: blockchain.explorer,
244
244
  chainId: Number(blockchain.chainId),
245
+ centrifugeId: Number(blockchain.centrifugeId),
245
246
  icon: blockchain.icon,
246
247
  name: blockchain.name,
247
248
  network: blockchain.network,
@@ -264,7 +265,7 @@ export class Centrifuge {
264
265
  }`, {}, (data) => {
265
266
  return data.pools.items.map((pool) => {
266
267
  const poolId = new PoolId(pool.id);
267
- return new Pool(this, poolId.toString(), Number(pool.blockchain.id));
268
+ return new Pool(this, poolId.toString());
268
269
  });
269
270
  });
270
271
  }
@@ -281,15 +282,15 @@ export class Centrifuge {
281
282
  * @param address - The token address
282
283
  * @param chainId - The chain ID
283
284
  */
284
- currency(address, chainId, tokenId = 0n) {
285
+ currency(address, centrifugeId, tokenId = 0n) {
285
286
  const curAddress = address.toLowerCase();
286
- return this._query(['currency', curAddress, chainId, tokenId], () => defer(async () => {
287
+ return this._query(['currency', curAddress, centrifugeId, tokenId], () => combineLatest([this.getClient(centrifugeId), this._idToChain(centrifugeId)]).pipe(switchMap(([client, chainId]) => defer(async () => {
287
288
  let decimals, name, symbol, supportsPermit;
288
289
  if (tokenId) {
289
290
  const contract = getContract({
290
291
  address: curAddress,
291
292
  abi: ABI.ERC6909,
292
- client: this.getClient(chainId),
293
+ client,
293
294
  });
294
295
  [decimals, name, symbol] = await Promise.all([
295
296
  contract.read.decimals([tokenId]),
@@ -302,7 +303,7 @@ export class Centrifuge {
302
303
  const contract = getContract({
303
304
  address: curAddress,
304
305
  abi: ABI.Currency,
305
- client: this.getClient(chainId),
306
+ client,
306
307
  });
307
308
  [decimals, name, symbol, supportsPermit] = await Promise.all([
308
309
  contract.read.decimals(),
@@ -321,23 +322,24 @@ export class Centrifuge {
321
322
  name,
322
323
  symbol,
323
324
  chainId,
325
+ centrifugeId,
324
326
  supportsPermit,
325
327
  };
326
- }));
328
+ }))));
327
329
  }
328
330
  /**
329
331
  * Get the asset currency details for a given asset ID
330
332
  * @param assetId - The asset ID to query
331
333
  */
332
334
  assetCurrency(assetId) {
333
- return this._query(['asset', assetId.toString()], () => this._idToChain(assetId.centrifugeId).pipe(switchMap((chainId) => this._protocolAddresses(chainId).pipe(map(({ spoke }) => ({ chainId, spoke })))), switchMap(async ({ spoke, chainId }) => {
334
- const [assetAddress, tokenId] = await this.getClient(chainId).readContract({
335
+ return this._query(['asset', assetId.toString()], () => combineLatest([this.getClient(assetId.centrifugeId), this._protocolAddresses(assetId.centrifugeId)]).pipe(switchMap(async ([client, { spoke }]) => {
336
+ const [assetAddress, tokenId] = await client.readContract({
335
337
  address: spoke,
336
338
  abi: ABI.Spoke,
337
339
  functionName: 'idToAsset',
338
340
  args: [assetId.raw],
339
341
  });
340
- return this.currency(assetAddress, chainId, tokenId);
342
+ return this.currency(assetAddress, assetId.centrifugeId, tokenId);
341
343
  })));
342
344
  }
343
345
  investor(address) {
@@ -349,11 +351,11 @@ export class Centrifuge {
349
351
  * @param owner - The owner address
350
352
  * @param chainId - The chain ID
351
353
  */
352
- balance(currency, owner, chainId) {
354
+ balance(currency, owner, centrifugeId) {
353
355
  const address = owner.toLowerCase();
354
- return this._query(['balance', currency, owner, chainId], () => {
355
- return this.currency(currency, chainId).pipe(switchMap((currencyMeta) => defer(async () => {
356
- const val = await this.getClient(chainId).readContract({
356
+ return this._query(['balance', currency, owner, centrifugeId], () => {
357
+ return combineLatest([this.currency(currency, centrifugeId), this.getClient(centrifugeId)]).pipe(switchMap(([currencyMeta, client]) => defer(async () => {
358
+ const val = await client.readContract({
357
359
  address: currency,
358
360
  abi: ABI.Currency,
359
361
  functionName: 'balanceOf',
@@ -371,16 +373,16 @@ export class Centrifuge {
371
373
  return event.args.from?.toLowerCase() === address || event.args.to?.toLowerCase() === address;
372
374
  });
373
375
  },
374
- }, chainId))));
376
+ }, centrifugeId))));
375
377
  });
376
378
  }
377
379
  /**
378
380
  * Get the assets that exist on a given spoke chain that have been registered on a given hub chain.
379
- * @param spokeChainId - The chain ID where the assets exist
380
- * @param hubChainId - The chain ID where the assets should optionally be registered
381
+ * @param spokeCentrifugeId - The Centrifuge ID where the assets exist
382
+ * @param hubCentrifugeId - The Centrifuge ID where the assets should optionally be registered
381
383
  */
382
- assets(spokeChainId, hubChainId = spokeChainId) {
383
- return this._query(['assets', spokeChainId, hubChainId], () => combineLatest([this.id(spokeChainId), this.id(hubChainId)]).pipe(switchMap(([spokeCentId, hubCentId]) => this._queryIndexer(`query ($hubCentId: String!) {
384
+ assets(spokeCentrifugeId, hubCentrifugeId = spokeCentrifugeId) {
385
+ return this._query(['assets', spokeCentrifugeId, hubCentrifugeId], () => this._queryIndexer(`query ($hubCentId: String!) {
384
386
  assetRegistrations(where: { centrifugeId: $hubCentId }, limit: 1000) {
385
387
  items {
386
388
  assetId
@@ -394,9 +396,9 @@ export class Centrifuge {
394
396
  }
395
397
  }
396
398
  }
397
- }`, { hubCentId: String(hubCentId) }).pipe(map((data) => {
399
+ }`, { hubCentId: String(hubCentrifugeId) }).pipe(map((data) => {
398
400
  return data.assetRegistrations.items
399
- .filter((assetReg) => assetReg.asset && Number(assetReg.asset.centrifugeId) === spokeCentId)
401
+ .filter((assetReg) => assetReg.asset && Number(assetReg.asset.centrifugeId) === spokeCentrifugeId)
400
402
  .map((assetReg) => {
401
403
  return {
402
404
  id: new AssetId(assetReg.assetId),
@@ -407,13 +409,13 @@ export class Centrifuge {
407
409
  tokenId: assetReg.asset.assetTokenId ? BigInt(assetReg.asset.assetTokenId) : undefined,
408
410
  };
409
411
  });
410
- })))));
412
+ })));
411
413
  }
412
414
  /**
413
415
  * Get the valuation addresses that can be used for holdings.
414
416
  */
415
- valuations(chainId) {
416
- return this._query(['valuations', chainId], () => this._protocolAddresses(chainId).pipe(map(({ identityValuation }) => {
417
+ valuations(centrifugeId) {
418
+ return this._query(['valuations', centrifugeId], () => this._protocolAddresses(centrifugeId).pipe(map(({ identityValuation }) => {
417
419
  return {
418
420
  identityValuation,
419
421
  };
@@ -422,8 +424,8 @@ export class Centrifuge {
422
424
  /**
423
425
  * Get the restriction hook addresses that can be used for share tokens.
424
426
  */
425
- restrictionHooks(chainId) {
426
- return this._query(['restrictionHooks', chainId], () => this._protocolAddresses(chainId).pipe(map(({ freezeOnlyHook, redemptionRestrictionsHook, fullRestrictionsHook, freelyTransferableHook }) => {
427
+ restrictionHooks(centrifugeId) {
428
+ return this._query(['restrictionHooks', centrifugeId], () => this._protocolAddresses(centrifugeId).pipe(map(({ freezeOnlyHook, redemptionRestrictionsHook, fullRestrictionsHook, freelyTransferableHook }) => {
427
429
  return {
428
430
  freezeOnlyHook,
429
431
  redemptionRestrictionsHook,
@@ -432,47 +434,58 @@ export class Centrifuge {
432
434
  };
433
435
  })));
434
436
  }
437
+ /**
438
+ * Get the adapter addresses that are available for cross-chain communication.
439
+ */
440
+ adapters(centrifugeId) {
441
+ return this._query(['adapters', centrifugeId], () => this._protocolAddresses(centrifugeId).pipe(map(({ axelarAdapter, wormholeAdapter, layerZeroAdapter, chainlinkAdapter }) => {
442
+ return {
443
+ axelarAdapter,
444
+ wormholeAdapter,
445
+ layerZeroAdapter,
446
+ chainlinkAdapter,
447
+ };
448
+ })));
449
+ }
435
450
  /**
436
451
  * Register an asset
437
- * @param originChainId - The chain ID where the asset exists
438
- * @param registerOnChainId - The chain ID where the asset should be registered
452
+ * @param originCentrifugeId - The centrifuge ID where the asset exists
453
+ * @param registerOnCentrifugeId - The centrifuge ID where the asset should be registered
439
454
  * @param assetAddress - The address of the asset to register
440
455
  * @param tokenId - Optional token ID for ERC6909 assets
441
456
  */
442
- registerAsset(originChainId, registerOnChainId, assetAddress, tokenId = 0) {
457
+ registerAsset(originCentrifugeId, registerOnCentrifugeId, assetAddress, tokenId = 0) {
443
458
  const self = this;
444
459
  return this._transact(async function* (ctx) {
445
- const [addresses, id, estimate] = await Promise.all([
446
- self._protocolAddresses(originChainId),
447
- self.id(registerOnChainId),
448
- self._estimate(originChainId, { chainId: registerOnChainId }, MessageType.RegisterAsset),
460
+ const [addresses, estimate] = await Promise.all([
461
+ self._protocolAddresses(originCentrifugeId),
462
+ self._estimate(originCentrifugeId, registerOnCentrifugeId, MessageType.RegisterAsset),
449
463
  ]);
450
464
  yield* doTransaction('Register asset', ctx, () => ctx.walletClient.writeContract({
451
465
  address: addresses.spoke,
452
466
  abi: ABI.Spoke,
453
467
  functionName: 'registerAsset',
454
- args: [id, assetAddress, BigInt(tokenId)],
468
+ args: [originCentrifugeId, assetAddress, BigInt(tokenId), ctx.signingAddress],
455
469
  value: estimate,
456
470
  }));
457
- }, originChainId);
471
+ }, originCentrifugeId);
458
472
  }
459
473
  /**
460
474
  * Repay an underpaid batch of messages on the Gateway
461
475
  */
462
- repayBatch(fromChain, to, batch, extraPayment = 0n) {
476
+ repayBatch(fromCentrifugeId, toCentrifugeId, batch, extraPayment = 0n) {
463
477
  const self = this;
464
478
  return this._transact(async function* (ctx) {
465
- const [addresses, toCentId] = await Promise.all([
466
- self._protocolAddresses(fromChain),
467
- 'chainId' in to ? self.id(to.chainId) : to.centId,
479
+ const [addresses, client] = await Promise.all([
480
+ self._protocolAddresses(fromCentrifugeId),
481
+ self.getClient(fromCentrifugeId),
468
482
  ]);
469
- const client = self.getClient(fromChain);
470
483
  const batchHash = keccak256(batch);
471
484
  const [counter, gasLimit] = await client.readContract({
472
485
  address: addresses.gateway,
473
486
  abi: ABI.Gateway,
474
487
  functionName: 'underpaid',
475
- args: [toCentId, batchHash],
488
+ args: [toCentrifugeId, batchHash],
476
489
  });
477
490
  if (counter === 0n) {
478
491
  throw new Error(`Batch is not underpaid and can't be repaid. Batch hash: "${batchHash}"`);
@@ -481,38 +494,38 @@ export class Centrifuge {
481
494
  address: addresses.multiAdapter,
482
495
  abi: ABI.MultiAdapter,
483
496
  functionName: 'estimate',
484
- args: [toCentId, batch, gasLimit],
497
+ args: [toCentrifugeId, batch, gasLimit],
485
498
  });
486
499
  yield* doTransaction('Repay', ctx, () => ctx.walletClient.writeContract({
487
500
  address: addresses.gateway,
488
501
  abi: ABI.Gateway,
489
502
  functionName: 'repay',
490
- args: [toCentId, batch],
503
+ args: [toCentrifugeId, batch, ctx.signingAddress],
491
504
  value: estimate + extraPayment,
492
505
  }));
493
- }, fromChain);
506
+ }, fromCentrifugeId);
494
507
  }
495
508
  /**
496
509
  * Retry a failed message on the destination chain
497
510
  */
498
- retryMessage(fromChain, toChain, message) {
511
+ retryMessage(fromCentrifugeId, toCentrifugeId, message) {
499
512
  const self = this;
500
513
  return this._transact(async function* (ctx) {
501
- const [addresses, fromCentId] = await Promise.all([self._protocolAddresses(toChain), self.id(fromChain)]);
514
+ const addresses = await self._protocolAddresses(toCentrifugeId);
502
515
  yield* doTransaction('Retry', ctx, () => ctx.walletClient.writeContract({
503
516
  address: addresses.gateway,
504
517
  abi: ABI.Gateway,
505
518
  functionName: 'retry',
506
- args: [fromCentId, message],
519
+ args: [fromCentrifugeId, message],
507
520
  }));
508
- }, toChain);
521
+ }, toCentrifugeId);
509
522
  }
510
523
  /**
511
524
  * Get the decimals of asset on the Hub side
512
525
  * @internal
513
526
  */
514
- _assetDecimals(assetId, chainId) {
515
- return this._query(['assetDecimals', assetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => this.getClient(chainId).readContract({
527
+ _assetDecimals(assetId, centrifugeId) {
528
+ return this._query(['assetDecimals', assetId.toString()], () => combineLatest([this._protocolAddresses(centrifugeId), this.getClient(centrifugeId)]).pipe(switchMap(([{ hubRegistry }, client]) => client.readContract({
516
529
  address: hubRegistry,
517
530
  // Use inline ABI because of function overload
518
531
  abi: parseAbi(['function decimals(uint128) view returns (uint8)']),
@@ -525,14 +538,13 @@ export class Centrifuge {
525
538
  * which is the contract that moves funds into the vault on behalf of the investor.
526
539
  * @param owner - The address of the owner
527
540
  * @param spender - The address of the spender
528
- * @param chainId - The chain ID where the asset is located
541
+ * @param centrifugeId - The centrifuge ID where the asset is located
529
542
  * @param asset - The address of the asset
530
543
  * @param tokenId - Optional token ID for ERC6909 assets
531
544
  * @internal
532
545
  */
533
- _allowance(owner, spender, chainId, asset, tokenId) {
534
- return this._query(['allowance', owner.toLowerCase(), spender.toLowerCase(), asset.toLowerCase(), chainId, tokenId], () => defer(async () => {
535
- const client = this.getClient(chainId);
546
+ _allowance(owner, spender, centrifugeId, asset, tokenId) {
547
+ return this._query(['allowance', owner.toLowerCase(), spender.toLowerCase(), asset.toLowerCase(), centrifugeId, tokenId], () => this.getClient(centrifugeId).pipe(switchMap((client) => defer(async () => {
536
548
  if (tokenId) {
537
549
  return client.readContract({
538
550
  address: asset,
@@ -557,27 +569,27 @@ export class Centrifuge {
557
569
  event.args.from?.toLowerCase() === owner.toLowerCase());
558
570
  });
559
571
  },
560
- }, chainId)));
572
+ }, centrifugeId)))));
561
573
  }
562
574
  /**
563
575
  * Returns an observable of all events on a given chain.
564
576
  * @internal
565
577
  */
566
- _events(chainId) {
567
- return this._query(['events', chainId], () => new Observable((subscriber) => {
568
- const unwatch = this.getClient(chainId).watchEvent({
578
+ _events(centrifugeId) {
579
+ return this._query(['events', centrifugeId], () => this.getClient(centrifugeId).pipe(switchMap((client) => new Observable((subscriber) => {
580
+ const unwatch = client.watchEvent({
569
581
  onLogs: (logs) => subscriber.next(logs),
570
582
  });
571
583
  return unwatch;
572
- }).pipe(filter((logs) => logs.length > 0), shareReplay({ bufferSize: 1, refCount: true }) // ensures only one watcher per chainId
584
+ })), filter((logs) => logs.length > 0), shareReplay({ bufferSize: 1, refCount: true }) // ensures only one watcher per centrifugeId
573
585
  ), { cache: true });
574
586
  }
575
587
  /**
576
588
  * Returns an observable of events on a given chain, filtered by name(s) and address(es).
577
589
  * @internal
578
590
  */
579
- _filteredEvents(address, eventName, chainId) {
580
- return this._events(chainId).pipe(map((logs) => {
591
+ _filteredEvents(address, eventName, centrifugeId) {
592
+ return this._events(centrifugeId).pipe(map((logs) => {
581
593
  return parseEventLogs({
582
594
  address,
583
595
  eventName,
@@ -649,11 +661,11 @@ export class Centrifuge {
649
661
  * ```ts
650
662
  * const address = '0xabc...123'
651
663
  * const tUSD = '0x456...def'
652
- * const chainId = 1
664
+ * const centrifugeId = 1
653
665
  *
654
666
  * // Wrap an observable that continuously emits values
655
- * const query = this._query(['balance', address, tUSD, chainId], () => {
656
- * return defer(() => fetchBalance(address, tUSD, chainId))
667
+ * const query = this._query(['balance', address, tUSD, centrifugeId], () => {
668
+ * return defer(() => fetchBalance(address, tUSD, centrifugeId))
657
669
  * .pipe(
658
670
  * repeatOnEvents(
659
671
  * this,
@@ -661,7 +673,7 @@ export class Centrifuge {
661
673
  * address: tUSD,
662
674
  * eventName: 'Transfer',
663
675
  * },
664
- * chainId
676
+ * centrifugeId
665
677
  * )
666
678
  * )
667
679
  * })
@@ -688,11 +700,11 @@ export class Centrifuge {
688
700
  * ```ts
689
701
  * const address = '0xabc...123'
690
702
  * const tUSD = '0x456...def'
691
- * const chainId = 1
703
+ * const centrifugeId = 1
692
704
  *
693
705
  * // Wrap an observable that only emits one value and then completes
694
- * const query = this._query(['balance', address, tUSD, chainId], () => {
695
- * return defer(() => fetchBalance(address, tUSD, chainId))
706
+ * const query = this._query(['balance', address, tUSD, centrifugeId], () => {
707
+ * return defer(() => fetchBalance(address, tUSD, centrifugeId))
696
708
  * }, { valueCacheTime: 60_000 })
697
709
  *
698
710
  * // Logs the current balance and updated balances whenever a new
@@ -762,7 +774,7 @@ export class Centrifuge {
762
774
  *
763
775
  * @internal
764
776
  */
765
- _transact(transactionCallback, chainId) {
777
+ _transact(transactionCallback, centrifugeId) {
766
778
  const self = this;
767
779
  async function* transact() {
768
780
  let isBatching = false;
@@ -772,8 +784,11 @@ export class Centrifuge {
772
784
  const { signer } = self;
773
785
  if (!signer)
774
786
  throw new Error('Signer not set');
775
- const publicClient = self.getClient(chainId);
776
- const chain = self.getChainConfig(chainId);
787
+ const [chainId, publicClient, chain] = await Promise.all([
788
+ self._idToChain(centrifugeId),
789
+ self.getClient(centrifugeId),
790
+ self.getChainConfig(centrifugeId),
791
+ ]);
777
792
  let walletClient = isLocalAccount(signer)
778
793
  ? createWalletClient({
779
794
  account: signer,
@@ -800,7 +815,7 @@ export class Centrifuge {
800
815
  isBatching,
801
816
  signingAddress: address,
802
817
  chain,
803
- chainId,
818
+ centrifugeId,
804
819
  publicClient,
805
820
  walletClient,
806
821
  signer,
@@ -819,7 +834,7 @@ export class Centrifuge {
819
834
  const $tx = defer(transact).pipe(mergeMap((d) => (isObservable(d) ? d : of(d))));
820
835
  makeThenable($tx, true);
821
836
  Object.assign($tx, {
822
- chainId,
837
+ centrifugeId,
823
838
  });
824
839
  return $tx;
825
840
  }
@@ -833,9 +848,9 @@ export class Centrifuge {
833
848
  * @internal
834
849
  */
835
850
  _experimental_batch(title, transactions) {
836
- const chainIds = [...new Set(transactions.map((tx) => tx.chainId))];
837
- if (chainIds.length !== 1) {
838
- throw new Error(`Cannot batch transactions on different chains: ${chainIds.join(', ')}`);
851
+ const centIds = [...new Set(transactions.map((tx) => tx.centrifugeId))];
852
+ if (centIds.length !== 1) {
853
+ throw new Error(`Cannot batch transactions on different networks. Found Centrifuge IDs: ${centIds.join(', ')}`);
839
854
  }
840
855
  for (const tx of transactions) {
841
856
  this.#isBatching.add(tx);
@@ -867,98 +882,50 @@ export class Centrifuge {
867
882
  }
868
883
  yield* wrapTransaction(title, ctx, { data, value, contract: contracts[0], messages });
869
884
  }));
870
- }, chainIds[0]);
885
+ }, centIds[0]);
871
886
  }
872
887
  /** @internal */
873
- _protocolAddresses(chainId) {
874
- return this._query(['protocolAddresses', chainId], () => this._deployments().pipe(map((data) => {
875
- if (!this.chains.includes(chainId)) {
876
- throw new Error(`Chain ID "${chainId}" not supported`);
877
- }
878
- const deployment = data.deployments.items.find((d) => Number(d.chainId) === chainId);
888
+ _protocolAddresses(centrifugeId) {
889
+ return this._query(['protocolAddresses', centrifugeId], () => this._deployments().pipe(map((data) => {
890
+ const deployment = data.deployments.items.find((d) => Number(d.centrifugeId) === centrifugeId);
879
891
  if (!deployment) {
880
- throw new Error(`No protocol contracts found for chain ID "${chainId}"`);
892
+ throw new Error(`No protocol contracts found for centrifuge ID "${centrifugeId}"`);
881
893
  }
882
894
  return deployment;
883
895
  })));
884
896
  }
885
- /** @internal */
886
- _getQuote(valuationAddress, baseAmount, baseAssetId, quoteAssetId, chainId) {
887
- return this._query(['getQuote', baseAmount, baseAssetId.toString(), quoteAssetId.toString()], () => timer(0, 60_000).pipe(switchMap(() => this._protocolAddresses(chainId)), switchMap(({ hubRegistry }) => defer(async () => {
888
- const [quote, quoteDecimals] = await Promise.all([
889
- this.getClient(chainId).readContract({
890
- address: valuationAddress,
891
- abi: ABI.Valuation,
892
- functionName: 'getQuote',
893
- args: [baseAmount.toBigInt(), baseAssetId.raw, quoteAssetId.raw],
894
- }),
895
- this.getClient(chainId).readContract({
896
- address: hubRegistry,
897
- // Use inline ABI because of function overload
898
- abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
899
- functionName: 'decimals',
900
- args: [quoteAssetId.raw],
901
- }),
902
- ]);
903
- return new Balance(quote, quoteDecimals);
904
- }))));
905
- }
906
897
  /**
907
898
  * Estimates the gas cost needed to bridge the message from one chain to another,
908
899
  * that results from a transaction
909
900
  * @internal
910
901
  */
911
- _estimate(fromChain, to, messageType) {
912
- return this._query(['estimate', fromChain, to, messageType], () => this._protocolAddresses(fromChain).pipe(switchMap(({ multiAdapter, gasService }) => {
902
+ _estimate(fromCentrifugeId, toCentrifugeId, messageType) {
903
+ return this._query(['estimate', fromCentrifugeId, toCentrifugeId, messageType], () => combineLatest([this._protocolAddresses(fromCentrifugeId), this.getClient(fromCentrifugeId)]).pipe(switchMap(([{ multiAdapter, gasService }, client]) => {
913
904
  const types = Array.isArray(messageType) ? messageType : [messageType];
914
905
  return combineLatest([
915
- 'chainId' in to ? this.id(to.chainId) : of(to.centId),
916
906
  ...types.map((typeAndMaybeSubtype) => {
917
907
  const type = typeof typeAndMaybeSubtype === 'number' ? typeAndMaybeSubtype : typeAndMaybeSubtype.type;
918
908
  const subtype = typeof typeAndMaybeSubtype === 'number' ? undefined : typeAndMaybeSubtype.subtype;
919
909
  const data = emptyMessage(type, subtype);
920
- return this.getClient(fromChain).readContract({
910
+ return client.readContract({
921
911
  address: gasService,
922
912
  abi: ABI.GasService,
923
- functionName: 'messageGasLimit',
924
- args: [0, data],
913
+ functionName: 'messageOverallGasLimit',
914
+ args: [toCentrifugeId, data],
925
915
  });
926
916
  }),
927
- ]).pipe(switchMap(async ([toCentId, ...gasLimits]) => {
928
- const estimate = await this.getClient(fromChain).readContract({
917
+ ]).pipe(switchMap(async ([...gasLimits]) => {
918
+ const estimate = await client.readContract({
929
919
  address: multiAdapter,
930
920
  abi: ABI.MultiAdapter,
931
921
  functionName: 'estimate',
932
- args: [toCentId, '0x0', gasLimits.reduce((acc, val) => acc + val, 0n)],
922
+ args: [toCentrifugeId, '0x0', gasLimits.reduce((acc, val) => acc + val, 0n)],
933
923
  });
934
924
  return (estimate * 3n) / 2n; // Add 50% buffer to the estimate
935
925
  }));
936
926
  })));
937
927
  }
938
928
  /** @internal */
939
- _maxBatchGasLimit(chainId) {
940
- return this._query(['maxBatchGasLimit', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(async ({ gasService }) => {
941
- try {
942
- // `batchGasLimit` was renamed to `maxBatchGasLimit`, support both for backwards compatibility,
943
- // until all chains are updated
944
- return await this.getClient(chainId).readContract({
945
- address: gasService,
946
- abi: ABI.GasService,
947
- functionName: 'maxBatchGasLimit',
948
- args: [0],
949
- });
950
- }
951
- catch {
952
- return await this.getClient(chainId).readContract({
953
- address: gasService,
954
- abi: ABI.GasService,
955
- functionName: 'batchGasLimit',
956
- args: [0],
957
- });
958
- }
959
- })));
960
- }
961
- /** @internal */
962
929
  _idToChain(centrifugeId) {
963
930
  return this._query(['idToChain', centrifugeId], () => this._deployments().pipe(map((data) => {
964
931
  const item = data.blockchains.items.find((b) => Number(b.centrifugeId) === centrifugeId);
@@ -968,6 +935,15 @@ export class Centrifuge {
968
935
  })));
969
936
  }
970
937
  /** @internal */
938
+ _chainToId(chainId) {
939
+ return this._query(['chainToId', chainId], () => this._deployments().pipe(map((data) => {
940
+ const item = data.blockchains.items.find((b) => Number(b.id) === chainId);
941
+ if (!item)
942
+ throw new Error(`Blockchain with chain ID "${chainId}" not found`);
943
+ return Number(item.centrifugeId);
944
+ })));
945
+ }
946
+ /** @internal */
971
947
  _deployments() {
972
948
  return this._query(['deployments'], () => this._getIndexerObservable(`{
973
949
  blockchains {
@@ -985,6 +961,7 @@ export class Centrifuge {
985
961
  balanceSheet
986
962
  centrifugeId
987
963
  chainId
964
+ chainlinkAdapter
988
965
  freezeOnlyHook
989
966
  fullRestrictionsHook
990
967
  gasService
@@ -1003,7 +980,9 @@ export class Centrifuge {
1003
980
  root
1004
981
  routerEscrow
1005
982
  shareClassManager
983
+ batchRequestManager
1006
984
  spoke
985
+ vaultRegistry
1007
986
  syncDepositVaultFactory
1008
987
  syncManager
1009
988
  wormholeAdapter