@centrifuge/sdk 0.55.1 → 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 +61 -49
  142. package/dist/entities/ShareClass.d.ts.map +1 -1
  143. package/dist/entities/ShareClass.js +383 -299
  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,18 +1,19 @@
1
- import { catchError, combineLatest, defer, EMPTY, expand, filter, firstValueFrom, map, of, switchMap } from 'rxjs';
1
+ import { catchError, combineLatest, defer, EMPTY, expand, filter, firstValueFrom, map, of, switchMap, timer, } from 'rxjs';
2
2
  import { encodeFunctionData, encodePacked, getContract } from 'viem';
3
3
  import { ABI } from '../abi/index.js';
4
4
  import { AccountType } from '../types/holdings.js';
5
5
  import { MessageType } from '../types/transaction.js';
6
+ import { AddressMap } from '../utils/AddressMap.js';
6
7
  import { Balance, Price } from '../utils/BigInt.js';
7
- import { addressToBytes32, randomUint } from '../utils/index.js';
8
+ import { addressToBytes32, encode, randomUint } from '../utils/index.js';
8
9
  import { repeatOnEvents } from '../utils/rx.js';
9
10
  import { wrapTransaction } from '../utils/transaction.js';
10
11
  import { AssetId, ShareClassId } from '../utils/types.js';
11
12
  import { BalanceSheet } from './BalanceSheet.js';
12
13
  import { Entity } from './Entity.js';
13
- import { PoolNetwork } from './PoolNetwork.js';
14
+ import { PoolNetwork, VaultManagerTrustedCall } from './PoolNetwork.js';
14
15
  import { Vault } from './Vault.js';
15
- import { AddressMap } from '../utils/AddressMap.js';
16
+ const GAS_LIMIT = 30000000n;
16
17
  /**
17
18
  * Query and interact with a share class, which allows querying total issuance, NAV per share,
18
19
  * and allows interactions related to asynchronous deposits and redemptions.
@@ -64,11 +65,11 @@ export class ShareClass extends Entity {
64
65
  };
65
66
  })));
66
67
  }
67
- balanceSheet(chainId) {
68
- return this._query(['balanceSheet', chainId], () => this.pool.activeNetworks().pipe(map((networks) => {
69
- const network = networks.find((n) => n.chainId === chainId);
68
+ balanceSheet(centrifugeId) {
69
+ return this._query(['balanceSheet', centrifugeId], () => this.pool.activeNetworks().pipe(map((networks) => {
70
+ const network = networks.find((n) => n.centrifugeId === centrifugeId);
70
71
  if (!network) {
71
- throw new Error(`No active network found for chain ID ${chainId}`);
72
+ throw new Error(`No active network found for centrifuge ID ${centrifugeId}`);
72
73
  }
73
74
  return new BalanceSheet(this._root, network, this);
74
75
  })));
@@ -78,15 +79,15 @@ export class ShareClass extends Entity {
78
79
  if (networks.length === 0)
79
80
  return of([]);
80
81
  return combineLatest(networks.map((network) => combineLatest([
81
- this._share(network.chainId).pipe(catchError(() => of(null))),
82
- this._restrictionManager(network.chainId).pipe(catchError(() => of(null))),
83
- this.valuation(network.chainId).pipe(catchError(() => of(null))),
82
+ this._share(network.centrifugeId),
83
+ this._restrictionManager(network.centrifugeId).pipe(catchError(() => of(null))),
84
+ this.valuation(network.centrifugeId),
84
85
  of(network),
85
86
  ])));
86
87
  }), map((data) => data
87
88
  .filter(([share, restrictionManager]) => share != null && restrictionManager != null)
88
89
  .map(([share, restrictionManager, valuation, network]) => ({
89
- chainId: network.chainId,
90
+ centrifugeId: network.centrifugeId,
90
91
  shareTokenAddress: share,
91
92
  restrictionManagerAddress: restrictionManager,
92
93
  valuation,
@@ -100,12 +101,12 @@ export class ShareClass extends Entity {
100
101
  tokenPrice
101
102
  address
102
103
  blockchain {
103
- id
104
+ centrifugeId
104
105
  }
105
106
  }
106
107
  }
107
108
  }`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
108
- chainId: Number(item.blockchain.id),
109
+ centrifugeId: Number(item.blockchain.centrifugeId),
109
110
  totalIssuance: new Balance(item.totalIssuance, poolCurrency.decimals),
110
111
  pricePerShare: new Price(item.tokenPrice),
111
112
  nav: new Balance(item.totalIssuance, poolCurrency.decimals).mul(new Price(item.tokenPrice)),
@@ -114,31 +115,30 @@ export class ShareClass extends Entity {
114
115
  }
115
116
  /**
116
117
  * Query the vaults of the share class.
117
- * @param chainId The optional chain ID to query the vaults on.
118
+ * @param centrifugeId The optional centrifuge ID to query the vaults on.
118
119
  * @param includeUnlinked Whether to include unlinked vaults.
119
120
  * @returns Vaults of the share class.
120
121
  */
121
- vaults(chainId, includeUnlinked = false) {
122
- return this._query(['vaults', chainId, includeUnlinked.toString()], () => this._allVaults().pipe(map((allVaults) => {
123
- const vaults = allVaults.filter((vault) => {
124
- if (chainId && vault.chainId !== chainId)
122
+ vaults(centrifugeId, includeUnlinked = false) {
123
+ return this._query(['vaults', centrifugeId, includeUnlinked.toString()], () => this._allVaults().pipe(map((allVaults) => {
124
+ return allVaults.filter((vault) => {
125
+ if (centrifugeId !== undefined && vault.centrifugeId !== centrifugeId)
125
126
  return false;
126
127
  if (!includeUnlinked && vault.status === 'Unlinked')
127
128
  return false;
128
129
  return true;
129
130
  });
130
- return vaults.map((vault) => new Vault(this._root, new PoolNetwork(this._root, this.pool, vault.chainId), this, vault.assetAddress, vault.address, vault.assetId));
131
- })));
131
+ }), map((vaults) => vaults.map((vault) => new Vault(this._root, new PoolNetwork(this._root, this.pool, vault.centrifugeId), this, vault.assetAddress, vault.address, vault.assetId)))));
132
132
  }
133
133
  /**
134
134
  * Query all the balances of the share class (from BalanceSheet and Holdings).
135
135
  */
136
- balances(chainId) {
137
- return this._query(['balances', chainId], () => combineLatest([this._balances(), this.pool.currency()]).pipe(switchMap(([res, poolCurrency]) => {
136
+ balances(centrifugeId) {
137
+ return this._query(['balances', centrifugeId], () => combineLatest([this._balances(), this.pool.currency()]).pipe(switchMap(([res, poolCurrency]) => {
138
138
  if (res.length === 0) {
139
139
  return of([]);
140
140
  }
141
- const items = res.filter((item) => Number(item.asset.blockchain.id) === chainId || !chainId);
141
+ const items = res.filter((item) => Number(item.centrifugeId) === centrifugeId || !centrifugeId);
142
142
  if (items.length === 0)
143
143
  return of([]);
144
144
  return combineLatest([
@@ -146,11 +146,11 @@ export class ShareClass extends Entity {
146
146
  if (!holding.holding)
147
147
  return of(null);
148
148
  const assetId = new AssetId(holding.assetId);
149
- return this._holding(assetId);
149
+ return this._holding(assetId).pipe(catchError(() => of(null)));
150
150
  })),
151
151
  combineLatest(items.map((holding) => {
152
152
  const assetId = new AssetId(holding.assetId);
153
- return this._balance(Number(holding.asset.blockchain.id), {
153
+ return this._balance(Number(holding.centrifugeId), {
154
154
  address: holding.asset.address,
155
155
  assetTokenId: BigInt(holding.asset.assetTokenId),
156
156
  id: assetId,
@@ -174,7 +174,7 @@ export class ShareClass extends Entity {
174
174
  tokenId: BigInt(data.asset.assetTokenId),
175
175
  name: data.asset.name,
176
176
  symbol: data.asset.symbol,
177
- chainId: Number(data.asset.blockchain.id),
177
+ centrifugeId: Number(data.centrifugeId),
178
178
  },
179
179
  holding: holding && {
180
180
  valuation: holding.valuation,
@@ -201,20 +201,20 @@ export class ShareClass extends Entity {
201
201
  this.balances(),
202
202
  ]).pipe(map(([epochs, outInv, outRed, balancesData]) => {
203
203
  const invByKey = new Map();
204
- outInv.forEach((o) => invByKey.set(`${o.assetId.toString()}-${o.chainId}`, o.amount));
204
+ outInv.forEach((o) => invByKey.set(`${o.assetId.toString()}-${o.centrifugeId}`, o.amount));
205
205
  const redByKey = new Map();
206
- outRed.forEach((o) => redByKey.set(`${o.assetId.toString()}-${o.chainId}`, o.amount));
206
+ outRed.forEach((o) => redByKey.set(`${o.assetId.toString()}-${o.centrifugeId}`, o.amount));
207
207
  const priceByAsset = new Map();
208
208
  balancesData.forEach((b) => priceByAsset.set(b.assetId.toString(), b.price));
209
209
  return epochs.map((epoch, i) => {
210
210
  const vault = vaults[i];
211
- const key = `${vault.assetId.toString()}-${vault.chainId}`;
211
+ const key = `${vault.assetId.toString()}-${vault.centrifugeId}`;
212
212
  const queuedInvest = invByKey.get(key) ?? new Balance(0n, 18);
213
213
  const queuedRedeem = redByKey.get(key) ?? new Balance(0n, 18);
214
214
  const assetPrice = priceByAsset.get(vault.assetId.toString()) ?? Price.fromFloat(1);
215
215
  return {
216
216
  assetId: vault.assetId,
217
- chainId: vault.chainId,
217
+ centrifugeId: vault.centrifugeId,
218
218
  queuedInvest,
219
219
  queuedRedeem,
220
220
  assetPrice,
@@ -227,12 +227,16 @@ export class ShareClass extends Entity {
227
227
  /**
228
228
  * Check if an address is a member of the share class.
229
229
  * @param address Address to check
230
- * @param chainId Chain ID of the network on which to check the member
230
+ * @param centrifugeId Centrifuge ID of the network on which to check the member
231
231
  */
232
- member(address, chainId) {
232
+ member(address, centrifugeId) {
233
233
  const addr = address.toLowerCase();
234
- return this._query(['member', addr, chainId], () => combineLatest([this._share(chainId), this._restrictionManager(chainId)]).pipe(switchMap(([share, restrictionManager]) => defer(async () => {
235
- const res = await this._root.getClient(chainId).readContract({
234
+ return this._query(['member', addr, centrifugeId], () => combineLatest([
235
+ this._share(centrifugeId),
236
+ this._restrictionManager(centrifugeId),
237
+ this._root.getClient(centrifugeId),
238
+ ]).pipe(switchMap(([share, restrictionManager, client]) => defer(async () => {
239
+ const res = await client.readContract({
236
240
  address: restrictionManager,
237
241
  abi: ABI.RestrictionManager,
238
242
  functionName: 'isMember',
@@ -246,7 +250,7 @@ export class ShareClass extends Entity {
246
250
  address: restrictionManager,
247
251
  eventName: 'UpdateMember',
248
252
  filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
249
- }, chainId), catchError((e) => {
253
+ }, centrifugeId), catchError((e) => {
250
254
  console.warn('Error checking member status', e);
251
255
  // Freeze-only hook doesn't have isMember function
252
256
  return of({
@@ -267,7 +271,7 @@ export class ShareClass extends Entity {
267
271
  const self = this;
268
272
  return this._transact(async function* (ctx) {
269
273
  const [{ hub }, metadata] = await Promise.all([
270
- self._root._protocolAddresses(self.pool.chainId),
274
+ self._root._protocolAddresses(self.pool.centrifugeId),
271
275
  self.pool.metadata(),
272
276
  ]);
273
277
  let data;
@@ -351,13 +355,13 @@ export class ShareClass extends Entity {
351
355
  contract: hub,
352
356
  data,
353
357
  });
354
- }, this.pool.chainId);
358
+ }, this.pool.centrifugeId);
355
359
  }
356
- updateSharePrice(pricePerShare) {
360
+ updateSharePrice(pricePerShare, updatedAt = new Date()) {
357
361
  const self = this;
358
362
  return this._transact(async function* (ctx) {
359
363
  const [{ hub }, activeNetworks] = await Promise.all([
360
- self._root._protocolAddresses(self.pool.chainId),
364
+ self._root._protocolAddresses(self.pool.centrifugeId),
361
365
  self.pool.activeNetworks(),
362
366
  ]);
363
367
  const batch = [];
@@ -370,17 +374,22 @@ export class ShareClass extends Entity {
370
374
  batch.push(encodeFunctionData({
371
375
  abi: ABI.Hub,
372
376
  functionName: 'updateSharePrice',
373
- args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
377
+ args: [
378
+ self.pool.id.raw,
379
+ self.id.raw,
380
+ pricePerShare.toBigInt(),
381
+ BigInt(Math.floor(updatedAt.getTime() / 1000)),
382
+ ],
374
383
  }));
375
384
  await Promise.all(activeNetworks.map(async (activeNetwork) => {
376
385
  const networkDetails = await activeNetwork.details();
377
- const id = await self._root.id(activeNetwork.chainId);
386
+ const id = activeNetwork.centrifugeId;
378
387
  const isShareClassInNetwork = networkDetails.activeShareClasses.find((shareClass) => shareClass.id.equals(self.id));
379
388
  if (isShareClassInNetwork) {
380
389
  batch.push(encodeFunctionData({
381
390
  abi: ABI.Hub,
382
391
  functionName: 'notifySharePrice',
383
- args: [self.pool.id.raw, self.id.raw, id],
392
+ args: [self.pool.id.raw, self.id.raw, id, ctx.signingAddress],
384
393
  }));
385
394
  addMessage(id, MessageType.NotifyPricePoolPerShare);
386
395
  }
@@ -390,81 +399,75 @@ export class ShareClass extends Entity {
390
399
  data: batch,
391
400
  messages,
392
401
  });
393
- }, this.pool.chainId);
402
+ }, this.pool.centrifugeId);
394
403
  }
395
404
  setMaxAssetPriceAge(assetId, maxPriceAge) {
396
405
  const self = this;
397
406
  return this._transact(async function* (ctx) {
398
- const { hub } = await self._root._protocolAddresses(self.pool.chainId);
407
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
399
408
  yield* wrapTransaction('Set max asset price age', ctx, {
400
409
  contract: hub,
401
410
  data: encodeFunctionData({
402
411
  abi: ABI.Hub,
403
412
  functionName: 'setMaxAssetPriceAge',
404
- args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
413
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge), ctx.signingAddress],
405
414
  }),
406
415
  messages: {
407
- [assetId.centrifugeId]: [MessageType.MaxAssetPriceAge],
416
+ [assetId.centrifugeId]: [MessageType.SetMaxAssetPriceAge],
408
417
  },
409
418
  });
410
- }, this.pool.chainId);
419
+ }, this.pool.centrifugeId);
411
420
  }
412
- setMaxSharePriceAge(chainId, maxPriceAge) {
421
+ setMaxSharePriceAge(centrifugeId, maxPriceAge) {
413
422
  const self = this;
414
423
  return this._transact(async function* (ctx) {
415
- const [{ hub }, id] = await Promise.all([
416
- self._root._protocolAddresses(self.pool.chainId),
417
- self._root.id(chainId),
418
- ]);
424
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
419
425
  yield* wrapTransaction('Set max share price age', ctx, {
420
426
  contract: hub,
421
427
  data: encodeFunctionData({
422
428
  abi: ABI.Hub,
423
429
  functionName: 'setMaxSharePriceAge',
424
- args: [id, self.pool.id.raw, self.id.raw, BigInt(maxPriceAge)],
430
+ args: [self.pool.id.raw, self.id.raw, centrifugeId, BigInt(maxPriceAge), ctx.signingAddress],
425
431
  }),
426
432
  messages: {
427
- [id]: [MessageType.MaxSharePriceAge],
433
+ [centrifugeId]: [MessageType.SetMaxSharePriceAge],
428
434
  },
429
435
  });
430
- }, this.pool.chainId);
436
+ }, this.pool.centrifugeId);
431
437
  }
432
438
  notifyAssetPrice(assetId) {
433
439
  const self = this;
434
440
  return this._transact(async function* (ctx) {
435
- const { hub } = await self._root._protocolAddresses(self.pool.chainId);
441
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
436
442
  yield* wrapTransaction('Notify asset price', ctx, {
437
443
  contract: hub,
438
444
  data: encodeFunctionData({
439
445
  abi: ABI.Hub,
440
446
  functionName: 'notifyAssetPrice',
441
- args: [self.pool.id.raw, self.id.raw, assetId.raw],
447
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, ctx.signingAddress],
442
448
  }),
443
449
  messages: {
444
450
  [assetId.centrifugeId]: [MessageType.NotifyPricePoolPerAsset],
445
451
  },
446
452
  });
447
- }, this.pool.chainId);
453
+ }, this.pool.centrifugeId);
448
454
  }
449
- notifySharePrice(chainId) {
455
+ notifySharePrice(centrifugeId) {
450
456
  const self = this;
451
457
  return this._transact(async function* (ctx) {
452
- const [{ hub }, id] = await Promise.all([
453
- self._root._protocolAddresses(self.pool.chainId),
454
- self._root.id(chainId),
455
- ]);
458
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
456
459
  yield* wrapTransaction('Notify share price', ctx, {
457
460
  contract: hub,
458
461
  data: encodeFunctionData({
459
462
  abi: ABI.Hub,
460
463
  functionName: 'notifySharePrice',
461
- args: [self.pool.id.raw, self.id.raw, id],
464
+ args: [self.pool.id.raw, self.id.raw, centrifugeId, ctx.signingAddress],
462
465
  }),
463
466
  messages: {
464
- [id]: [MessageType.NotifyPricePoolPerShare],
467
+ [centrifugeId]: [MessageType.NotifyPricePoolPerShare],
465
468
  },
466
469
  });
467
- }, this.pool.chainId);
470
+ }, this.pool.centrifugeId);
468
471
  }
469
472
  /**
470
473
  * Approve deposits and issue shares for the given assets.
@@ -474,20 +477,18 @@ export class ShareClass extends Entity {
474
477
  approveDepositsAndIssueShares(assets) {
475
478
  const self = this;
476
479
  return this._transact(async function* (ctx) {
477
- const [{ hub }, id, pendingAmounts, orders, maxBatchGasLimit] = await Promise.all([
478
- self._root._protocolAddresses(self.pool.chainId),
479
- self._root.id(self.pool.chainId),
480
+ const [{ batchRequestManager }, pendingAmounts, orders] = await Promise.all([
481
+ self._root._protocolAddresses(self.pool.centrifugeId),
480
482
  self.pendingAmounts(),
481
483
  firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
482
484
  if (orders.outstandingInvests.length === 0)
483
485
  return of([]);
484
486
  return combineLatest(orders.outstandingInvests.map((order) => self._investorOrder(order.assetId, order.investor)));
485
487
  }))),
486
- self._root._maxBatchGasLimit(self.pool.chainId),
487
488
  ]);
488
- const assetsWithApprove = assets.filter((a) => a.approveAssetAmount).length;
489
- const assetsWithIssue = assets.filter((a) => a.issuePricePerShare).length;
490
- const gasLimitPerAsset = assetsWithIssue ? maxBatchGasLimit / BigInt(assetsWithIssue) : 0n;
489
+ const assetsWithApprove = assets.filter((a) => 'approveAssetAmount' in a).length;
490
+ const assetsWithIssue = assets.filter((a) => 'issuePricePerShare' in a).length;
491
+ const gasLimitPerAsset = assetsWithIssue ? GAS_LIMIT / BigInt(assetsWithIssue) : 0n;
491
492
  const estimatePerMessage = 700000n;
492
493
  const estimatePerMessageIfLocal = 360000n;
493
494
  const ordersByAssetId = {};
@@ -511,14 +512,14 @@ export class ShareClass extends Entity {
511
512
  messages[centId].push(message);
512
513
  }
513
514
  for (const asset of assets) {
514
- const gasPerMessage = asset.assetId.centrifugeId === id ? estimatePerMessageIfLocal : estimatePerMessage;
515
+ const gasPerMessage = asset.assetId.centrifugeId === self.pool.centrifugeId ? estimatePerMessageIfLocal : estimatePerMessage;
515
516
  let gasLeft = gasLimitPerAsset;
516
517
  const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
517
518
  if (!pending) {
518
519
  throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
519
520
  }
520
521
  let nowDepositEpoch = pending?.depositEpoch;
521
- if (asset.approveAssetAmount) {
522
+ if ('approveAssetAmount' in asset) {
522
523
  if (asset.approveAssetAmount.gt(pending.pendingDeposit)) {
523
524
  throw new Error(`Approve amount exceeds pending amount for asset "${asset.assetId.toString()}"`);
524
525
  }
@@ -526,7 +527,7 @@ export class ShareClass extends Entity {
526
527
  throw new Error(`Approve amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
527
528
  }
528
529
  batch.push(encodeFunctionData({
529
- abi: ABI.Hub,
530
+ abi: ABI.BatchRequestManager,
530
531
  functionName: 'approveDeposits',
531
532
  args: [
532
533
  self.pool.id.raw,
@@ -534,6 +535,8 @@ export class ShareClass extends Entity {
534
535
  asset.assetId.raw,
535
536
  nowDepositEpoch,
536
537
  asset.approveAssetAmount.toBigInt(),
538
+ asset.approvePricePerAsset.toBigInt(),
539
+ ctx.signingAddress,
537
540
  ],
538
541
  }));
539
542
  addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
@@ -541,7 +544,7 @@ export class ShareClass extends Entity {
541
544
  nowDepositEpoch++;
542
545
  }
543
546
  const nowIssueEpoch = pending.issueEpoch;
544
- if (asset.issuePricePerShare) {
547
+ if ('issuePricePerShare' in asset) {
545
548
  if (nowIssueEpoch >= nowDepositEpoch)
546
549
  throw new Error('Nothing to issue');
547
550
  let i;
@@ -555,9 +558,17 @@ export class ShareClass extends Entity {
555
558
  throw new Error(`Issue price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
556
559
  }
557
560
  batch.push(encodeFunctionData({
558
- abi: ABI.Hub,
561
+ abi: ABI.BatchRequestManager,
559
562
  functionName: 'issueShares',
560
- args: [self.pool.id.raw, self.id.raw, asset.assetId.raw, nowIssueEpoch + i, price.toBigInt(), 0n],
563
+ args: [
564
+ self.pool.id.raw,
565
+ self.id.raw,
566
+ asset.assetId.raw,
567
+ nowIssueEpoch + i,
568
+ price.toBigInt(),
569
+ 0n,
570
+ ctx.signingAddress,
571
+ ],
561
572
  }));
562
573
  addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
563
574
  gasLeft -= gasPerMessage;
@@ -569,7 +580,7 @@ export class ShareClass extends Entity {
569
580
  assetOrders?.slice(0, claims).forEach((order) => {
570
581
  if (order.pendingDeposit > 0n) {
571
582
  batch.push(encodeFunctionData({
572
- abi: ABI.Hub,
583
+ abi: ABI.BatchRequestManager,
573
584
  functionName: 'notifyDeposit',
574
585
  args: [
575
586
  self.pool.id.raw,
@@ -577,6 +588,7 @@ export class ShareClass extends Entity {
577
588
  asset.assetId.raw,
578
589
  addressToBytes32(order.investor),
579
590
  order.maxDepositClaims + i, // +i to ensure the additional epochs that are being issued are included
591
+ ctx.signingAddress,
580
592
  ],
581
593
  }));
582
594
  addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
@@ -596,11 +608,11 @@ export class ShareClass extends Entity {
596
608
  title = 'Approve';
597
609
  }
598
610
  yield* wrapTransaction(title, ctx, {
599
- contract: hub,
611
+ contract: batchRequestManager,
600
612
  data: batch,
601
613
  messages,
602
614
  });
603
- }, this.pool.chainId);
615
+ }, this.pool.centrifugeId);
604
616
  }
605
617
  /**
606
618
  * Approve redeems and revoke shares for the given assets.
@@ -610,20 +622,18 @@ export class ShareClass extends Entity {
610
622
  approveRedeemsAndRevokeShares(assets) {
611
623
  const self = this;
612
624
  return this._transact(async function* (ctx) {
613
- const [{ hub }, id, pendingAmounts, orders, maxBatchGasLimit] = await Promise.all([
614
- self._root._protocolAddresses(self.pool.chainId),
615
- self._root.id(self.pool.chainId),
625
+ const [{ batchRequestManager }, pendingAmounts, orders] = await Promise.all([
626
+ self._root._protocolAddresses(self.pool.centrifugeId),
616
627
  self.pendingAmounts(),
617
628
  firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
618
629
  if (orders.outstandingRedeems.length === 0)
619
630
  return of([]);
620
631
  return combineLatest(orders.outstandingRedeems.map((order) => self._investorOrder(order.assetId, order.investor)));
621
632
  }))),
622
- self._root._maxBatchGasLimit(self.pool.chainId),
623
633
  ]);
624
- const assetsWithApprove = assets.filter((a) => a.approveShareAmount).length;
625
- const assetsWithRevoke = assets.filter((a) => a.revokePricePerShare).length;
626
- const gasLimitPerAsset = assetsWithRevoke ? maxBatchGasLimit / BigInt(assetsWithRevoke) : 0n;
634
+ const assetsWithApprove = assets.filter((a) => 'approveShareAmount' in a).length;
635
+ const assetsWithRevoke = assets.filter((a) => 'revokePricePerShare' in a).length;
636
+ const gasLimitPerAsset = assetsWithRevoke ? GAS_LIMIT / BigInt(assetsWithRevoke) : 0n;
627
637
  const estimatePerMessage = 700000n;
628
638
  const estimatePerMessageIfLocal = 360000n;
629
639
  const ordersByAssetId = {};
@@ -647,14 +657,14 @@ export class ShareClass extends Entity {
647
657
  messages[centId].push(message);
648
658
  }
649
659
  for (const asset of assets) {
650
- const gasPerMessage = asset.assetId.centrifugeId === id ? estimatePerMessageIfLocal : estimatePerMessage;
660
+ const gasPerMessage = asset.assetId.centrifugeId === self.pool.centrifugeId ? estimatePerMessageIfLocal : estimatePerMessage;
651
661
  let gasLeft = gasLimitPerAsset;
652
662
  const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
653
663
  if (!pending) {
654
664
  throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
655
665
  }
656
666
  let nowRedeemEpoch = pending.redeemEpoch;
657
- if (asset.approveShareAmount) {
667
+ if ('approveShareAmount' in asset) {
658
668
  if (asset.approveShareAmount.gt(pending.pendingRedeem)) {
659
669
  throw new Error(`Share amount exceeds pending redeem for asset "${asset.assetId.toString()}"`);
660
670
  }
@@ -662,7 +672,7 @@ export class ShareClass extends Entity {
662
672
  throw new Error(`Share amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
663
673
  }
664
674
  batch.push(encodeFunctionData({
665
- abi: ABI.Hub,
675
+ abi: ABI.BatchRequestManager,
666
676
  functionName: 'approveRedeems',
667
677
  args: [
668
678
  self.pool.id.raw,
@@ -670,12 +680,13 @@ export class ShareClass extends Entity {
670
680
  asset.assetId.raw,
671
681
  nowRedeemEpoch,
672
682
  asset.approveShareAmount.toBigInt(),
683
+ asset.approvePricePerAsset.toBigInt(),
673
684
  ],
674
685
  }));
675
686
  nowRedeemEpoch++;
676
687
  }
677
688
  const nowRevokeEpoch = pending.revokeEpoch;
678
- if (asset.revokePricePerShare) {
689
+ if ('revokePricePerShare' in asset) {
679
690
  if (nowRevokeEpoch >= nowRedeemEpoch)
680
691
  throw new Error('Nothing to revoke');
681
692
  let i;
@@ -689,9 +700,17 @@ export class ShareClass extends Entity {
689
700
  throw new Error(`Revoke price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
690
701
  }
691
702
  batch.push(encodeFunctionData({
692
- abi: ABI.Hub,
703
+ abi: ABI.BatchRequestManager,
693
704
  functionName: 'revokeShares',
694
- args: [self.pool.id.raw, self.id.raw, asset.assetId.raw, nowRevokeEpoch + i, price.toBigInt(), 0n],
705
+ args: [
706
+ self.pool.id.raw,
707
+ self.id.raw,
708
+ asset.assetId.raw,
709
+ nowRevokeEpoch + i,
710
+ price.toBigInt(),
711
+ 0n,
712
+ ctx.signingAddress,
713
+ ],
695
714
  }));
696
715
  addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
697
716
  gasLeft -= gasPerMessage;
@@ -703,7 +722,7 @@ export class ShareClass extends Entity {
703
722
  assetOrders?.slice(0, claims).forEach((order) => {
704
723
  if (order.pendingRedeem > 0n) {
705
724
  batch.push(encodeFunctionData({
706
- abi: ABI.Hub,
725
+ abi: ABI.BatchRequestManager,
707
726
  functionName: 'notifyRedeem',
708
727
  args: [
709
728
  self.pool.id.raw,
@@ -711,6 +730,7 @@ export class ShareClass extends Entity {
711
730
  asset.assetId.raw,
712
731
  addressToBytes32(order.investor),
713
732
  order.maxRedeemClaims + 1, // +1 to ensure the order that's being issued is included
733
+ ctx.signingAddress,
714
734
  ],
715
735
  }));
716
736
  addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
@@ -730,11 +750,11 @@ export class ShareClass extends Entity {
730
750
  title = 'Approve';
731
751
  }
732
752
  yield* wrapTransaction(title, ctx, {
733
- contract: hub,
753
+ contract: batchRequestManager,
734
754
  data: batch,
735
755
  messages,
736
756
  });
737
- }, this.pool.chainId);
757
+ }, this.pool.centrifugeId);
738
758
  }
739
759
  /**
740
760
  * Claim a deposit on the Hub side for the given asset and investor after the shares have been issued.
@@ -743,14 +763,14 @@ export class ShareClass extends Entity {
743
763
  claimDeposit(assetId, investor) {
744
764
  const self = this;
745
765
  return this._transact(async function* (ctx) {
746
- const [{ hub }, investorOrder] = await Promise.all([
747
- self._root._protocolAddresses(self.pool.chainId),
766
+ const [{ batchRequestManager }, investorOrder] = await Promise.all([
767
+ self._root._protocolAddresses(self.pool.centrifugeId),
748
768
  self._investorOrder(assetId, investor),
749
769
  ]);
750
770
  yield* wrapTransaction('Claim deposit', ctx, {
751
- contract: hub,
771
+ contract: batchRequestManager,
752
772
  data: encodeFunctionData({
753
- abi: ABI.Hub,
773
+ abi: ABI.BatchRequestManager,
754
774
  functionName: 'notifyDeposit',
755
775
  args: [
756
776
  self.pool.id.raw,
@@ -758,11 +778,12 @@ export class ShareClass extends Entity {
758
778
  assetId.raw,
759
779
  addressToBytes32(investor),
760
780
  investorOrder.maxDepositClaims,
781
+ ctx.signingAddress,
761
782
  ],
762
783
  }),
763
784
  messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
764
785
  });
765
- }, this.pool.chainId);
786
+ }, this.pool.centrifugeId);
766
787
  }
767
788
  /**
768
789
  * Claim a redemption on the Hub side for the given asset and investor after the shares have been revoked.
@@ -771,44 +792,48 @@ export class ShareClass extends Entity {
771
792
  claimRedeem(assetId, investor) {
772
793
  const self = this;
773
794
  return this._transact(async function* (ctx) {
774
- const [{ hub }, investorOrder] = await Promise.all([
775
- self._root._protocolAddresses(self.pool.chainId),
795
+ const [{ batchRequestManager }, investorOrder] = await Promise.all([
796
+ self._root._protocolAddresses(self.pool.centrifugeId),
776
797
  self._investorOrder(assetId, investor),
777
798
  ]);
778
799
  yield* wrapTransaction('Claim redeem', ctx, {
779
- contract: hub,
800
+ contract: batchRequestManager,
780
801
  data: encodeFunctionData({
781
- abi: ABI.Hub,
802
+ abi: ABI.BatchRequestManager,
782
803
  functionName: 'notifyRedeem',
783
- args: [self.pool.id.raw, self.id.raw, assetId.raw, addressToBytes32(investor), investorOrder.maxRedeemClaims],
804
+ args: [
805
+ self.pool.id.raw,
806
+ self.id.raw,
807
+ assetId.raw,
808
+ addressToBytes32(investor),
809
+ investorOrder.maxRedeemClaims,
810
+ ctx.signingAddress,
811
+ ],
784
812
  }),
785
813
  messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
786
814
  });
787
- }, this.pool.chainId);
815
+ }, this.pool.centrifugeId);
788
816
  }
789
817
  /**
790
818
  * Update a member of the share class.
791
819
  * @param address Address of the investor
792
820
  * @param validUntil Time in seconds from Unix epoch until the investor is valid
793
- * @param chainId Chain ID of the network on which to update the member
821
+ * @param centrifugeId Centrifuge ID of the network on which to update the member
794
822
  */
795
- updateMember(address, validUntil, chainId) {
796
- return this.updateMembers([{ address, validUntil, chainId }]);
823
+ updateMember(address, validUntil, centrifugeId) {
824
+ return this.updateMembers([{ address, validUntil, centrifugeId }]);
797
825
  }
798
826
  /**
799
827
  * Batch update a list of members of the share class.
800
- * @param members Array of members to update, each with address, validUntil and chainId
828
+ * @param members Array of members to update, each with address, validUntil and centrifugeId
801
829
  * @param members.address Address of the investor
802
830
  * @param members.validUntil Time in seconds from Unix epoch until the investor is valid
803
- * @param members.chainId Chain ID of the network on which to update the member
831
+ * @param members.centrifugeId Centrifuge ID of the network on which to update the member
804
832
  */
805
833
  updateMembers(members) {
806
834
  const self = this;
807
835
  return this._transact(async function* (ctx) {
808
- const [{ hub }, ...ids] = await Promise.all([
809
- self._root._protocolAddresses(self.pool.chainId),
810
- ...members.map((m) => self._root.id(m.chainId)),
811
- ]);
836
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
812
837
  const batch = [];
813
838
  const messages = {};
814
839
  function addMessage(centId, message) {
@@ -816,23 +841,20 @@ export class ShareClass extends Entity {
816
841
  messages[centId] = [];
817
842
  messages[centId].push(message);
818
843
  }
819
- members.forEach((member, index) => {
820
- const id = ids[index];
821
- if (!id) {
822
- return;
823
- }
844
+ members.forEach((member) => {
824
845
  batch.push(encodeFunctionData({
825
846
  abi: ABI.Hub,
826
847
  functionName: 'updateRestriction',
827
848
  args: [
828
849
  self.pool.id.raw,
829
850
  self.id.raw,
830
- id,
851
+ member.centrifugeId,
831
852
  encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(member.address), BigInt(member.validUntil)]),
832
853
  0n,
854
+ ctx.signingAddress,
833
855
  ],
834
856
  }));
835
- addMessage(id, MessageType.UpdateRestriction);
857
+ addMessage(member.centrifugeId, MessageType.UpdateRestriction);
836
858
  });
837
859
  if (batch.length === 0) {
838
860
  throw new Error('No data to update members');
@@ -842,7 +864,7 @@ export class ShareClass extends Entity {
842
864
  data: batch,
843
865
  messages,
844
866
  });
845
- }, this.pool.chainId);
867
+ }, this.pool.centrifugeId);
846
868
  }
847
869
  /**
848
870
  * Retrieve all holders of the share class.
@@ -873,11 +895,10 @@ export class ShareClass extends Entity {
873
895
  orderBy,
874
896
  orderDirection,
875
897
  ], () => combineLatest([
876
- this._root._deployments(),
877
898
  this.pool.currency(),
878
899
  this._investorOrders(),
879
900
  this._tokenInstancePositions({ limit, offset, orderBy, orderDirection, filter }),
880
- ]).pipe(switchMap(([deployments, poolCurrency, { outstandingInvests, outstandingRedeems }, { items: tokenInstancePositions, assets, pageInfo, totalCount },]) => {
901
+ ]).pipe(switchMap(([poolCurrency, { outstandingInvests, outstandingRedeems }, { items: tokenInstancePositions, assets, pageInfo, totalCount },]) => {
881
902
  // Handle empty positions case or else combineLatest([]) can hang indefinitely
882
903
  if (tokenInstancePositions.length === 0) {
883
904
  return of({
@@ -891,11 +912,10 @@ export class ShareClass extends Entity {
891
912
  centrifugeId: position.centrifugeId,
892
913
  tokenId: this.id.raw,
893
914
  }).pipe(catchError(() => of(null))));
894
- const chainsById = new Map(deployments.blockchains.items.map((chain) => [chain.centrifugeId, chain.id]));
895
915
  return combineLatest(whitelistedQueries).pipe(map((whitelistResults) => {
896
916
  const investors = tokenInstancePositions.map((position, i) => {
897
917
  const whitelistData = whitelistResults[i];
898
- const chainId = Number(chainsById.get(position.centrifugeId));
918
+ const centrifugeId = Number(position.centrifugeId);
899
919
  const outstandingInvest = outstandingInvests.find((order) => order.investor === position.accountAddress);
900
920
  const outstandingRedeem = outstandingRedeems.find((order) => order.investor === position.accountAddress);
901
921
  const assetId = outstandingInvest?.assetId.toString();
@@ -906,7 +926,7 @@ export class ShareClass extends Entity {
906
926
  return {
907
927
  address: position.accountAddress,
908
928
  amount: new Balance(outstandingInvest?.pendingAmount ?? 0n, assetDecimals),
909
- chainId,
929
+ centrifugeId,
910
930
  createdAt: whitelistData?.createdAt ?? '',
911
931
  holdings: new Balance(position.balance, poolCurrency.decimals),
912
932
  isFrozen: whitelistData?.isFrozen ?? position.isFrozen,
@@ -947,12 +967,7 @@ export class ShareClass extends Entity {
947
967
  whitelistedHolders(options) {
948
968
  const limit = options?.limit ?? 20;
949
969
  const offset = options?.offset ?? 0;
950
- return this._query(['whitelistedHolders', this.id.raw, limit, offset], () => combineLatest([
951
- this._root._deployments(),
952
- this.pool.currency(),
953
- this._investorOrders(),
954
- this._whitelistedInvestors({ limit, offset }),
955
- ]).pipe(switchMap(([deployments, poolCurrency, { outstandingInvests, outstandingRedeems }, { items: whitelistedInvestors, assets, pageInfo, totalCount },]) => {
970
+ return this._query(['whitelistedHolders', this.id.raw, limit, offset], () => combineLatest([this.pool.currency(), this._investorOrders(), this._whitelistedInvestors({ limit, offset })]).pipe(switchMap(([poolCurrency, { outstandingInvests, outstandingRedeems }, { items: whitelistedInvestors, assets, pageInfo, totalCount },]) => {
956
971
  if (whitelistedInvestors.length === 0) {
957
972
  return of({
958
973
  investors: [],
@@ -965,11 +980,9 @@ export class ShareClass extends Entity {
965
980
  centrifugeId: investor.centrifugeId,
966
981
  tokenId: this.id.raw,
967
982
  }).pipe(catchError(() => of(null))));
968
- const chainsById = new Map(deployments.blockchains.items.map((chain) => [chain.centrifugeId, chain.id]));
969
983
  return combineLatest(positionQueries).pipe(map((positionResults) => {
970
984
  const investors = whitelistedInvestors.map((investor, i) => {
971
985
  const positionData = positionResults[i];
972
- const chainId = Number(chainsById.get(investor.centrifugeId));
973
986
  const outstandingInvest = outstandingInvests.find((order) => order.investor === investor.address);
974
987
  const outstandingRedeem = outstandingRedeems.find((order) => order.investor === investor.address);
975
988
  const assetId = outstandingInvest?.assetId.toString();
@@ -979,7 +992,7 @@ export class ShareClass extends Entity {
979
992
  return {
980
993
  address: investor.address,
981
994
  amount: new Balance(outstandingInvest?.pendingAmount ?? 0n, assetDecimals),
982
- chainId,
995
+ centrifugeId: Number(investor.centrifugeId),
983
996
  createdAt: investor.createdAt,
984
997
  holdings: new Balance(positionBalance, poolCurrency.decimals),
985
998
  isFrozen: investor.isFrozen ?? positionData?.isFrozen,
@@ -1040,13 +1053,15 @@ export class ShareClass extends Entity {
1040
1053
  }
1041
1054
  /**
1042
1055
  * Freeze a member of the share class.
1056
+ * @param address Address to freeze
1057
+ * @param centrifugeId Centrifuge ID of the network on which to freeze the member
1043
1058
  */
1044
- freezeMember(address, chainId) {
1059
+ freezeMember(address, centrifugeId) {
1045
1060
  const self = this;
1046
1061
  return this._transact(async function* (ctx) {
1047
1062
  const [share, restrictionManager] = await Promise.all([
1048
- firstValueFrom(self._share(chainId)),
1049
- firstValueFrom(self._restrictionManager(chainId)),
1063
+ firstValueFrom(self._share(centrifugeId)),
1064
+ firstValueFrom(self._restrictionManager(centrifugeId)),
1050
1065
  ]);
1051
1066
  yield* wrapTransaction('Freeze member', ctx, {
1052
1067
  contract: restrictionManager,
@@ -1056,17 +1071,19 @@ export class ShareClass extends Entity {
1056
1071
  args: [share, address],
1057
1072
  }),
1058
1073
  });
1059
- }, chainId);
1074
+ }, centrifugeId);
1060
1075
  }
1061
1076
  /**
1062
1077
  * Unfreeze a member of the share class
1078
+ * @param address Address to unfreeze
1079
+ * @param centrifugeId Centrifuge ID of the network on which to unfreeze the member
1063
1080
  */
1064
- unfreezeMember(address, chainId) {
1081
+ unfreezeMember(address, centrifugeId) {
1065
1082
  const self = this;
1066
1083
  return this._transact(async function* (ctx) {
1067
1084
  const [share, restrictionManager] = await Promise.all([
1068
- firstValueFrom(self._share(chainId)),
1069
- firstValueFrom(self._restrictionManager(chainId)),
1085
+ firstValueFrom(self._share(centrifugeId)),
1086
+ firstValueFrom(self._restrictionManager(centrifugeId)),
1070
1087
  ]);
1071
1088
  yield* wrapTransaction('Unfreeze member', ctx, {
1072
1089
  contract: restrictionManager,
@@ -1076,14 +1093,14 @@ export class ShareClass extends Entity {
1076
1093
  args: [share, address],
1077
1094
  }),
1078
1095
  });
1079
- }, chainId);
1096
+ }, centrifugeId);
1080
1097
  }
1081
1098
  /**
1082
1099
  * Get the pending and claimable investment/redeem amounts for all investors
1083
1100
  * in a given share class (per vault/chain)
1084
1101
  */
1085
- investmentsByVault(chainId) {
1086
- return this._query(['investmentsByVault', chainId], () => combineLatest([this._investorOrders(), this.vaults(chainId), this.pendingAmounts()]).pipe(switchMap(([orders, vaults, pendingAmounts]) => {
1102
+ investmentsByVault(centrifugeId) {
1103
+ return this._query(['investmentsByVault', centrifugeId], () => combineLatest([this._investorOrders(), this.vaults(centrifugeId), this.pendingAmounts()]).pipe(switchMap(([orders, vaults, pendingAmounts]) => {
1087
1104
  if (!vaults.length)
1088
1105
  return of([]);
1089
1106
  const allInvestors = new Set();
@@ -1101,25 +1118,25 @@ export class ShareClass extends Entity {
1101
1118
  .forEach((o) => vaultInvestors.add(o.investor));
1102
1119
  if (vaultInvestors.size === 0)
1103
1120
  return of([]);
1104
- const pendingMatch = pendingAmounts.find((p) => p.assetId.equals(vault.assetId) && p.chainId === vault.chainId);
1121
+ const pendingMatch = pendingAmounts.find((p) => p.assetId.equals(vault.assetId) && p.centrifugeId === vault.centrifugeId);
1105
1122
  const allPendingIssuances = pendingMatch?.pendingIssuances ?? [];
1106
1123
  const allPendingRevocations = pendingMatch?.pendingRevocations ?? [];
1107
1124
  return combineLatest(Array.from(vaultInvestors).map((investor) => vault.investment(investor).pipe(map((investment) => {
1108
1125
  const pendingIssuances = allPendingIssuances.map((epoch) => ({
1109
1126
  ...epoch,
1110
1127
  assetId: vault.assetId,
1111
- chainId: vault.chainId,
1128
+ centrifugeId: vault.centrifugeId,
1112
1129
  }));
1113
1130
  const pendingRevocations = allPendingRevocations.map((epoch) => ({
1114
1131
  ...epoch,
1115
1132
  assetId: vault.assetId,
1116
- chainId: vault.chainId,
1133
+ centrifugeId: vault.centrifugeId,
1117
1134
  }));
1118
1135
  return {
1119
1136
  investor,
1120
1137
  investment,
1121
1138
  assetId: vault.assetId,
1122
- chainId: vault.chainId,
1139
+ centrifugeId: vault.centrifugeId,
1123
1140
  pendingIssuances,
1124
1141
  pendingRevocations,
1125
1142
  pendingMatch,
@@ -1128,7 +1145,7 @@ export class ShareClass extends Entity {
1128
1145
  investor,
1129
1146
  investment: null,
1130
1147
  assetId: vault.assetId,
1131
- chainId: vault.chainId,
1148
+ centrifugeId: vault.centrifugeId,
1132
1149
  pendingIssuances: [],
1133
1150
  pendingRevocations: [],
1134
1151
  pendingMatch: null,
@@ -1169,7 +1186,7 @@ export class ShareClass extends Entity {
1169
1186
  expandedRecords.push({
1170
1187
  investor: inv.investor,
1171
1188
  assetId: inv.assetId,
1172
- chainId: inv.chainId,
1189
+ centrifugeId: inv.centrifugeId,
1173
1190
  epoch: inv.pendingMatch.depositEpoch,
1174
1191
  epochType: 'deposit',
1175
1192
  investorAmount,
@@ -1188,7 +1205,7 @@ export class ShareClass extends Entity {
1188
1205
  expandedRecords.push({
1189
1206
  investor: inv.investor,
1190
1207
  assetId: inv.assetId,
1191
- chainId: inv.chainId,
1208
+ centrifugeId: inv.centrifugeId,
1192
1209
  epoch: issuance.epoch,
1193
1210
  epochType: 'issue',
1194
1211
  investorAmount,
@@ -1207,7 +1224,7 @@ export class ShareClass extends Entity {
1207
1224
  expandedRecords.push({
1208
1225
  investor: inv.investor,
1209
1226
  assetId: inv.assetId,
1210
- chainId: inv.chainId,
1227
+ centrifugeId: inv.centrifugeId,
1211
1228
  epoch: inv.pendingMatch.redeemEpoch,
1212
1229
  epochType: 'redeem',
1213
1230
  investorAmount,
@@ -1226,7 +1243,7 @@ export class ShareClass extends Entity {
1226
1243
  expandedRecords.push({
1227
1244
  investor: inv.investor,
1228
1245
  assetId: inv.assetId,
1229
- chainId: inv.chainId,
1246
+ centrifugeId: inv.centrifugeId,
1230
1247
  epoch: revocation.epoch,
1231
1248
  epochType: 'revoke',
1232
1249
  investorAmount,
@@ -1265,15 +1282,10 @@ export class ShareClass extends Entity {
1265
1282
  decimals
1266
1283
  symbol
1267
1284
  name
1268
- blockchain {
1269
- chainId
1270
- }
1285
+ centrifugeId
1271
1286
  }
1272
1287
  token {
1273
1288
  decimals
1274
- blockchain {
1275
- chainId
1276
- }
1277
1289
  }
1278
1290
  }
1279
1291
  }
@@ -1305,14 +1317,10 @@ export class ShareClass extends Entity {
1305
1317
  decimals
1306
1318
  symbol
1307
1319
  name
1308
- blockchain {
1309
- chainId
1310
- }
1320
+ centrifugeId
1311
1321
  }
1312
1322
  token {
1313
1323
  decimals
1314
- blockchain {
1315
- chainId
1316
1324
  }
1317
1325
  }
1318
1326
  }
@@ -1398,15 +1406,10 @@ export class ShareClass extends Entity {
1398
1406
  decimals
1399
1407
  symbol
1400
1408
  name
1401
- blockchain {
1402
- chainId
1403
- }
1409
+ centrifugeId
1404
1410
  }
1405
1411
  token {
1406
1412
  decimals
1407
- blockchain {
1408
- chainId
1409
- }
1410
1413
  }
1411
1414
  }
1412
1415
  }
@@ -1438,15 +1441,10 @@ export class ShareClass extends Entity {
1438
1441
  decimals
1439
1442
  symbol
1440
1443
  name
1441
- blockchain {
1442
- chainId
1443
- }
1444
+ centrifugeId
1444
1445
  }
1445
1446
  token {
1446
1447
  decimals
1447
- blockchain {
1448
- chainId
1449
- }
1450
1448
  }
1451
1449
  }
1452
1450
  }
@@ -1511,13 +1509,13 @@ export class ShareClass extends Entity {
1511
1509
  }
1512
1510
  /**
1513
1511
  * Get the valuation contract address for this share class on a specific chain.
1514
- * @param chainId
1512
+ * @param centrifugeId
1515
1513
  */
1516
- valuation(chainId) {
1517
- return this._query(['valuation', chainId], () => this._root._protocolAddresses(chainId).pipe(switchMap(({ syncManager }) => defer(async () => {
1518
- const valuation = await this._root.getClient(chainId).readContract({
1514
+ valuation(centrifugeId) {
1515
+ return this._query(['valuation', centrifugeId], () => combineLatest([this._root._protocolAddresses(centrifugeId), this._root.getClient(centrifugeId)]).pipe(switchMap(([{ syncManager }, client]) => defer(async () => {
1516
+ const valuation = await client.readContract({
1519
1517
  address: syncManager,
1520
- abi: ABI.SyncRequests,
1518
+ abi: ABI.SyncManager,
1521
1519
  functionName: 'valuation',
1522
1520
  args: [this.pool.id.raw, this.id.raw],
1523
1521
  });
@@ -1526,20 +1524,19 @@ export class ShareClass extends Entity {
1526
1524
  address: syncManager,
1527
1525
  eventName: ['SetValuation'],
1528
1526
  filter: (events) => events.some((event) => event.args.poolId === this.pool.id.raw && event.args.scId === this.id.raw),
1529
- }, chainId)))));
1527
+ }, centrifugeId)))));
1530
1528
  }
1531
1529
  /**
1532
1530
  * Set the default valuation contract for this share class on a specific chain.
1533
- * @param chainId - The chain ID where the valuation should be updated
1531
+ * @param centrifugeId - The centrifuge ID where the valuation should be updated
1534
1532
  * @param valuation - The address of the valuation contract
1535
1533
  */
1536
- updateValuation(chainId, valuation) {
1534
+ updateValuation(centrifugeId, valuation) {
1537
1535
  const self = this;
1538
1536
  return this._transact(async function* (ctx) {
1539
- const [id, { hub }, spokeAddresses] = await Promise.all([
1540
- self._root.id(chainId),
1541
- self._root._protocolAddresses(self.pool.chainId),
1542
- self._root._protocolAddresses(chainId),
1537
+ const [{ hub }, spokeAddresses] = await Promise.all([
1538
+ self._root._protocolAddresses(self.pool.centrifugeId),
1539
+ self._root._protocolAddresses(centrifugeId),
1543
1540
  ]);
1544
1541
  yield* wrapTransaction('Update valuation', ctx, {
1545
1542
  contract: hub,
@@ -1549,55 +1546,52 @@ export class ShareClass extends Entity {
1549
1546
  args: [
1550
1547
  self.pool.id.raw,
1551
1548
  self.id.raw,
1552
- id,
1549
+ centrifugeId,
1553
1550
  addressToBytes32(spokeAddresses.syncManager),
1554
- encodePacked(['uint8', 'bytes32'], [/* UpdateContractType.Valuation */ 1, addressToBytes32(valuation)]),
1551
+ encode([VaultManagerTrustedCall.Valuation, addressToBytes32(valuation)]),
1555
1552
  0n,
1553
+ ctx.signingAddress,
1556
1554
  ],
1557
1555
  }),
1558
- messages: { [id]: [MessageType.UpdateContract] },
1556
+ messages: { [centrifugeId]: [MessageType.TrustedContractUpdate] },
1559
1557
  });
1560
- }, this.pool.chainId);
1558
+ }, this.pool.centrifugeId);
1561
1559
  }
1562
1560
  /**
1563
1561
  * Update the hook for this share class on a specific chain.
1564
- * @param chainId - The chain ID where the hook should be updated
1562
+ * @param centrifugeId - The centrifuge ID where the hook should be updated
1565
1563
  * @param hook - The address of the new hook contract
1566
1564
  */
1567
- updateHook(chainId, hook) {
1565
+ updateHook(centrifugeId, hook) {
1568
1566
  const self = this;
1569
1567
  return this._transact(async function* (ctx) {
1570
- const [id, { hub }] = await Promise.all([
1571
- self._root.id(chainId),
1572
- self._root._protocolAddresses(self.pool.chainId),
1573
- ]);
1568
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
1574
1569
  yield* wrapTransaction('Update hook', ctx, {
1575
1570
  contract: hub,
1576
1571
  data: encodeFunctionData({
1577
1572
  abi: ABI.Hub,
1578
1573
  functionName: 'updateShareHook',
1579
- args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(hook)],
1574
+ args: [self.pool.id.raw, self.id.raw, centrifugeId, addressToBytes32(hook), ctx.signingAddress],
1580
1575
  }),
1581
- messages: { [id]: [MessageType.UpdateShareHook] },
1576
+ messages: { [centrifugeId]: [MessageType.UpdateShareHook] },
1582
1577
  });
1583
- }, this.pool.chainId);
1578
+ }, this.pool.centrifugeId);
1584
1579
  }
1585
1580
  /**
1586
1581
  * Update both (or one of) the hook and valuation for this share class on a specific chain in a single transaction.
1587
- * @param chainId - The chain ID where the updates should be applied
1582
+ * @param centrifugeId - The centrifuge ID where the updates should be applied
1588
1583
  * @param hook - The address of the new hook contract (optional)
1589
1584
  * @param valuation - The address of the new valuation contract (optional)
1590
1585
  */
1591
- updateHookAndValuation(chainId, hook, valuation) {
1586
+ updateHookAndValuation(centrifugeId, hook, valuation) {
1592
1587
  if (!hook && !valuation) {
1593
1588
  throw new Error('At least one of hook or valuation must be provided');
1594
1589
  }
1595
1590
  const self = this;
1596
1591
  return this._transact(async function* (ctx) {
1597
- const [id, { hub }, spokeAddresses] = await Promise.all([
1598
- self._root.id(chainId),
1599
- self._root._protocolAddresses(self.pool.chainId),
1600
- self._root._protocolAddresses(chainId),
1592
+ const [{ hub }, spokeAddresses] = await Promise.all([
1593
+ self._root._protocolAddresses(self.pool.centrifugeId),
1594
+ self._root._protocolAddresses(centrifugeId),
1601
1595
  ]);
1602
1596
  const calls = [];
1603
1597
  const messages = [];
@@ -1605,7 +1599,7 @@ export class ShareClass extends Entity {
1605
1599
  calls.push(encodeFunctionData({
1606
1600
  abi: ABI.Hub,
1607
1601
  functionName: 'updateShareHook',
1608
- args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(hook)],
1602
+ args: [self.pool.id.raw, self.id.raw, centrifugeId, addressToBytes32(hook), ctx.signingAddress],
1609
1603
  }));
1610
1604
  messages.push(MessageType.UpdateShareHook);
1611
1605
  }
@@ -1616,21 +1610,22 @@ export class ShareClass extends Entity {
1616
1610
  args: [
1617
1611
  self.pool.id.raw,
1618
1612
  self.id.raw,
1619
- id,
1613
+ centrifugeId,
1620
1614
  addressToBytes32(spokeAddresses.syncManager),
1621
1615
  encodePacked(['uint8', 'bytes32'], [/* UpdateContractType.Valuation */ 1, addressToBytes32(valuation)]),
1622
1616
  0n,
1617
+ ctx.signingAddress,
1623
1618
  ],
1624
1619
  }));
1625
- messages.push(MessageType.UpdateContract);
1620
+ messages.push(MessageType.TrustedContractUpdate);
1626
1621
  }
1627
1622
  const title = hook && valuation ? 'Update hook and valuation' : hook ? 'Update hook' : 'Update valuation';
1628
1623
  yield* wrapTransaction(title, ctx, {
1629
1624
  contract: hub,
1630
1625
  data: calls,
1631
- messages: { [id]: messages },
1626
+ messages: { [centrifugeId]: messages },
1632
1627
  });
1633
- }, this.pool.chainId);
1628
+ }, this.pool.centrifugeId);
1634
1629
  }
1635
1630
  /** @internal */
1636
1631
  _balances() {
@@ -1643,6 +1638,7 @@ export class ShareClass extends Entity {
1643
1638
  assetAmount
1644
1639
  assetPrice
1645
1640
  assetId
1641
+ centrifugeId
1646
1642
  asset {
1647
1643
  decimals
1648
1644
  assetTokenId
@@ -1651,6 +1647,7 @@ export class ShareClass extends Entity {
1651
1647
  symbol
1652
1648
  blockchain {
1653
1649
  id
1650
+ centrifugeId
1654
1651
  }
1655
1652
  }
1656
1653
  }
@@ -1662,14 +1659,15 @@ export class ShareClass extends Entity {
1662
1659
  /** @internal */
1663
1660
  _holding(assetId) {
1664
1661
  return this._query(['holding', assetId.toString()], () => combineLatest([
1665
- this._root._protocolAddresses(this.pool.chainId),
1662
+ this._root._protocolAddresses(this.pool.centrifugeId),
1666
1663
  this.pool.currency(),
1667
- this._root._assetDecimals(assetId, this.pool.chainId),
1664
+ this._root._assetDecimals(assetId, this.pool.centrifugeId),
1668
1665
  ]).pipe(switchMap(([{ holdings: holdingsAddr }, poolCurrency, assetDecimals]) => defer(async () => {
1666
+ const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
1669
1667
  const holdings = getContract({
1670
1668
  address: holdingsAddr,
1671
1669
  abi: ABI.Holdings,
1672
- client: this._root.getClient(this.pool.chainId),
1670
+ client,
1673
1671
  });
1674
1672
  const [valuation, amount, value, isLiability, ...accounts] = await Promise.all([
1675
1673
  holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
@@ -1709,12 +1707,15 @@ export class ShareClass extends Entity {
1709
1707
  return event.args.scId === this.id && event.args.assetId === assetId.raw;
1710
1708
  });
1711
1709
  },
1712
- }, this.pool.chainId)))));
1710
+ }, this.pool.centrifugeId)))));
1713
1711
  }
1714
1712
  /** @internal */
1715
- _balance(chainId, asset) {
1716
- return this._query(['balance', asset.id.toString()], () => combineLatest([this._root._protocolAddresses(chainId), this.pool.currency()]).pipe(switchMap(([addresses, poolCurrency]) => defer(async () => {
1717
- const client = this._root.getClient(chainId);
1713
+ _balance(centrifugeId, asset) {
1714
+ return this._query(['balance', asset.id.toString()], () => combineLatest([
1715
+ this._root._protocolAddresses(centrifugeId),
1716
+ this.pool.currency(),
1717
+ this._root.getClient(centrifugeId),
1718
+ ]).pipe(switchMap(([addresses, poolCurrency, client]) => defer(async () => {
1718
1719
  const [amountBn, priceBn] = await Promise.all([
1719
1720
  client.readContract({
1720
1721
  address: addresses.balanceSheet,
@@ -1747,53 +1748,106 @@ export class ShareClass extends Entity {
1747
1748
  // NoteDeposit, Deposit, Withdraw events
1748
1749
  event.args.asset?.toLowerCase() === asset.address?.toLowerCase()));
1749
1750
  },
1750
- }, chainId)))));
1751
+ }, centrifugeId)))));
1751
1752
  }
1752
1753
  /** @internal */
1753
1754
  _investorOrders() {
1754
1755
  return this._root._queryIndexer(`query ($scId: String!) {
1755
- outstandingInvests(where: {tokenId: $scId}) {
1756
+ investOrders(where: {tokenId: $scId}) {
1756
1757
  items {
1757
- investor: account
1758
+ account
1758
1759
  assetId
1759
- queuedAmount
1760
- depositAmount
1761
- pendingAmount
1760
+ tokenId
1761
+ approvedAssetsAmount
1762
+ approvedAt
1763
+ claimedSharesAmount
1764
+ claimedAt
1765
+ issuedSharesAmount
1766
+ issuedAt
1767
+ pendingAssetsAmount
1768
+ postedAt
1769
+ queuedAssetsAmount
1762
1770
  }
1763
1771
  }
1764
- outstandingRedeems(where: {tokenId: $scId}) {
1772
+ redeemOrders(where: {tokenId: $scId}) {
1765
1773
  items {
1774
+ account
1766
1775
  assetId
1767
- investor: account
1768
- queuedAmount
1769
- depositAmount
1770
- pendingAmount
1776
+ tokenId
1777
+ approvedSharesAmount
1778
+ approvedAt
1779
+ claimedAssetsAmount
1780
+ claimedAt
1781
+ pendingSharesAmount
1782
+ postedAt
1783
+ revokedSharesAmount
1784
+ revokedAssetsAmount
1785
+ revokedPoolAmount
1786
+ revokedAt
1787
+ queuedSharesAmount
1771
1788
  }
1772
1789
  }
1773
1790
  }`, { scId: this.id.raw }, (data) => ({
1774
- outstandingInvests: data.outstandingInvests.items.map((item) => ({
1791
+ investOrders: data.investOrders.items.map((item) => ({
1775
1792
  ...item,
1776
1793
  assetId: new AssetId(item.assetId),
1794
+ account: item.account.toLowerCase(),
1795
+ investor: item.account.toLowerCase(),
1796
+ tokenId: item.tokenId.toLowerCase(),
1797
+ })),
1798
+ outstandingInvests: data.investOrders.items.map((item) => ({
1799
+ assetId: new AssetId(item.assetId),
1800
+ account: item.account.toLowerCase(),
1801
+ investor: item.account.toLowerCase(),
1802
+ tokenId: item.tokenId.toLowerCase(),
1803
+ pendingAmount: item.pendingAssetsAmount,
1804
+ queuedAmount: item.queuedAssetsAmount,
1777
1805
  })),
1778
- outstandingRedeems: data.outstandingRedeems.items.map((item) => ({
1806
+ redeemOrders: data.redeemOrders.items.map((item) => ({
1779
1807
  ...item,
1780
1808
  assetId: new AssetId(item.assetId),
1809
+ account: item.account.toLowerCase(),
1810
+ investor: item.account.toLowerCase(),
1811
+ tokenId: item.tokenId.toLowerCase(),
1812
+ })),
1813
+ outstandingRedeems: data.redeemOrders.items.map((item) => ({
1814
+ assetId: new AssetId(item.assetId),
1815
+ account: item.account.toLowerCase(),
1816
+ investor: item.account.toLowerCase(),
1817
+ tokenId: item.tokenId.toLowerCase(),
1818
+ pendingAmount: item.pendingSharesAmount,
1819
+ queuedAmount: item.queuedSharesAmount,
1781
1820
  })),
1782
1821
  }));
1783
1822
  }
1784
1823
  /** @internal */
1785
1824
  _investorOrder(assetId, investor) {
1786
- return this._query(['investorOrder', assetId.toString(), investor.toLowerCase()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1825
+ return this._query(['investorOrder', assetId.toString(), investor.toLowerCase()], () => combineLatest([
1826
+ this._root._protocolAddresses(this.pool.centrifugeId),
1827
+ this._root.getClient(this.pool.centrifugeId),
1828
+ ]).pipe(switchMap(([{ batchRequestManager }, client]) => defer(async () => {
1787
1829
  const contract = getContract({
1788
- address: shareClassManager,
1789
- abi: ABI.ShareClassManager,
1790
- client: this._root.getClient(this.pool.chainId),
1830
+ address: batchRequestManager,
1831
+ abi: ABI.BatchRequestManager,
1832
+ client,
1791
1833
  });
1792
- const [maxDepositClaims, maxRedeemClaims, [pendingDeposit], [pendingRedeem]] = await Promise.all([
1793
- contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
1794
- contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
1795
- contract.read.depositRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
1796
- contract.read.redeemRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
1834
+ const [maxDepositClaims, maxRedeemClaims, [pendingDeposit], [pendingRedeem], [, queuedInvest], [, queuedRedeem],] = await Promise.all([
1835
+ contract.read.maxDepositClaims([this.pool.id.raw, this.id.raw, addressToBytes32(investor), assetId.raw]),
1836
+ contract.read.maxRedeemClaims([this.pool.id.raw, this.id.raw, addressToBytes32(investor), assetId.raw]),
1837
+ contract.read.depositRequest([this.pool.id.raw, this.id.raw, assetId.raw, addressToBytes32(investor)]),
1838
+ contract.read.redeemRequest([this.pool.id.raw, this.id.raw, assetId.raw, addressToBytes32(investor)]),
1839
+ contract.read.queuedDepositRequest([
1840
+ this.pool.id.raw,
1841
+ this.id.raw,
1842
+ assetId.raw,
1843
+ addressToBytes32(investor),
1844
+ ]),
1845
+ contract.read.queuedRedeemRequest([
1846
+ this.pool.id.raw,
1847
+ this.id.raw,
1848
+ assetId.raw,
1849
+ addressToBytes32(investor),
1850
+ ]),
1797
1851
  ]);
1798
1852
  return {
1799
1853
  assetId,
@@ -1802,9 +1856,11 @@ export class ShareClass extends Entity {
1802
1856
  maxRedeemClaims,
1803
1857
  pendingDeposit,
1804
1858
  pendingRedeem,
1859
+ queuedInvest,
1860
+ queuedRedeem,
1805
1861
  };
1806
1862
  }).pipe(repeatOnEvents(this._root, {
1807
- address: shareClassManager,
1863
+ address: batchRequestManager,
1808
1864
  eventName: [
1809
1865
  'UpdateDepositRequest',
1810
1866
  'UpdateRedeemRequest',
@@ -1817,7 +1873,7 @@ export class ShareClass extends Entity {
1817
1873
  return events.some((event) => event.args.scId === this.id.raw &&
1818
1874
  (event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
1819
1875
  },
1820
- }, this.pool.chainId)))));
1876
+ }, this.pool.centrifugeId)))));
1821
1877
  }
1822
1878
  /** @internal */
1823
1879
  _allVaults() {
@@ -1832,24 +1888,25 @@ export class ShareClass extends Entity {
1832
1888
  assetAddress
1833
1889
  status
1834
1890
  blockchain {
1835
- id
1891
+ centrifugeId
1836
1892
  }
1837
1893
  }
1838
1894
  }
1839
1895
  }`, { scId: this.id.raw }, (data) => data.vaults.items.map(({ blockchain, asset, ...rest }) => ({
1840
1896
  ...rest,
1841
- chainId: Number(blockchain.id),
1897
+ centrifugeId: Number(blockchain.centrifugeId),
1842
1898
  assetId: new AssetId(asset.id),
1843
1899
  })));
1844
1900
  }
1845
1901
  /** @internal */
1846
1902
  _metadata() {
1847
- return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1848
- const [name, symbol] = await this._root.getClient(this.pool.chainId).readContract({
1903
+ return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1904
+ const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
1905
+ const [name, symbol] = await client.readContract({
1849
1906
  address: shareClassManager,
1850
1907
  abi: ABI.ShareClassManager,
1851
1908
  functionName: 'metadata',
1852
- args: [this.id.raw],
1909
+ args: [this.pool.id.raw, this.id.raw],
1853
1910
  });
1854
1911
  return {
1855
1912
  name,
@@ -1863,17 +1920,23 @@ export class ShareClass extends Entity {
1863
1920
  return event.args.scId === this.id;
1864
1921
  });
1865
1922
  },
1866
- }, this.pool.chainId)))));
1923
+ }, this.pool.centrifugeId)))));
1867
1924
  }
1868
1925
  /** @internal */
1869
1926
  _metrics() {
1870
- return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1871
- const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
1927
+ return this._query(['metrics'], () => combineLatest([
1928
+ this._root._protocolAddresses(this.pool.centrifugeId),
1929
+ this._root.getClient(this.pool.centrifugeId),
1930
+ ]).pipe(switchMap(([{ shareClassManager }, client]) => defer(async () => {
1931
+ const contract = getContract({
1872
1932
  address: shareClassManager,
1873
1933
  abi: ABI.ShareClassManager,
1874
- functionName: 'metrics',
1875
- args: [this.id.raw],
1934
+ client,
1876
1935
  });
1936
+ const [totalIssuance, [pricePerShare]] = await Promise.all([
1937
+ contract.read.totalIssuance([this.pool.id.raw, this.id.raw]),
1938
+ contract.read.pricePoolPerShare([this.pool.id.raw, this.id.raw]),
1939
+ ]);
1877
1940
  return {
1878
1941
  totalIssuance: new Balance(totalIssuance, 18),
1879
1942
  pricePerShare: new Price(pricePerShare),
@@ -1892,7 +1955,7 @@ export class ShareClass extends Entity {
1892
1955
  return event.args.scId === this.id.raw;
1893
1956
  });
1894
1957
  },
1895
- }, this.pool.chainId)))));
1958
+ }, this.pool.centrifugeId)))));
1896
1959
  }
1897
1960
  /** @internal */
1898
1961
  _epochInvestOrders() {
@@ -1949,29 +2012,30 @@ export class ShareClass extends Entity {
1949
2012
  /** @internal */
1950
2013
  _epoch(assetId) {
1951
2014
  return this._query(['epoch', assetId.toString()], () => combineLatest([
1952
- this._root._protocolAddresses(this.pool.chainId),
2015
+ this._root._protocolAddresses(this.pool.centrifugeId),
1953
2016
  this.pool.currency(),
1954
- this._root._assetDecimals(assetId, this.pool.chainId),
2017
+ this._root._assetDecimals(assetId, this.pool.centrifugeId),
1955
2018
  this._epochInvestOrders(),
1956
2019
  this._epochRedeemOrders(),
1957
- ]).pipe(switchMap(([{ shareClassManager }, poolCurrency, assetDecimals, epochInvestOrders, epochRedeemOrders]) => defer(async () => {
2020
+ this._root.getClient(this.pool.centrifugeId),
2021
+ ]).pipe(switchMap(([{ batchRequestManager }, poolCurrency, assetDecimals, epochInvestOrders, epochRedeemOrders, client]) => defer(async () => {
1958
2022
  const scm = getContract({
1959
- address: shareClassManager,
1960
- abi: ABI.ShareClassManager,
1961
- client: this._root.getClient(this.pool.chainId),
2023
+ address: batchRequestManager,
2024
+ abi: ABI.BatchRequestManager,
2025
+ client,
1962
2026
  });
1963
2027
  const [epoch, pendingDeposit, pendingRedeem] = await Promise.all([
1964
- scm.read.epochId([this.id.raw, assetId.raw]),
1965
- scm.read.pendingDeposit([this.id.raw, assetId.raw]),
1966
- scm.read.pendingRedeem([this.id.raw, assetId.raw]),
2028
+ scm.read.epochId([this.pool.id.raw, this.id.raw, assetId.raw]),
2029
+ scm.read.pendingDeposit([this.pool.id.raw, this.id.raw, assetId.raw]),
2030
+ scm.read.pendingRedeem([this.pool.id.raw, this.id.raw, assetId.raw]),
1967
2031
  ]);
1968
2032
  const depositEpoch = epoch[0] + 1;
1969
2033
  const redeemEpoch = epoch[1] + 1;
1970
2034
  const issueEpoch = epoch[2] + 1;
1971
2035
  const revokeEpoch = epoch[3] + 1;
1972
2036
  const [depositEpochAmounts, redeemEpochAmount] = await Promise.all([
1973
- Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.id.raw, assetId.raw, issueEpoch + i]))),
1974
- Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.id.raw, assetId.raw, revokeEpoch + i]))),
2037
+ Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.pool.id.raw, this.id.raw, assetId.raw, issueEpoch + i]))),
2038
+ Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.pool.id.raw, this.id.raw, assetId.raw, revokeEpoch + i]))),
1975
2039
  ]);
1976
2040
  const approvedDeposit = depositEpochAmounts.reduce((acc, amount) => acc + amount[1], 0n);
1977
2041
  const approvedRedeem = redeemEpochAmount.reduce((acc, amount) => acc + amount[1], 0n);
@@ -1996,7 +2060,7 @@ export class ShareClass extends Entity {
1996
2060
  })),
1997
2061
  };
1998
2062
  }).pipe(repeatOnEvents(this._root, {
1999
- address: shareClassManager,
2063
+ address: batchRequestManager,
2000
2064
  eventName: [
2001
2065
  'ApproveDeposits',
2002
2066
  'ApproveRedeems',
@@ -2012,30 +2076,35 @@ export class ShareClass extends Entity {
2012
2076
  return event.args.scId === this.id.raw;
2013
2077
  });
2014
2078
  },
2015
- }, this.pool.chainId)))));
2079
+ }, this.pool.centrifugeId)))));
2016
2080
  }
2017
2081
  /** @internal */
2018
- _updateContract(chainId, target, payload) {
2082
+ _updateContract(centrifugeId, target, payload) {
2019
2083
  const self = this;
2020
2084
  return this._transact(async function* (ctx) {
2021
- const [id, { hub }] = await Promise.all([
2022
- self._root.id(chainId),
2023
- self._root._protocolAddresses(self.pool.chainId),
2024
- ]);
2085
+ const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
2025
2086
  yield* wrapTransaction('Update contract', ctx, {
2026
2087
  contract: hub,
2027
2088
  data: encodeFunctionData({
2028
2089
  abi: ABI.Hub,
2029
2090
  functionName: 'updateContract',
2030
- args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(target), payload, 0n],
2091
+ args: [
2092
+ self.pool.id.raw,
2093
+ self.id.raw,
2094
+ centrifugeId,
2095
+ addressToBytes32(target),
2096
+ payload,
2097
+ 0n,
2098
+ ctx.signingAddress,
2099
+ ],
2031
2100
  }),
2032
- messages: { [id]: [MessageType.UpdateContract] },
2101
+ messages: { [centrifugeId]: [MessageType.TrustedContractUpdate] },
2033
2102
  });
2034
- }, this.pool.chainId);
2103
+ }, this.pool.centrifugeId);
2035
2104
  }
2036
2105
  /** @internal */
2037
2106
  _epochOutstandingInvests() {
2038
- return this._query(['epochOutstandingInvests'], () => combineLatest([this._root._deployments()]).pipe(switchMap(([deployments]) => this._root._queryIndexer(`query ($scId: String!) {
2107
+ return this._query(['epochOutstandingInvests'], () => this._root._queryIndexer(`query ($scId: String!) {
2039
2108
  epochOutstandingInvests(where: { tokenId: $scId }, limit: 1000) {
2040
2109
  items {
2041
2110
  assetId
@@ -2044,17 +2113,16 @@ export class ShareClass extends Entity {
2044
2113
  }
2045
2114
  }
2046
2115
  }`, { scId: this.id.raw }, (data) => {
2047
- const chainsById = new Map(deployments.blockchains.items.map((c) => [c.centrifugeId, c.id]));
2048
2116
  return data.epochOutstandingInvests.items.map((item) => ({
2049
2117
  assetId: new AssetId(item.assetId),
2050
- chainId: Number(chainsById.get(item.asset.centrifugeId)),
2118
+ centrifugeId: item.asset.centrifugeId,
2051
2119
  amount: new Balance(item.pendingAssetsAmount || 0, item.asset.decimals),
2052
2120
  }));
2053
- }))));
2121
+ }));
2054
2122
  }
2055
2123
  /** @internal */
2056
2124
  _epochOutstandingRedeems() {
2057
- return this._query(['epochOutstandingRedeems'], () => combineLatest([this._root._deployments()]).pipe(switchMap(([deployments]) => this._root._queryIndexer(`query ($scId: String!) {
2125
+ return this._query(['epochOutstandingRedeems'], () => this._root._queryIndexer(`query ($scId: String!) {
2058
2126
  epochOutstandingRedeems(where: { tokenId: $scId }, limit: 1000) {
2059
2127
  items {
2060
2128
  assetId
@@ -2063,22 +2131,21 @@ export class ShareClass extends Entity {
2063
2131
  }
2064
2132
  }
2065
2133
  }`, { scId: this.id.raw }, (data) => {
2066
- const chainsById = new Map(deployments.blockchains.items.map((c) => [c.centrifugeId, c.id]));
2067
2134
  return data.epochOutstandingRedeems.items.map((item) => ({
2068
2135
  assetId: new AssetId(item.assetId),
2069
- chainId: Number(chainsById.get(item.asset.centrifugeId)),
2136
+ centrifugeId: item.asset.centrifugeId,
2070
2137
  amount: new Balance(item.pendingSharesAmount || 0, 18),
2071
2138
  }));
2072
- }))));
2139
+ }));
2073
2140
  }
2074
2141
  /** @internal */
2075
- _share(chainId) {
2076
- return this._query(['share', chainId], () => this.pool.network(chainId).pipe(switchMap((network) => network._share(this.id))));
2142
+ _share(centrifugeId) {
2143
+ return this._query(['share', centrifugeId], () => this.pool.network(centrifugeId).pipe(switchMap((network) => network._share(this.id))));
2077
2144
  }
2078
2145
  /** @internal */
2079
- _restrictionManager(chainId) {
2080
- return this._query(['restrictionManager', chainId], () => this._share(chainId).pipe(switchMap((share) => defer(async () => {
2081
- const address = await this._root.getClient(chainId).readContract({
2146
+ _restrictionManager(centrifugeId) {
2147
+ return this._query(['restrictionManager', centrifugeId], () => combineLatest([this._share(centrifugeId), this._root.getClient(centrifugeId)]).pipe(switchMap(([share, client]) => defer(async () => {
2148
+ const address = await client.readContract({
2082
2149
  address: share,
2083
2150
  abi: ABI.Currency,
2084
2151
  functionName: 'hook',
@@ -2088,12 +2155,13 @@ export class ShareClass extends Entity {
2088
2155
  }
2089
2156
  /** @internal */
2090
2157
  _getFreeAccountId() {
2091
- return this._query(['getFreeAccountId'], () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
2092
- const id = Number(randomUint(32));
2158
+ return this._query(['getFreeAccountId'], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
2159
+ const id = randomUint(256);
2093
2160
  if (triesLeft <= 0)
2094
2161
  return EMPTY;
2095
2162
  return defer(async () => {
2096
- const exists = await this._root.getClient(this.pool.chainId).readContract({
2163
+ const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
2164
+ const exists = await client.readContract({
2097
2165
  address: accounting,
2098
2166
  abi: ABI.Accounting,
2099
2167
  functionName: 'exists',
@@ -2122,7 +2190,7 @@ export class ShareClass extends Entity {
2122
2190
  centrifugeIds?.join(','),
2123
2191
  orderBy,
2124
2192
  orderDirection,
2125
- ], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap((protocolAddresses) => {
2193
+ ], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(switchMap((protocolAddresses) => {
2126
2194
  // Build where clause dynamically based on which filters are provided
2127
2195
  const whereConditions = ['tokenId: $scId', 'accountAddress_not_in: $excludedAddresses'];
2128
2196
  if (balance_gt !== undefined)
@@ -2311,5 +2379,21 @@ export class ShareClass extends Entity {
2311
2379
  };
2312
2380
  })));
2313
2381
  }
2382
+ /** @internal */
2383
+ _getQuote(valuationAddress, assetId, baseAmount) {
2384
+ return this._query(['getQuote', valuationAddress, baseAmount.toString(), assetId.toString()], () => timer(0, 120_000).pipe(switchMap(() => this._root.getClient(this.pool.centrifugeId)), switchMap((client) => combineLatest([
2385
+ this.pool.currency(),
2386
+ defer(() => {
2387
+ return client.readContract({
2388
+ address: valuationAddress,
2389
+ abi: ABI.Valuation,
2390
+ functionName: 'getQuote',
2391
+ args: [this.pool.id.raw, this.id.raw, assetId.raw, baseAmount.toBigInt()],
2392
+ });
2393
+ }),
2394
+ ])), map(([poolCurrency, quote]) => {
2395
+ return new Balance(quote, poolCurrency.decimals);
2396
+ })));
2397
+ }
2314
2398
  }
2315
2399
  //# sourceMappingURL=ShareClass.js.map