@centrifuge/sdk 0.0.0-alpha.8 → 0.1.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 (455) hide show
  1. package/README.md +16 -13
  2. package/dist/Centrifuge.d.ts +309 -231
  3. package/dist/Centrifuge.d.ts.map +1 -1
  4. package/dist/Centrifuge.js +700 -155
  5. package/dist/Centrifuge.js.map +1 -1
  6. package/dist/Centrifuge.test.d.ts +2 -0
  7. package/dist/Centrifuge.test.d.ts.map +1 -0
  8. package/dist/Centrifuge.test.js +531 -0
  9. package/dist/Centrifuge.test.js.map +1 -0
  10. package/dist/abi/Accounting.abi.d.ts +3 -0
  11. package/dist/abi/Accounting.abi.d.ts.map +1 -0
  12. package/dist/abi/Accounting.abi.js +33 -0
  13. package/dist/abi/Accounting.abi.js.map +1 -0
  14. package/dist/abi/AsyncRequestManager.abi.d.ts +3 -0
  15. package/dist/abi/AsyncRequestManager.abi.d.ts.map +1 -0
  16. package/dist/abi/AsyncRequestManager.abi.js +78 -0
  17. package/dist/abi/AsyncRequestManager.abi.js.map +1 -0
  18. package/dist/abi/AsyncVault.abi.d.ts +3 -0
  19. package/dist/abi/AsyncVault.abi.d.ts.map +1 -0
  20. package/dist/abi/AsyncVault.abi.js +101 -0
  21. package/dist/abi/AsyncVault.abi.js.map +1 -0
  22. package/dist/abi/BalanceSheet.abi.d.ts +3 -0
  23. package/dist/abi/BalanceSheet.abi.d.ts.map +1 -0
  24. package/dist/abi/BalanceSheet.abi.js +55 -0
  25. package/dist/abi/BalanceSheet.abi.js.map +1 -0
  26. package/dist/abi/Currency.abi.d.ts +3 -0
  27. package/dist/abi/Currency.abi.d.ts.map +1 -0
  28. package/dist/abi/Currency.abi.js +16 -0
  29. package/dist/abi/Currency.abi.js.map +1 -0
  30. package/dist/abi/ERC6909.abi.d.ts +3 -0
  31. package/dist/abi/ERC6909.abi.d.ts.map +1 -0
  32. package/dist/abi/ERC6909.abi.js +22 -0
  33. package/dist/abi/ERC6909.abi.js.map +1 -0
  34. package/dist/abi/GasService.abi.d.ts +3 -0
  35. package/dist/abi/GasService.abi.d.ts.map +1 -0
  36. package/dist/abi/GasService.abi.js +32 -0
  37. package/dist/abi/GasService.abi.js.map +1 -0
  38. package/dist/abi/Gateway.abi.d.ts +3 -0
  39. package/dist/abi/Gateway.abi.d.ts.map +1 -0
  40. package/dist/abi/Gateway.abi.js +62 -0
  41. package/dist/abi/Gateway.abi.js.map +1 -0
  42. package/dist/abi/Holdings.abi.d.ts +3 -0
  43. package/dist/abi/Holdings.abi.d.ts.map +1 -0
  44. package/dist/abi/Holdings.abi.js +43 -0
  45. package/dist/abi/Holdings.abi.js.map +1 -0
  46. package/dist/abi/Hub.abi.d.ts +3 -0
  47. package/dist/abi/Hub.abi.d.ts.map +1 -0
  48. package/dist/abi/Hub.abi.js +89 -0
  49. package/dist/abi/Hub.abi.js.map +1 -0
  50. package/dist/abi/HubRegistry.abi.d.ts +3 -0
  51. package/dist/abi/HubRegistry.abi.d.ts.map +1 -0
  52. package/dist/abi/HubRegistry.abi.js +39 -0
  53. package/dist/abi/HubRegistry.abi.js.map +1 -0
  54. package/dist/abi/MerkleProofManager.abi.d.ts +3 -0
  55. package/dist/abi/MerkleProofManager.abi.d.ts.map +1 -0
  56. package/dist/abi/MerkleProofManager.abi.js +26 -0
  57. package/dist/abi/MerkleProofManager.abi.js.map +1 -0
  58. package/dist/abi/MessageDispatcher.abi.d.ts +3 -0
  59. package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -0
  60. package/dist/abi/MessageDispatcher.abi.js +49 -0
  61. package/dist/abi/MessageDispatcher.abi.js.map +1 -0
  62. package/dist/abi/MultiAdapter.abi.d.ts +3 -0
  63. package/dist/abi/MultiAdapter.abi.d.ts.map +1 -0
  64. package/dist/abi/MultiAdapter.abi.js +53 -0
  65. package/dist/abi/MultiAdapter.abi.js.map +1 -0
  66. package/dist/abi/OnOffRampManager.abi.d.ts +3 -0
  67. package/dist/abi/OnOffRampManager.abi.d.ts.map +1 -0
  68. package/dist/abi/OnOffRampManager.abi.js +31 -0
  69. package/dist/abi/OnOffRampManager.abi.js.map +1 -0
  70. package/dist/abi/OnOffRampManagerFactory.abi.d.ts +3 -0
  71. package/dist/abi/OnOffRampManagerFactory.abi.d.ts.map +1 -0
  72. package/dist/abi/OnOffRampManagerFactory.abi.js +2 -0
  73. package/dist/abi/OnOffRampManagerFactory.abi.js.map +1 -0
  74. package/dist/abi/PoolEscrow.abi.d.ts +3 -0
  75. package/dist/abi/PoolEscrow.abi.d.ts.map +1 -0
  76. package/dist/abi/PoolEscrow.abi.js +32 -0
  77. package/dist/abi/PoolEscrow.abi.js.map +1 -0
  78. package/dist/abi/PoolEscrowFactory.abi.d.ts +3 -0
  79. package/dist/abi/PoolEscrowFactory.abi.d.ts.map +1 -0
  80. package/dist/abi/PoolEscrowFactory.abi.js +19 -0
  81. package/dist/abi/PoolEscrowFactory.abi.js.map +1 -0
  82. package/dist/abi/RestrictionManager.abi.d.ts +3 -0
  83. package/dist/abi/RestrictionManager.abi.d.ts.map +1 -0
  84. package/dist/abi/RestrictionManager.abi.js +23 -0
  85. package/dist/abi/RestrictionManager.abi.js.map +1 -0
  86. package/dist/abi/ShareClassManager.abi.d.ts +3 -0
  87. package/dist/abi/ShareClassManager.abi.d.ts.map +1 -0
  88. package/dist/abi/ShareClassManager.abi.js +89 -0
  89. package/dist/abi/ShareClassManager.abi.js.map +1 -0
  90. package/dist/abi/Spoke.abi.d.ts +3 -0
  91. package/dist/abi/Spoke.abi.d.ts.map +1 -0
  92. package/dist/abi/Spoke.abi.js +90 -0
  93. package/dist/abi/Spoke.abi.js.map +1 -0
  94. package/dist/abi/SyncRequestManager.abi.d.ts +3 -0
  95. package/dist/abi/SyncRequestManager.abi.d.ts.map +1 -0
  96. package/dist/abi/SyncRequestManager.abi.js +61 -0
  97. package/dist/abi/SyncRequestManager.abi.js.map +1 -0
  98. package/dist/abi/Valuation.abi.d.ts +3 -0
  99. package/dist/abi/Valuation.abi.d.ts.map +1 -0
  100. package/dist/abi/Valuation.abi.js +2 -0
  101. package/dist/abi/Valuation.abi.js.map +1 -0
  102. package/dist/abi/VaultRouter.abi.d.ts +3 -0
  103. package/dist/abi/VaultRouter.abi.d.ts.map +1 -0
  104. package/dist/abi/VaultRouter.abi.js +50 -0
  105. package/dist/abi/VaultRouter.abi.js.map +1 -0
  106. package/dist/abi/index.d.ts +9027 -8
  107. package/dist/abi/index.d.ts.map +1 -1
  108. package/dist/abi/index.js +48 -16
  109. package/dist/abi/index.js.map +1 -1
  110. package/dist/config/chains.d.ts +202 -941
  111. package/dist/config/chains.d.ts.map +1 -1
  112. package/dist/config/chains.js +2 -2
  113. package/dist/config/chains.js.map +1 -1
  114. package/dist/config/protocol.d.ts +3 -0
  115. package/dist/config/protocol.d.ts.map +1 -0
  116. package/dist/config/protocol.js +7 -0
  117. package/dist/config/protocol.js.map +1 -0
  118. package/dist/constants.d.ts +1 -0
  119. package/dist/constants.d.ts.map +1 -1
  120. package/dist/constants.js +1 -0
  121. package/dist/constants.js.map +1 -1
  122. package/dist/entities/BalanceSheet.d.ts +48 -0
  123. package/dist/entities/BalanceSheet.d.ts.map +1 -0
  124. package/dist/entities/BalanceSheet.js +94 -0
  125. package/dist/entities/BalanceSheet.js.map +1 -0
  126. package/dist/entities/BalanceSheet.test.d.ts +2 -0
  127. package/dist/entities/BalanceSheet.test.d.ts.map +1 -0
  128. package/dist/entities/BalanceSheet.test.js +64 -0
  129. package/dist/entities/BalanceSheet.test.js.map +1 -0
  130. package/dist/{Entity.d.ts → entities/Entity.d.ts} +1 -1
  131. package/dist/entities/Entity.d.ts.map +1 -0
  132. package/dist/{Entity.js → entities/Entity.js} +0 -3
  133. package/dist/entities/Entity.js.map +1 -0
  134. package/dist/{IndexerQueries → entities/IndexerQueries}/assetSnapshots.d.ts +14 -14
  135. package/dist/entities/IndexerQueries/assetSnapshots.d.ts.map +1 -0
  136. package/dist/{IndexerQueries → entities/IndexerQueries}/assetSnapshots.js +15 -17
  137. package/dist/entities/IndexerQueries/assetSnapshots.js.map +1 -0
  138. package/dist/{IndexerQueries → entities/IndexerQueries}/assetTransactions.d.ts +7 -6
  139. package/dist/entities/IndexerQueries/assetTransactions.d.ts.map +1 -0
  140. package/dist/{IndexerQueries → entities/IndexerQueries}/assetTransactions.js +8 -7
  141. package/dist/entities/IndexerQueries/assetTransactions.js.map +1 -0
  142. package/dist/{IndexerQueries → entities/IndexerQueries}/epochs.d.ts +7 -7
  143. package/dist/entities/IndexerQueries/epochs.d.ts.map +1 -0
  144. package/dist/{IndexerQueries → entities/IndexerQueries}/epochs.js +7 -7
  145. package/dist/entities/IndexerQueries/epochs.js.map +1 -0
  146. package/dist/{IndexerQueries → entities/IndexerQueries}/index.d.ts +24 -24
  147. package/dist/entities/IndexerQueries/index.d.ts.map +1 -0
  148. package/dist/{IndexerQueries → entities/IndexerQueries}/index.js +7 -7
  149. package/dist/entities/IndexerQueries/index.js.map +1 -0
  150. package/dist/{IndexerQueries → entities/IndexerQueries}/investorTransactions.d.ts +4 -4
  151. package/dist/entities/IndexerQueries/investorTransactions.d.ts.map +1 -0
  152. package/dist/{IndexerQueries → entities/IndexerQueries}/investorTransactions.js +4 -4
  153. package/dist/entities/IndexerQueries/investorTransactions.js.map +1 -0
  154. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeSnapshots.d.ts +8 -8
  155. package/dist/entities/IndexerQueries/poolFeeSnapshots.d.ts.map +1 -0
  156. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeSnapshots.js +8 -8
  157. package/dist/entities/IndexerQueries/poolFeeSnapshots.js.map +1 -0
  158. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeTransactions.d.ts +3 -3
  159. package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts.map +1 -0
  160. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeTransactions.js +3 -3
  161. package/dist/entities/IndexerQueries/poolFeeTransactions.js.map +1 -0
  162. package/dist/{IndexerQueries → entities/IndexerQueries}/poolSnapshots.d.ts +30 -24
  163. package/dist/entities/IndexerQueries/poolSnapshots.d.ts.map +1 -0
  164. package/dist/{IndexerQueries → entities/IndexerQueries}/poolSnapshots.js +29 -23
  165. package/dist/entities/IndexerQueries/poolSnapshots.js.map +1 -0
  166. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheCurrencyBalance.d.ts +15 -15
  167. package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts.map +1 -0
  168. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheCurrencyBalance.js +8 -8
  169. package/dist/entities/IndexerQueries/trancheCurrencyBalance.js.map +1 -0
  170. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheSnapshots.d.ts +6 -6
  171. package/dist/entities/IndexerQueries/trancheSnapshots.d.ts.map +1 -0
  172. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheSnapshots.js +6 -6
  173. package/dist/entities/IndexerQueries/trancheSnapshots.js.map +1 -0
  174. package/dist/entities/Investor.d.ts +47 -0
  175. package/dist/entities/Investor.d.ts.map +1 -0
  176. package/dist/entities/Investor.js +93 -0
  177. package/dist/entities/Investor.js.map +1 -0
  178. package/dist/entities/Investor.test.d.ts +2 -0
  179. package/dist/entities/Investor.test.d.ts.map +1 -0
  180. package/dist/entities/Investor.test.js +78 -0
  181. package/dist/entities/Investor.test.js.map +1 -0
  182. package/dist/entities/MerkleProofManager.d.ts +37 -0
  183. package/dist/entities/MerkleProofManager.d.ts.map +1 -0
  184. package/dist/entities/MerkleProofManager.js +210 -0
  185. package/dist/entities/MerkleProofManager.js.map +1 -0
  186. package/dist/entities/MerkleProofManager.test.d.ts +2 -0
  187. package/dist/entities/MerkleProofManager.test.d.ts.map +1 -0
  188. package/dist/entities/MerkleProofManager.test.js +241 -0
  189. package/dist/entities/MerkleProofManager.test.js.map +1 -0
  190. package/dist/entities/OnOffRampManager.d.ts +34 -0
  191. package/dist/entities/OnOffRampManager.d.ts.map +1 -0
  192. package/dist/entities/OnOffRampManager.js +191 -0
  193. package/dist/entities/OnOffRampManager.js.map +1 -0
  194. package/dist/entities/OnOffRampManager.test.d.ts +2 -0
  195. package/dist/entities/OnOffRampManager.test.d.ts.map +1 -0
  196. package/dist/entities/OnOffRampManager.test.js +170 -0
  197. package/dist/entities/OnOffRampManager.test.js.map +1 -0
  198. package/dist/entities/Pool.d.ts +157 -0
  199. package/dist/entities/Pool.d.ts.map +1 -0
  200. package/dist/entities/Pool.js +591 -0
  201. package/dist/entities/Pool.js.map +1 -0
  202. package/dist/entities/Pool.test.d.ts +2 -0
  203. package/dist/entities/Pool.test.d.ts.map +1 -0
  204. package/dist/entities/Pool.test.js +271 -0
  205. package/dist/entities/Pool.test.js.map +1 -0
  206. package/dist/entities/PoolNetwork.d.ts +77 -0
  207. package/dist/entities/PoolNetwork.d.ts.map +1 -0
  208. package/dist/entities/PoolNetwork.js +360 -0
  209. package/dist/entities/PoolNetwork.js.map +1 -0
  210. package/dist/entities/PoolNetwork.test.d.ts +2 -0
  211. package/dist/entities/PoolNetwork.test.d.ts.map +1 -0
  212. package/dist/entities/PoolNetwork.test.js +166 -0
  213. package/dist/entities/PoolNetwork.test.js.map +1 -0
  214. package/dist/entities/Reports/PoolReports.d.ts +8 -0
  215. package/dist/entities/Reports/PoolReports.d.ts.map +1 -0
  216. package/dist/entities/Reports/PoolReports.js +14 -0
  217. package/dist/entities/Reports/PoolReports.js.map +1 -0
  218. package/dist/entities/Reports/PoolSharePricesReport.d.ts +25 -0
  219. package/dist/entities/Reports/PoolSharePricesReport.d.ts.map +1 -0
  220. package/dist/entities/Reports/PoolSharePricesReport.js +64 -0
  221. package/dist/entities/Reports/PoolSharePricesReport.js.map +1 -0
  222. package/dist/entities/Reports/PoolSharePricesReport.test.d.ts +2 -0
  223. package/dist/entities/Reports/PoolSharePricesReport.test.d.ts.map +1 -0
  224. package/dist/entities/Reports/PoolSharePricesReport.test.js +35 -0
  225. package/dist/entities/Reports/PoolSharePricesReport.test.js.map +1 -0
  226. package/dist/{Reports → entities/Reports}/Processor.d.ts +1 -1
  227. package/dist/entities/Reports/Processor.d.ts.map +1 -0
  228. package/dist/{Reports → entities/Reports}/Processor.js +27 -13
  229. package/dist/entities/Reports/Processor.js.map +1 -0
  230. package/dist/entities/Reports/Processor.test.d.ts +2 -0
  231. package/dist/entities/Reports/Processor.test.d.ts.map +1 -0
  232. package/dist/entities/Reports/Processor.test.js +767 -0
  233. package/dist/entities/Reports/Processor.test.js.map +1 -0
  234. package/dist/entities/Reports/Reports.test.d.ts +2 -0
  235. package/dist/entities/Reports/Reports.test.d.ts.map +1 -0
  236. package/dist/entities/Reports/Reports.test.js +559 -0
  237. package/dist/entities/Reports/Reports.test.js.map +1 -0
  238. package/dist/{Reports → entities/Reports}/index.d.ts +2 -2
  239. package/dist/entities/Reports/index.d.ts.map +1 -0
  240. package/dist/{Reports → entities/Reports}/index.js +4 -4
  241. package/dist/entities/Reports/index.js.map +1 -0
  242. package/dist/entities/Reports/types.d.ts +9 -0
  243. package/dist/entities/Reports/types.d.ts.map +1 -0
  244. package/dist/entities/Reports/types.js +2 -0
  245. package/dist/entities/Reports/types.js.map +1 -0
  246. package/dist/entities/Reports/utils.d.ts +20 -0
  247. package/dist/entities/Reports/utils.d.ts.map +1 -0
  248. package/dist/entities/Reports/utils.js +47 -0
  249. package/dist/entities/Reports/utils.js.map +1 -0
  250. package/dist/entities/ShareClass.d.ts +215 -0
  251. package/dist/entities/ShareClass.d.ts.map +1 -0
  252. package/dist/entities/ShareClass.js +1321 -0
  253. package/dist/entities/ShareClass.js.map +1 -0
  254. package/dist/entities/ShareClass.test.d.ts +2 -0
  255. package/dist/entities/ShareClass.test.d.ts.map +1 -0
  256. package/dist/entities/ShareClass.test.js +528 -0
  257. package/dist/entities/ShareClass.test.js.map +1 -0
  258. package/dist/entities/Vault.d.ts +92 -0
  259. package/dist/entities/Vault.d.ts.map +1 -0
  260. package/dist/entities/Vault.js +433 -0
  261. package/dist/entities/Vault.js.map +1 -0
  262. package/dist/entities/Vault.test.d.ts +2 -0
  263. package/dist/entities/Vault.test.d.ts.map +1 -0
  264. package/dist/entities/Vault.test.js +309 -0
  265. package/dist/entities/Vault.test.js.map +1 -0
  266. package/dist/index.d.ts +15 -8
  267. package/dist/index.d.ts.map +1 -1
  268. package/dist/index.js +13 -5
  269. package/dist/index.js.map +1 -1
  270. package/dist/tests/forkServer.d.mts +2 -0
  271. package/dist/tests/forkServer.d.mts.map +1 -0
  272. package/dist/tests/forkServer.mjs +104 -0
  273. package/dist/tests/forkServer.mjs.map +1 -0
  274. package/dist/tests/mocks/mockAssetSnapshots.d.ts +1 -1
  275. package/dist/tests/mocks/mockAssetSnapshots.d.ts.map +1 -1
  276. package/dist/tests/mocks/mockAssetSnapshots.js +27 -27
  277. package/dist/tests/mocks/mockAssetSnapshots.js.map +1 -1
  278. package/dist/tests/mocks/mockAssetTransactions.d.ts +1 -1
  279. package/dist/tests/mocks/mockAssetTransactions.d.ts.map +1 -1
  280. package/dist/tests/mocks/mockAssetTransactions.js +17 -14
  281. package/dist/tests/mocks/mockAssetTransactions.js.map +1 -1
  282. package/dist/tests/mocks/mockEpochs.d.ts +1 -1
  283. package/dist/tests/mocks/mockEpochs.d.ts.map +1 -1
  284. package/dist/tests/mocks/mockEpochs.js +13 -13
  285. package/dist/tests/mocks/mockEpochs.js.map +1 -1
  286. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts +1 -1
  287. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts.map +1 -1
  288. package/dist/tests/mocks/mockInvestorCurrencyBalance.js +15 -15
  289. package/dist/tests/mocks/mockInvestorCurrencyBalance.js.map +1 -1
  290. package/dist/tests/mocks/mockInvestorTransactions.d.ts +1 -1
  291. package/dist/tests/mocks/mockInvestorTransactions.d.ts.map +1 -1
  292. package/dist/tests/mocks/mockInvestorTransactions.js +5 -5
  293. package/dist/tests/mocks/mockInvestorTransactions.js.map +1 -1
  294. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts +1 -1
  295. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts.map +1 -1
  296. package/dist/tests/mocks/mockPoolFeeSnapshot.js +29 -29
  297. package/dist/tests/mocks/mockPoolFeeSnapshot.js.map +1 -1
  298. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts +3 -3
  299. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts.map +1 -1
  300. package/dist/tests/mocks/mockPoolFeeTransactions.js +3 -3
  301. package/dist/tests/mocks/mockPoolFeeTransactions.js.map +1 -1
  302. package/dist/tests/mocks/mockPoolMetadata.d.ts.map +1 -1
  303. package/dist/tests/mocks/mockPoolMetadata.js +7 -17
  304. package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
  305. package/dist/tests/mocks/mockPoolSnapshots.d.ts +1 -1
  306. package/dist/tests/mocks/mockPoolSnapshots.d.ts.map +1 -1
  307. package/dist/tests/mocks/mockPoolSnapshots.js +47 -45
  308. package/dist/tests/mocks/mockPoolSnapshots.js.map +1 -1
  309. package/dist/tests/mocks/mockTrancheSnapshots.d.ts +1 -1
  310. package/dist/tests/mocks/mockTrancheSnapshots.d.ts.map +1 -1
  311. package/dist/tests/mocks/mockTrancheSnapshots.js +21 -21
  312. package/dist/tests/mocks/mockTrancheSnapshots.js.map +1 -1
  313. package/dist/tests/setup.d.ts.map +1 -1
  314. package/dist/tests/setup.js +4 -3
  315. package/dist/tests/setup.js.map +1 -1
  316. package/dist/tests/tenderly.d.ts +15 -2
  317. package/dist/tests/tenderly.d.ts.map +1 -1
  318. package/dist/tests/tenderly.js +74 -67
  319. package/dist/tests/tenderly.js.map +1 -1
  320. package/dist/tests/utils.d.ts +3 -0
  321. package/dist/tests/utils.d.ts.map +1 -0
  322. package/dist/tests/utils.js +4 -0
  323. package/dist/tests/utils.js.map +1 -0
  324. package/dist/types/holdings.d.ts +9 -0
  325. package/dist/types/holdings.d.ts.map +1 -0
  326. package/dist/types/holdings.js +10 -0
  327. package/dist/types/holdings.js.map +1 -0
  328. package/dist/types/index.d.ts +52 -5
  329. package/dist/types/index.d.ts.map +1 -1
  330. package/dist/types/indexer.d.ts +4189 -0
  331. package/dist/types/indexer.d.ts.map +1 -0
  332. package/dist/types/indexer.js +56 -0
  333. package/dist/types/indexer.js.map +1 -0
  334. package/dist/types/poolInput.d.ts +79 -0
  335. package/dist/types/poolInput.d.ts.map +1 -0
  336. package/dist/types/poolInput.js +2 -0
  337. package/dist/types/poolInput.js.map +1 -0
  338. package/dist/types/poolMetadata.d.ts +41 -13
  339. package/dist/types/poolMetadata.d.ts.map +1 -1
  340. package/dist/types/reports.d.ts +71 -66
  341. package/dist/types/reports.d.ts.map +1 -1
  342. package/dist/types/transaction.d.ts +102 -3
  343. package/dist/types/transaction.d.ts.map +1 -1
  344. package/dist/types/transaction.js +55 -1
  345. package/dist/types/transaction.js.map +1 -1
  346. package/dist/utils/BigInt.d.ts +17 -23
  347. package/dist/utils/BigInt.d.ts.map +1 -1
  348. package/dist/utils/BigInt.js +18 -25
  349. package/dist/utils/BigInt.js.map +1 -1
  350. package/dist/utils/BigInt.test.d.ts +2 -0
  351. package/dist/utils/BigInt.test.d.ts.map +1 -0
  352. package/dist/utils/BigInt.test.js +298 -0
  353. package/dist/utils/BigInt.test.js.map +1 -0
  354. package/dist/utils/currencies.d.ts +5 -0
  355. package/dist/utils/currencies.d.ts.map +1 -0
  356. package/dist/utils/currencies.js +7 -0
  357. package/dist/utils/currencies.js.map +1 -0
  358. package/dist/utils/decimal.d.ts +2 -2
  359. package/dist/utils/decimal.d.ts.map +1 -1
  360. package/dist/utils/decimal.js.map +1 -1
  361. package/dist/utils/index.d.ts +4 -0
  362. package/dist/utils/index.d.ts.map +1 -0
  363. package/dist/utils/index.js +24 -0
  364. package/dist/utils/index.js.map +1 -0
  365. package/dist/utils/ipfs.d.ts +7 -0
  366. package/dist/utils/ipfs.d.ts.map +1 -0
  367. package/dist/utils/ipfs.js +64 -0
  368. package/dist/utils/ipfs.js.map +1 -0
  369. package/dist/utils/ipfs.test.d.ts +2 -0
  370. package/dist/utils/ipfs.test.d.ts.map +1 -0
  371. package/dist/utils/ipfs.test.js +54 -0
  372. package/dist/utils/ipfs.test.js.map +1 -0
  373. package/dist/utils/permit.d.ts +13 -0
  374. package/dist/utils/permit.d.ts.map +1 -0
  375. package/dist/utils/permit.js +82 -0
  376. package/dist/utils/permit.js.map +1 -0
  377. package/dist/utils/permit.test.d.ts +2 -0
  378. package/dist/utils/permit.test.d.ts.map +1 -0
  379. package/dist/utils/permit.test.js +22 -0
  380. package/dist/utils/permit.test.js.map +1 -0
  381. package/dist/utils/rx.d.ts +3 -3
  382. package/dist/utils/rx.d.ts.map +1 -1
  383. package/dist/utils/rx.js +5 -1
  384. package/dist/utils/rx.js.map +1 -1
  385. package/dist/utils/transaction.d.ts +20 -10
  386. package/dist/utils/transaction.d.ts.map +1 -1
  387. package/dist/utils/transaction.js +162 -23
  388. package/dist/utils/transaction.js.map +1 -1
  389. package/dist/utils/types.d.ts +39 -0
  390. package/dist/utils/types.d.ts.map +1 -0
  391. package/dist/utils/types.js +89 -0
  392. package/dist/utils/types.js.map +1 -0
  393. package/dist/utils/types.test.d.ts +2 -0
  394. package/dist/utils/types.test.d.ts.map +1 -0
  395. package/dist/utils/types.test.js +89 -0
  396. package/dist/utils/types.test.js.map +1 -0
  397. package/package.json +12 -12
  398. package/dist/Account.d.ts +0 -11
  399. package/dist/Account.d.ts.map +0 -1
  400. package/dist/Account.js +0 -46
  401. package/dist/Account.js.map +0 -1
  402. package/dist/Entity.d.ts.map +0 -1
  403. package/dist/Entity.js.map +0 -1
  404. package/dist/IndexerQueries/assetSnapshots.d.ts.map +0 -1
  405. package/dist/IndexerQueries/assetSnapshots.js.map +0 -1
  406. package/dist/IndexerQueries/assetTransactions.d.ts.map +0 -1
  407. package/dist/IndexerQueries/assetTransactions.js.map +0 -1
  408. package/dist/IndexerQueries/epochs.d.ts.map +0 -1
  409. package/dist/IndexerQueries/epochs.js.map +0 -1
  410. package/dist/IndexerQueries/index.d.ts.map +0 -1
  411. package/dist/IndexerQueries/index.js.map +0 -1
  412. package/dist/IndexerQueries/investorTransactions.d.ts.map +0 -1
  413. package/dist/IndexerQueries/investorTransactions.js.map +0 -1
  414. package/dist/IndexerQueries/poolFeeSnapshots.d.ts.map +0 -1
  415. package/dist/IndexerQueries/poolFeeSnapshots.js.map +0 -1
  416. package/dist/IndexerQueries/poolFeeTransactions.d.ts.map +0 -1
  417. package/dist/IndexerQueries/poolFeeTransactions.js.map +0 -1
  418. package/dist/IndexerQueries/poolSnapshots.d.ts.map +0 -1
  419. package/dist/IndexerQueries/poolSnapshots.js.map +0 -1
  420. package/dist/IndexerQueries/trancheCurrencyBalance.d.ts.map +0 -1
  421. package/dist/IndexerQueries/trancheCurrencyBalance.js.map +0 -1
  422. package/dist/IndexerQueries/trancheSnapshots.d.ts.map +0 -1
  423. package/dist/IndexerQueries/trancheSnapshots.js.map +0 -1
  424. package/dist/Pool.d.ts +0 -25
  425. package/dist/Pool.d.ts.map +0 -1
  426. package/dist/Pool.js +0 -79
  427. package/dist/Pool.js.map +0 -1
  428. package/dist/PoolNetwork.d.ts +0 -54
  429. package/dist/PoolNetwork.d.ts.map +0 -1
  430. package/dist/PoolNetwork.js +0 -238
  431. package/dist/PoolNetwork.js.map +0 -1
  432. package/dist/Reports/Processor.d.ts.map +0 -1
  433. package/dist/Reports/Processor.js.map +0 -1
  434. package/dist/Reports/index.d.ts.map +0 -1
  435. package/dist/Reports/index.js.map +0 -1
  436. package/dist/Vault.d.ts +0 -84
  437. package/dist/Vault.d.ts.map +0 -1
  438. package/dist/Vault.js +0 -331
  439. package/dist/Vault.js.map +0 -1
  440. package/dist/abi/CentrifugeRouter.abi.json +0 -43
  441. package/dist/abi/Currency.abi.json +0 -14
  442. package/dist/abi/Gateway.abi.json +0 -1
  443. package/dist/abi/InvestmentManager.abi.json +0 -4
  444. package/dist/abi/LiquidityPool.abi.json +0 -79
  445. package/dist/abi/PoolManager.abi.json +0 -55
  446. package/dist/abi/RestrictionManager.abi.json +0 -22
  447. package/dist/abi/Router.abi.json +0 -1
  448. package/dist/config/lp.d.ts +0 -17
  449. package/dist/config/lp.d.ts.map +0 -1
  450. package/dist/config/lp.js +0 -35
  451. package/dist/config/lp.js.map +0 -1
  452. package/dist/utils/pinToApi.d.ts +0 -2
  453. package/dist/utils/pinToApi.d.ts.map +0 -1
  454. package/dist/utils/pinToApi.js +0 -10
  455. package/dist/utils/pinToApi.js.map +0 -1
@@ -0,0 +1,1321 @@
1
+ import { catchError, combineLatest, defer, EMPTY, expand, filter, firstValueFrom, map, of, switchMap } from 'rxjs';
2
+ import { encodeFunctionData, encodePacked, getContract } from 'viem';
3
+ import { ABI } from '../abi/index.js';
4
+ import { AccountType } from '../types/holdings.js';
5
+ import { MessageType } from '../types/transaction.js';
6
+ import { Balance, Price } from '../utils/BigInt.js';
7
+ import { addressToBytes32, randomUint } from '../utils/index.js';
8
+ import { repeatOnEvents } from '../utils/rx.js';
9
+ import { wrapTransaction } from '../utils/transaction.js';
10
+ import { AssetId, ShareClassId } from '../utils/types.js';
11
+ import { BalanceSheet } from './BalanceSheet.js';
12
+ import { Entity } from './Entity.js';
13
+ import { PoolNetwork } from './PoolNetwork.js';
14
+ import { Vault } from './Vault.js';
15
+ /**
16
+ * Query and interact with a share class, which allows querying total issuance, NAV per share,
17
+ * and allows interactions related to asynchronous deposits and redemptions.
18
+ */
19
+ export class ShareClass extends Entity {
20
+ pool;
21
+ id;
22
+ /** @internal */
23
+ constructor(_root, pool, id) {
24
+ const _id = id instanceof ShareClassId ? id : new ShareClassId(id);
25
+ super(_root, ['shareclass', _id.toString()]);
26
+ this.pool = pool;
27
+ this.id = _id;
28
+ }
29
+ /**
30
+ * Query the details of the share class.
31
+ * @returns The details of the share class, including name, symbol, total issuance, NAV per share and relavant metadata from the pool metadata.
32
+ */
33
+ details() {
34
+ return this._query(null, () => combineLatest([
35
+ this._metrics(),
36
+ this._metadata(),
37
+ this.navPerNetwork(),
38
+ this.pool.currency(),
39
+ this.pool.metadata(),
40
+ ]).pipe(map(([metrics, metadata, navPerNetwork, poolCurrency, poolMeta]) => {
41
+ const totalIssuance = navPerNetwork.reduce((acc, item) => acc.add(item.totalIssuance), new Balance(0n, poolCurrency.decimals));
42
+ const meta = poolMeta?.shareClasses?.[this.id.raw];
43
+ return {
44
+ id: this.id,
45
+ name: metadata.name,
46
+ symbol: metadata.symbol,
47
+ totalIssuance,
48
+ pricePerShare: metrics.pricePerShare,
49
+ nav: totalIssuance.mul(metrics.pricePerShare),
50
+ navPerNetwork,
51
+ icon: meta?.icon || null,
52
+ minInitialInvestment: meta?.minInitialInvestment || null,
53
+ apyPercentage: meta?.apyPercentage || null,
54
+ apy: meta?.apy || null,
55
+ defaultAccounts: {
56
+ asset: meta?.defaultAccounts?.asset || null,
57
+ equity: meta?.defaultAccounts?.equity || null,
58
+ gain: meta?.defaultAccounts?.gain || null,
59
+ loss: meta?.defaultAccounts?.loss || null,
60
+ expense: meta?.defaultAccounts?.expense || null,
61
+ liability: meta?.defaultAccounts?.liability || null,
62
+ },
63
+ };
64
+ })));
65
+ }
66
+ balanceSheet(chainId) {
67
+ return this._query(null, () => this.pool.activeNetworks().pipe(map((networks) => {
68
+ const network = networks.find((n) => n.chainId === chainId);
69
+ if (!network) {
70
+ throw new Error(`No active network found for chain ID ${chainId}`);
71
+ }
72
+ return new BalanceSheet(this._root, network, this);
73
+ })));
74
+ }
75
+ deploymentPerNetwork() {
76
+ return this._query(null, () => this.pool.activeNetworks().pipe(switchMap((networks) => {
77
+ if (networks.length === 0)
78
+ return of([]);
79
+ return combineLatest(networks.map((network) => combineLatest([
80
+ this._share(network.chainId).pipe(catchError(() => of(null))),
81
+ this._restrictionManager(network.chainId).pipe(catchError(() => of(null))),
82
+ of(network),
83
+ ])));
84
+ }), map((data) => data
85
+ .filter(([, restrictionManager]) => restrictionManager != null)
86
+ .map(([share, restrictionManager, network]) => ({
87
+ chainId: network.chainId,
88
+ shareTokenAddress: share,
89
+ restrictionManagerAddress: restrictionManager,
90
+ })))));
91
+ }
92
+ navPerNetwork() {
93
+ return this._query(null, () => this.pool.currency().pipe(switchMap((poolCurrency) => this._root._queryIndexer(`query ($scId: String!) {
94
+ tokenInstances(where: { tokenId: $scId }) {
95
+ items {
96
+ totalIssuance
97
+ tokenPrice
98
+ address
99
+ blockchain {
100
+ id
101
+ }
102
+ }
103
+ }
104
+ }`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
105
+ chainId: Number(item.blockchain.id),
106
+ totalIssuance: new Balance(item.totalIssuance, poolCurrency.decimals),
107
+ pricePerShare: new Price(item.tokenPrice),
108
+ nav: new Balance(item.totalIssuance, poolCurrency.decimals).mul(new Price(item.tokenPrice)),
109
+ address: item.address,
110
+ }))))));
111
+ }
112
+ /**
113
+ * Query the vaults of the share class.
114
+ * @param chainId The optional chain ID to query the vaults on.
115
+ * @param includeUnlinked Whether to include unlinked vaults.
116
+ * @returns Vaults of the share class.
117
+ */
118
+ vaults(chainId, includeUnlinked = false) {
119
+ return this._query(null, () => this._allVaults().pipe(map((allVaults) => {
120
+ const vaults = allVaults.filter((vault) => {
121
+ if (chainId && vault.chainId !== chainId)
122
+ return false;
123
+ if (!includeUnlinked && vault.status === 'Unlinked')
124
+ return false;
125
+ return true;
126
+ });
127
+ return vaults.map((vault) => new Vault(this._root, new PoolNetwork(this._root, this.pool, vault.chainId), this, vault.assetAddress, vault.address, vault.assetId));
128
+ })));
129
+ }
130
+ /**
131
+ * Query all the balances of the share class (from BalanceSheet and Holdings).
132
+ */
133
+ balances(chainId) {
134
+ return this._query(null, () => combineLatest([this._balances(), this.pool.currency()]).pipe(switchMap(([res, poolCurrency]) => {
135
+ if (res.length === 0) {
136
+ return of([]);
137
+ }
138
+ const items = res.filter((item) => Number(item.asset.blockchain.id) === chainId || !chainId);
139
+ if (items.length === 0)
140
+ return of([]);
141
+ return combineLatest([
142
+ combineLatest(items.map((holding) => {
143
+ if (!holding.holding)
144
+ return of(null);
145
+ const assetId = new AssetId(holding.assetId);
146
+ return this._holding(assetId);
147
+ })),
148
+ combineLatest(items.map((holding) => {
149
+ const assetId = new AssetId(holding.assetId);
150
+ return this._balance(Number(holding.asset.blockchain.id), {
151
+ address: holding.asset.address,
152
+ assetTokenId: BigInt(holding.asset.assetTokenId),
153
+ id: assetId,
154
+ decimals: holding.asset.decimals,
155
+ });
156
+ })),
157
+ ]).pipe(map(([holdings, balances]) => items.map((data, i) => {
158
+ const holding = holdings[i];
159
+ const balance = balances[i];
160
+ // If the holding hasn't been initialized yet, the price is 1
161
+ const price = holding ? balance.price : Price.fromFloat(1);
162
+ const value = Balance.fromFloat(balance.amount.toDecimal().mul(price.toDecimal()), poolCurrency.decimals);
163
+ return {
164
+ assetId: new AssetId(data.assetId),
165
+ amount: balance.amount,
166
+ value,
167
+ price,
168
+ asset: {
169
+ decimals: data.asset.decimals,
170
+ address: data.asset.address,
171
+ tokenId: BigInt(data.asset.assetTokenId),
172
+ name: data.asset.name,
173
+ symbol: data.asset.symbol,
174
+ chainId: Number(data.asset.blockchain.id),
175
+ },
176
+ holding: holding && {
177
+ valuation: holding.valuation,
178
+ amount: holding.amount,
179
+ value: holding.value,
180
+ isLiability: holding.isLiability,
181
+ accounts: holding.accounts,
182
+ },
183
+ };
184
+ })));
185
+ })));
186
+ }
187
+ /**
188
+ * Get the pending and approved amounts for deposits and redemptions for each asset.
189
+ */
190
+ pendingAmounts() {
191
+ return this._query(null, () => this._allVaults().pipe(map((vaults) => vaults.filter((vault) => vault.status === 'Linked')), switchMap((vaults) => {
192
+ if (vaults.length === 0) {
193
+ return of([]);
194
+ }
195
+ return combineLatest(vaults.map((vault) => this._epoch(vault.assetId))).pipe(map((epochs) => {
196
+ return epochs.map((epoch, i) => {
197
+ const vault = vaults[i];
198
+ return {
199
+ assetId: vault.assetId,
200
+ chainId: vault.chainId,
201
+ ...epoch,
202
+ };
203
+ });
204
+ }));
205
+ })));
206
+ }
207
+ /**
208
+ * Check if an address is a member of the share class.
209
+ * @param address Address to check
210
+ * @param chainId Chain ID of the network on which to check the member
211
+ */
212
+ member(address, chainId) {
213
+ const addr = address.toLowerCase();
214
+ return this._query(['member', addr, chainId], () => combineLatest([this._share(chainId), this._restrictionManager(chainId)]).pipe(switchMap(([share, restrictionManager]) => defer(async () => {
215
+ const res = await this._root.getClient(chainId).readContract({
216
+ address: restrictionManager,
217
+ abi: ABI.RestrictionManager,
218
+ functionName: 'isMember',
219
+ args: [share, addr],
220
+ });
221
+ return {
222
+ isMember: res[0],
223
+ validUntil: new Date(Number(res[1]) * 1000),
224
+ };
225
+ }).pipe(repeatOnEvents(this._root, {
226
+ address: restrictionManager,
227
+ eventName: 'UpdateMember',
228
+ filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
229
+ }, chainId), catchError((e) => {
230
+ console.warn('Error checking member status', e);
231
+ // Freeze-only hook doesn't have isMember function
232
+ return of({
233
+ isMember: false,
234
+ validUntil: new Date(0),
235
+ });
236
+ })))));
237
+ }
238
+ /**
239
+ * Create a holding for a registered asset in the share class.
240
+ * @param assetId - Asset ID of the asset to create a holding for
241
+ * @param valuation - Valuation of the asset
242
+ * @param isLiability - Whether the holding is a liability or not
243
+ * @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
244
+ * Other accounts are expected to be provided or to exist in the pool metadata.
245
+ */
246
+ createHolding(assetId, valuation, isLiability, accounts) {
247
+ const self = this;
248
+ return this._transact(async function* (ctx) {
249
+ const [{ hub }, metadata] = await Promise.all([
250
+ self._root._protocolAddresses(self.pool.chainId),
251
+ self.pool.metadata(),
252
+ ]);
253
+ let data;
254
+ if (isLiability) {
255
+ const expenseAccount = accounts[AccountType.Expense] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.expense;
256
+ const liabilityAccount = accounts[AccountType.Liability] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.liability;
257
+ if (liabilityAccount === undefined) {
258
+ throw new Error('Missing required accounts for liability creation');
259
+ }
260
+ if (expenseAccount) {
261
+ data = encodeFunctionData({
262
+ abi: ABI.Hub,
263
+ functionName: 'initializeLiability',
264
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, expenseAccount, liabilityAccount],
265
+ });
266
+ }
267
+ else {
268
+ const newExpenseAccount = await self._getFreeAccountId();
269
+ const createAccountData = encodeFunctionData({
270
+ abi: ABI.Hub,
271
+ functionName: 'createAccount',
272
+ args: [self.pool.id.raw, newExpenseAccount, true],
273
+ });
274
+ const initHoldingData = encodeFunctionData({
275
+ abi: ABI.Hub,
276
+ functionName: 'initializeLiability',
277
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, newExpenseAccount, liabilityAccount],
278
+ });
279
+ data = [createAccountData, initHoldingData];
280
+ }
281
+ }
282
+ else {
283
+ const assetAccount = accounts[AccountType.Asset] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.asset;
284
+ const equityAccount = accounts[AccountType.Equity] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.equity;
285
+ const gainAccount = accounts[AccountType.Gain] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.gain;
286
+ const lossAccount = accounts[AccountType.Loss] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.loss;
287
+ if (equityAccount === undefined || gainAccount === undefined || lossAccount === undefined) {
288
+ throw new Error('Missing required accounts for holding creation');
289
+ }
290
+ if (assetAccount) {
291
+ data = encodeFunctionData({
292
+ abi: ABI.Hub,
293
+ functionName: 'initializeHolding',
294
+ args: [
295
+ self.pool.id.raw,
296
+ self.id.raw,
297
+ assetId.raw,
298
+ valuation,
299
+ assetAccount,
300
+ equityAccount,
301
+ gainAccount,
302
+ lossAccount,
303
+ ],
304
+ });
305
+ }
306
+ else {
307
+ const newAssetAccount = await self._getFreeAccountId();
308
+ const createAccountData = encodeFunctionData({
309
+ abi: ABI.Hub,
310
+ functionName: 'createAccount',
311
+ args: [self.pool.id.raw, newAssetAccount, false],
312
+ });
313
+ const initHoldingData = encodeFunctionData({
314
+ abi: ABI.Hub,
315
+ functionName: 'initializeHolding',
316
+ args: [
317
+ self.pool.id.raw,
318
+ self.id.raw,
319
+ assetId.raw,
320
+ valuation,
321
+ newAssetAccount,
322
+ equityAccount,
323
+ gainAccount,
324
+ lossAccount,
325
+ ],
326
+ });
327
+ data = [createAccountData, initHoldingData];
328
+ }
329
+ }
330
+ yield* wrapTransaction('Create holding', ctx, {
331
+ contract: hub,
332
+ data,
333
+ });
334
+ }, this.pool.chainId);
335
+ }
336
+ updateSharePrice(pricePerShare) {
337
+ const self = this;
338
+ return this._transact(async function* (ctx) {
339
+ const [{ hub }, activeNetworks] = await Promise.all([
340
+ self._root._protocolAddresses(self.pool.chainId),
341
+ self.pool.activeNetworks(),
342
+ ]);
343
+ const batch = [];
344
+ const messages = {};
345
+ function addMessage(centId, message) {
346
+ if (!messages[centId])
347
+ messages[centId] = [];
348
+ messages[centId].push(message);
349
+ }
350
+ batch.push(encodeFunctionData({
351
+ abi: ABI.Hub,
352
+ functionName: 'updateSharePrice',
353
+ args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
354
+ }));
355
+ await Promise.all(activeNetworks.map(async (activeNetwork) => {
356
+ const networkDetails = await activeNetwork.details();
357
+ const id = await self._root.id(activeNetwork.chainId);
358
+ const isShareClassInNetwork = networkDetails.activeShareClasses.find((shareClass) => shareClass.id.equals(self.id));
359
+ if (isShareClassInNetwork) {
360
+ batch.push(encodeFunctionData({
361
+ abi: ABI.Hub,
362
+ functionName: 'notifySharePrice',
363
+ args: [self.pool.id.raw, self.id.raw, id],
364
+ }));
365
+ addMessage(id, MessageType.NotifyPricePoolPerShare);
366
+ }
367
+ }));
368
+ yield* wrapTransaction('Update share price', ctx, {
369
+ contract: hub,
370
+ data: batch,
371
+ messages,
372
+ });
373
+ }, this.pool.chainId);
374
+ }
375
+ setMaxAssetPriceAge(assetId, maxPriceAge) {
376
+ const self = this;
377
+ return this._transact(async function* (ctx) {
378
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
379
+ yield* wrapTransaction('Set max asset price age', ctx, {
380
+ contract: hub,
381
+ data: encodeFunctionData({
382
+ abi: ABI.Hub,
383
+ functionName: 'setMaxAssetPriceAge',
384
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
385
+ }),
386
+ messages: {
387
+ [assetId.centrifugeId]: [MessageType.MaxAssetPriceAge],
388
+ },
389
+ });
390
+ }, this.pool.chainId);
391
+ }
392
+ setMaxSharePriceAge(chainId, maxPriceAge) {
393
+ const self = this;
394
+ return this._transact(async function* (ctx) {
395
+ const [{ hub }, id] = await Promise.all([
396
+ self._root._protocolAddresses(self.pool.chainId),
397
+ self._root.id(chainId),
398
+ ]);
399
+ yield* wrapTransaction('Set max share price age', ctx, {
400
+ contract: hub,
401
+ data: encodeFunctionData({
402
+ abi: ABI.Hub,
403
+ functionName: 'setMaxSharePriceAge',
404
+ args: [id, self.pool.id.raw, self.id.raw, BigInt(maxPriceAge)],
405
+ }),
406
+ messages: {
407
+ [id]: [MessageType.MaxSharePriceAge],
408
+ },
409
+ });
410
+ }, this.pool.chainId);
411
+ }
412
+ notifyAssetPrice(assetId) {
413
+ const self = this;
414
+ return this._transact(async function* (ctx) {
415
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
416
+ yield* wrapTransaction('Notify asset price', ctx, {
417
+ contract: hub,
418
+ data: encodeFunctionData({
419
+ abi: ABI.Hub,
420
+ functionName: 'notifyAssetPrice',
421
+ args: [self.pool.id.raw, self.id.raw, assetId.raw],
422
+ }),
423
+ messages: {
424
+ [assetId.centrifugeId]: [MessageType.NotifyPricePoolPerAsset],
425
+ },
426
+ });
427
+ }, this.pool.chainId);
428
+ }
429
+ notifySharePrice(chainId) {
430
+ const self = this;
431
+ return this._transact(async function* (ctx) {
432
+ const [{ hub }, id] = await Promise.all([
433
+ self._root._protocolAddresses(self.pool.chainId),
434
+ self._root.id(chainId),
435
+ ]);
436
+ yield* wrapTransaction('Notify share price', ctx, {
437
+ contract: hub,
438
+ data: encodeFunctionData({
439
+ abi: ABI.Hub,
440
+ functionName: 'notifySharePrice',
441
+ args: [self.pool.id.raw, self.id.raw, id],
442
+ }),
443
+ messages: {
444
+ [id]: [MessageType.NotifyPricePoolPerShare],
445
+ },
446
+ });
447
+ }, this.pool.chainId);
448
+ }
449
+ /**
450
+ * Approve deposits and issue shares for the given assets.
451
+ * @param assets - Array of assets to approve deposits and/or issue shares for
452
+ * `issuePricePerShare` can be a single price for all epochs or an array of prices for each epoch to be issued for.
453
+ */
454
+ approveDepositsAndIssueShares(assets) {
455
+ const self = this;
456
+ return this._transact(async function* (ctx) {
457
+ const [{ hub }, id, pendingAmounts, orders, maxBatchGasLimit] = await Promise.all([
458
+ self._root._protocolAddresses(self.pool.chainId),
459
+ self._root.id(self.pool.chainId),
460
+ self.pendingAmounts(),
461
+ firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
462
+ if (orders.outstandingInvests.length === 0)
463
+ return of([]);
464
+ return combineLatest(orders.outstandingInvests.map((order) => self._investorOrder(order.assetId, order.investor)));
465
+ }))),
466
+ self._root._maxBatchGasLimit(self.pool.chainId),
467
+ ]);
468
+ const assetsWithApprove = assets.filter((a) => a.approveAssetAmount).length;
469
+ const assetsWithIssue = assets.filter((a) => a.issuePricePerShare).length;
470
+ const gasLimitPerAsset = assetsWithIssue ? maxBatchGasLimit / BigInt(assetsWithIssue) : 0n;
471
+ const estimatePerMessage = 700000n;
472
+ const estimatePerMessageIfLocal = 360000n;
473
+ const ordersByAssetId = {};
474
+ orders.forEach((order) => {
475
+ if (order.pendingDeposit === 0n)
476
+ return;
477
+ const id = order.assetId.toString();
478
+ if (!ordersByAssetId[id])
479
+ ordersByAssetId[id] = [];
480
+ ordersByAssetId[id].push(order);
481
+ });
482
+ const uniqueAssets = new Set(assets.map((a) => a.assetId.toString()));
483
+ if (uniqueAssets.size !== assets.length) {
484
+ throw new Error('Assets array contains multiple entries for the same asset ID');
485
+ }
486
+ const batch = [];
487
+ const messages = {};
488
+ function addMessage(centId, message) {
489
+ if (!messages[centId])
490
+ messages[centId] = [];
491
+ messages[centId].push(message);
492
+ }
493
+ for (const asset of assets) {
494
+ const gasPerMessage = asset.assetId.centrifugeId === id ? estimatePerMessageIfLocal : estimatePerMessage;
495
+ let gasLeft = gasLimitPerAsset;
496
+ const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
497
+ if (!pending) {
498
+ throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
499
+ }
500
+ let nowDepositEpoch = pending?.depositEpoch;
501
+ if (asset.approveAssetAmount) {
502
+ if (asset.approveAssetAmount.gt(pending.pendingDeposit)) {
503
+ throw new Error(`Approve amount exceeds pending amount for asset "${asset.assetId.toString()}"`);
504
+ }
505
+ if (asset.approveAssetAmount.lte(0n)) {
506
+ throw new Error(`Approve amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
507
+ }
508
+ batch.push(encodeFunctionData({
509
+ abi: ABI.Hub,
510
+ functionName: 'approveDeposits',
511
+ args: [
512
+ self.pool.id.raw,
513
+ self.id.raw,
514
+ asset.assetId.raw,
515
+ nowDepositEpoch,
516
+ asset.approveAssetAmount.toBigInt(),
517
+ ],
518
+ }));
519
+ addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
520
+ gasLeft -= gasPerMessage;
521
+ nowDepositEpoch++;
522
+ }
523
+ const nowIssueEpoch = pending.issueEpoch;
524
+ if (asset.issuePricePerShare) {
525
+ if (nowIssueEpoch >= nowDepositEpoch)
526
+ throw new Error('Nothing to issue');
527
+ let i;
528
+ for (i = 0; i < nowDepositEpoch - nowIssueEpoch; i++) {
529
+ const price = Array.isArray(asset.issuePricePerShare)
530
+ ? asset.issuePricePerShare[i]
531
+ : asset.issuePricePerShare;
532
+ if (!price)
533
+ break;
534
+ if (price.lte(0n)) {
535
+ throw new Error(`Issue price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
536
+ }
537
+ batch.push(encodeFunctionData({
538
+ abi: ABI.Hub,
539
+ functionName: 'issueShares',
540
+ args: [self.pool.id.raw, self.id.raw, asset.assetId.raw, nowIssueEpoch + i, price.toBigInt(), 0n],
541
+ }));
542
+ addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
543
+ gasLeft -= gasPerMessage;
544
+ }
545
+ // If we've issued shares, also notify a number of invest orders
546
+ if (i) {
547
+ const claims = gasLeft > 0n ? Number(gasLeft / gasPerMessage) : 0;
548
+ const assetOrders = ordersByAssetId[asset.assetId.toString()];
549
+ assetOrders?.slice(0, claims).forEach((order) => {
550
+ if (order.pendingDeposit > 0n) {
551
+ batch.push(encodeFunctionData({
552
+ abi: ABI.Hub,
553
+ functionName: 'notifyDeposit',
554
+ args: [
555
+ self.pool.id.raw,
556
+ self.id.raw,
557
+ asset.assetId.raw,
558
+ addressToBytes32(order.investor),
559
+ order.maxDepositClaims + i, // +i to ensure the additional epochs that are being issued are included
560
+ ],
561
+ }));
562
+ addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
563
+ }
564
+ });
565
+ }
566
+ }
567
+ }
568
+ if (batch.length === 0) {
569
+ throw new Error('No approve or issue actions provided');
570
+ }
571
+ let title = 'Approve and issue';
572
+ if (assetsWithApprove === 0) {
573
+ title = 'Issue';
574
+ }
575
+ else if (assetsWithIssue === 0) {
576
+ title = 'Approve';
577
+ }
578
+ yield* wrapTransaction(title, ctx, {
579
+ contract: hub,
580
+ data: batch,
581
+ messages,
582
+ });
583
+ }, this.pool.chainId);
584
+ }
585
+ /**
586
+ * Approve redeems and revoke shares for the given assets.
587
+ * @param assets - Array of assets to approve redeems and/or revoke shares for
588
+ * `approveShareAmount` can be a single amount for all epochs or an array of amounts for each epoch to be revoked.
589
+ */
590
+ approveRedeemsAndRevokeShares(assets) {
591
+ const self = this;
592
+ return this._transact(async function* (ctx) {
593
+ const [{ hub }, id, pendingAmounts, orders, maxBatchGasLimit] = await Promise.all([
594
+ self._root._protocolAddresses(self.pool.chainId),
595
+ self._root.id(self.pool.chainId),
596
+ self.pendingAmounts(),
597
+ firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
598
+ if (orders.outstandingRedeems.length === 0)
599
+ return of([]);
600
+ return combineLatest(orders.outstandingRedeems.map((order) => self._investorOrder(order.assetId, order.investor)));
601
+ }))),
602
+ self._root._maxBatchGasLimit(self.pool.chainId),
603
+ ]);
604
+ const assetsWithApprove = assets.filter((a) => a.approveShareAmount).length;
605
+ const assetsWithRevoke = assets.filter((a) => a.revokePricePerShare).length;
606
+ const gasLimitPerAsset = assetsWithRevoke ? maxBatchGasLimit / BigInt(assetsWithRevoke) : 0n;
607
+ const estimatePerMessage = 700000n;
608
+ const estimatePerMessageIfLocal = 360000n;
609
+ const ordersByAssetId = {};
610
+ orders.forEach((order) => {
611
+ if (order.pendingRedeem === 0n)
612
+ return;
613
+ const id = order.assetId.toString();
614
+ if (!ordersByAssetId[id])
615
+ ordersByAssetId[id] = [];
616
+ ordersByAssetId[id].push(order);
617
+ });
618
+ const uniqueAssets = new Set(assets.map((a) => a.assetId.toString()));
619
+ if (uniqueAssets.size !== assets.length) {
620
+ throw new Error('Assets array contains multiple entries for the same asset ID');
621
+ }
622
+ const batch = [];
623
+ const messages = {};
624
+ function addMessage(centId, message) {
625
+ if (!messages[centId])
626
+ messages[centId] = [];
627
+ messages[centId].push(message);
628
+ }
629
+ for (const asset of assets) {
630
+ const gasPerMessage = asset.assetId.centrifugeId === id ? estimatePerMessageIfLocal : estimatePerMessage;
631
+ let gasLeft = gasLimitPerAsset;
632
+ const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
633
+ if (!pending) {
634
+ throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
635
+ }
636
+ let nowRedeemEpoch = pending.redeemEpoch;
637
+ if (asset.approveShareAmount) {
638
+ if (asset.approveShareAmount.gt(pending.pendingRedeem)) {
639
+ throw new Error(`Share amount exceeds pending redeem for asset "${asset.assetId.toString()}"`);
640
+ }
641
+ if (asset.approveShareAmount.lte(0n)) {
642
+ throw new Error(`Share amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
643
+ }
644
+ batch.push(encodeFunctionData({
645
+ abi: ABI.Hub,
646
+ functionName: 'approveRedeems',
647
+ args: [
648
+ self.pool.id.raw,
649
+ self.id.raw,
650
+ asset.assetId.raw,
651
+ nowRedeemEpoch,
652
+ asset.approveShareAmount.toBigInt(),
653
+ ],
654
+ }));
655
+ nowRedeemEpoch++;
656
+ }
657
+ const nowRevokeEpoch = pending.revokeEpoch;
658
+ if (asset.revokePricePerShare) {
659
+ if (nowRevokeEpoch >= nowRedeemEpoch)
660
+ throw new Error('Nothing to revoke');
661
+ let i;
662
+ for (i = 0; i < nowRedeemEpoch - nowRevokeEpoch; i++) {
663
+ const price = Array.isArray(asset.revokePricePerShare)
664
+ ? asset.revokePricePerShare[i]
665
+ : asset.revokePricePerShare;
666
+ if (!price)
667
+ break;
668
+ if (price.lte(0n)) {
669
+ throw new Error(`Revoke price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
670
+ }
671
+ batch.push(encodeFunctionData({
672
+ abi: ABI.Hub,
673
+ functionName: 'revokeShares',
674
+ args: [self.pool.id.raw, self.id.raw, asset.assetId.raw, nowRevokeEpoch + i, price.toBigInt(), 0n],
675
+ }));
676
+ addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
677
+ gasLeft -= gasPerMessage;
678
+ }
679
+ // If we've revoked shares, also notify a number of redeem orders
680
+ if (i) {
681
+ const claims = gasLeft > 0n ? Number(gasLeft / gasPerMessage) : 0;
682
+ const assetOrders = ordersByAssetId[asset.assetId.toString()];
683
+ assetOrders?.slice(0, claims).forEach((order) => {
684
+ if (order.pendingRedeem > 0n) {
685
+ batch.push(encodeFunctionData({
686
+ abi: ABI.Hub,
687
+ functionName: 'notifyRedeem',
688
+ args: [
689
+ self.pool.id.raw,
690
+ self.id.raw,
691
+ asset.assetId.raw,
692
+ addressToBytes32(order.investor),
693
+ order.maxRedeemClaims + 1, // +1 to ensure the order that's being issued is included
694
+ ],
695
+ }));
696
+ addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
697
+ }
698
+ });
699
+ }
700
+ }
701
+ }
702
+ if (batch.length === 0) {
703
+ throw new Error('No approve or revoke actions provided');
704
+ }
705
+ let title = 'Approve and revoke';
706
+ if (assetsWithApprove === 0) {
707
+ title = 'Revoke';
708
+ }
709
+ else if (assetsWithRevoke === 0) {
710
+ title = 'Approve';
711
+ }
712
+ yield* wrapTransaction(title, ctx, {
713
+ contract: hub,
714
+ data: batch,
715
+ messages,
716
+ });
717
+ }, this.pool.chainId);
718
+ }
719
+ /**
720
+ * Claim a deposit on the Hub side for the given asset and investor after the shares have been issued.
721
+ * This will send a message to the Spoke that will allow the investor to claim their shares.
722
+ */
723
+ claimDeposit(assetId, investor) {
724
+ const self = this;
725
+ return this._transact(async function* (ctx) {
726
+ const [{ hub }, investorOrder] = await Promise.all([
727
+ self._root._protocolAddresses(self.pool.chainId),
728
+ self._investorOrder(assetId, investor),
729
+ ]);
730
+ yield* wrapTransaction('Claim deposit', ctx, {
731
+ contract: hub,
732
+ data: encodeFunctionData({
733
+ abi: ABI.Hub,
734
+ functionName: 'notifyDeposit',
735
+ args: [
736
+ self.pool.id.raw,
737
+ self.id.raw,
738
+ assetId.raw,
739
+ addressToBytes32(investor),
740
+ investorOrder.maxDepositClaims,
741
+ ],
742
+ }),
743
+ messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
744
+ });
745
+ }, this.pool.chainId);
746
+ }
747
+ /**
748
+ * Claim a redemption on the Hub side for the given asset and investor after the shares have been revoked.
749
+ * This will send a message to the Spoke that will allow the investor to claim their redeemed currency.
750
+ */
751
+ claimRedeem(assetId, investor) {
752
+ const self = this;
753
+ return this._transact(async function* (ctx) {
754
+ const [{ hub }, investorOrder] = await Promise.all([
755
+ self._root._protocolAddresses(self.pool.chainId),
756
+ self._investorOrder(assetId, investor),
757
+ ]);
758
+ yield* wrapTransaction('Claim redeem', ctx, {
759
+ contract: hub,
760
+ data: encodeFunctionData({
761
+ abi: ABI.Hub,
762
+ functionName: 'notifyRedeem',
763
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, addressToBytes32(investor), investorOrder.maxRedeemClaims],
764
+ }),
765
+ messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
766
+ });
767
+ }, this.pool.chainId);
768
+ }
769
+ /**
770
+ * Update a member of the share class.
771
+ * @param address Address of the investor
772
+ * @param validUntil Time in seconds from Unix epoch until the investor is valid
773
+ * @param chainId Chain ID of the network on which to update the member
774
+ */
775
+ updateMember(address, validUntil, chainId) {
776
+ return this.updateMembers([{ address, validUntil, chainId }]);
777
+ }
778
+ /**
779
+ * Batch update a list of members of the share class.
780
+ * @param members Array of members to update, each with address, validUntil and chainId
781
+ * @param members.address Address of the investor
782
+ * @param members.validUntil Time in seconds from Unix epoch until the investor is valid
783
+ * @param members.chainId Chain ID of the network on which to update the member
784
+ */
785
+ updateMembers(members) {
786
+ const self = this;
787
+ return this._transact(async function* (ctx) {
788
+ const [{ hub }, ...ids] = await Promise.all([
789
+ self._root._protocolAddresses(self.pool.chainId),
790
+ ...members.map((m) => self._root.id(m.chainId)),
791
+ ]);
792
+ const batch = [];
793
+ const messages = {};
794
+ function addMessage(centId, message) {
795
+ if (!messages[centId])
796
+ messages[centId] = [];
797
+ messages[centId].push(message);
798
+ }
799
+ members.forEach((member, index) => {
800
+ const id = ids[index];
801
+ if (!id) {
802
+ return;
803
+ }
804
+ batch.push(encodeFunctionData({
805
+ abi: ABI.Hub,
806
+ functionName: 'updateRestriction',
807
+ args: [
808
+ self.pool.id.raw,
809
+ self.id.raw,
810
+ id,
811
+ encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(member.address), BigInt(member.validUntil)]),
812
+ 0n,
813
+ ],
814
+ }));
815
+ addMessage(id, MessageType.UpdateRestriction);
816
+ });
817
+ if (batch.length === 0) {
818
+ throw new Error('No data to update members');
819
+ }
820
+ yield* wrapTransaction(`Update member${batch.length > 1 ? 's' : ''}`, ctx, {
821
+ contract: hub,
822
+ data: batch,
823
+ messages,
824
+ });
825
+ }, this.pool.chainId);
826
+ }
827
+ /**
828
+ * Retrieve holders of the share class.
829
+ */
830
+ holders() {
831
+ return this._query(null, () => combineLatest([
832
+ this._root._deployments(),
833
+ this.pool.currency(),
834
+ this._investorOrders(),
835
+ this._tokenInstancePositions(),
836
+ ]).pipe(map(([deployments, poolCurrency, { outstandingInvests, outstandingRedeems }, { items: tokenInstancePositions, assets },]) => {
837
+ const chainsById = new Map(deployments.blockchains.items.map((chain) => [chain.centrifugeId, chain.id]));
838
+ return tokenInstancePositions.map((position) => {
839
+ const chainId = Number(chainsById.get(position.centrifugeId));
840
+ const outstandingInvest = outstandingInvests.find((order) => order.investor === position.accountAddress);
841
+ const outstandingRedeem = outstandingRedeems.find((order) => order.investor === position.accountAddress);
842
+ const assetId = outstandingInvest?.assetId.toString();
843
+ const assetDecimals = assets.find((asset) => asset.id === assetId)?.decimals ?? 18;
844
+ return {
845
+ address: position.accountAddress,
846
+ holdings: new Balance(position.balance, poolCurrency.decimals),
847
+ isFrozen: position.isFrozen,
848
+ chainId,
849
+ outstandingInvest: outstandingInvest
850
+ ? new Balance(outstandingInvest.pendingAmount, assetDecimals).scale(poolCurrency.decimals)
851
+ : new Balance(0n, poolCurrency.decimals),
852
+ amount: new Balance(outstandingInvest?.pendingAmount ?? 0n, assetDecimals),
853
+ outstandingRedeem: outstandingRedeem
854
+ ? new Balance(outstandingRedeem.pendingAmount, poolCurrency.decimals)
855
+ : new Balance(0n, poolCurrency.decimals),
856
+ };
857
+ });
858
+ })));
859
+ }
860
+ /** @internal */
861
+ _balances() {
862
+ return this._root._queryIndexer(`query ($scId: String!) {
863
+ holdingEscrows(where: { tokenId: $scId }) {
864
+ items {
865
+ holding {
866
+ updatedAt
867
+ }
868
+ assetAmount
869
+ assetPrice
870
+ assetId
871
+ asset {
872
+ decimals
873
+ assetTokenId
874
+ address
875
+ name
876
+ symbol
877
+ blockchain {
878
+ id
879
+ }
880
+ }
881
+ }
882
+ }
883
+ }`, {
884
+ scId: this.id.raw,
885
+ }, (data) => data.holdingEscrows.items);
886
+ }
887
+ /** @internal */
888
+ _holding(assetId) {
889
+ return this._query(['holding', assetId.toString()], () => combineLatest([
890
+ this._root._protocolAddresses(this.pool.chainId),
891
+ this.pool.currency(),
892
+ this._root._assetDecimals(assetId, this.pool.chainId),
893
+ ]).pipe(switchMap(([{ holdings: holdingsAddr }, poolCurrency, assetDecimals]) => defer(async () => {
894
+ const holdings = getContract({
895
+ address: holdingsAddr,
896
+ abi: ABI.Holdings,
897
+ client: this._root.getClient(this.pool.chainId),
898
+ });
899
+ const [valuation, amount, value, isLiability, ...accounts] = await Promise.all([
900
+ holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
901
+ holdings.read.amount([this.pool.id.raw, this.id.raw, assetId.raw]),
902
+ holdings.read.value([this.pool.id.raw, this.id.raw, assetId.raw]),
903
+ holdings.read.isLiability([this.pool.id.raw, this.id.raw, assetId.raw]),
904
+ ...[
905
+ AccountType.Asset,
906
+ AccountType.Equity,
907
+ AccountType.Loss,
908
+ AccountType.Gain,
909
+ AccountType.Expense,
910
+ AccountType.Liability,
911
+ ].map((kind) => holdings.read.accountId([this.pool.id.raw, this.id.raw, assetId.raw, kind])),
912
+ ]);
913
+ return {
914
+ assetId,
915
+ assetDecimals,
916
+ valuation,
917
+ amount: new Balance(amount, assetDecimals),
918
+ value: new Balance(value, poolCurrency.decimals),
919
+ isLiability,
920
+ accounts: {
921
+ [AccountType.Asset]: accounts[0] || null,
922
+ [AccountType.Equity]: accounts[1] || null,
923
+ [AccountType.Loss]: accounts[2] || null,
924
+ [AccountType.Gain]: accounts[3] || null,
925
+ [AccountType.Expense]: accounts[4] || null,
926
+ [AccountType.Liability]: accounts[5] || null,
927
+ },
928
+ };
929
+ }).pipe(repeatOnEvents(this._root, {
930
+ address: holdingsAddr,
931
+ eventName: ['Increase', 'Decrease', 'Update', 'UpdateValuation'],
932
+ filter: (events) => {
933
+ return events.some((event) => {
934
+ return event.args.scId === this.id && event.args.assetId === assetId.raw;
935
+ });
936
+ },
937
+ }, this.pool.chainId)))));
938
+ }
939
+ /** @internal */
940
+ _balance(chainId, asset) {
941
+ return this._query(['balance', asset.id.toString()], () => combineLatest([this._root._protocolAddresses(chainId), this.pool.currency()]).pipe(switchMap(([addresses, poolCurrency]) => defer(async () => {
942
+ const client = this._root.getClient(chainId);
943
+ const [amountBn, priceBn] = await Promise.all([
944
+ client.readContract({
945
+ address: addresses.balanceSheet,
946
+ abi: ABI.BalanceSheet,
947
+ functionName: 'availableBalanceOf',
948
+ args: [this.pool.id.raw, this.id.raw, asset.address, BigInt(asset.assetTokenId ?? 0n)],
949
+ }),
950
+ client.readContract({
951
+ address: addresses.spoke,
952
+ abi: ABI.Spoke,
953
+ functionName: 'pricePoolPerAsset',
954
+ args: [this.pool.id.raw, this.id.raw, asset.id.raw, false],
955
+ }),
956
+ ]);
957
+ const amount = new Balance(amountBn, asset.decimals);
958
+ const price = new Price(priceBn);
959
+ const value = Balance.fromFloat(amount.toDecimal().mul(price.toDecimal()), poolCurrency.decimals);
960
+ return {
961
+ amount,
962
+ value,
963
+ price,
964
+ };
965
+ }).pipe(repeatOnEvents(this._root, {
966
+ address: [addresses.balanceSheet, addresses.spoke],
967
+ eventName: ['NoteDeposit', 'Deposit', 'Withdraw', 'UpdateAssetPrice'],
968
+ filter: (events) => {
969
+ return events.some((event) => event.args.scId === this.id.raw &&
970
+ // UpdateAssetPrice event
971
+ (event.args.assetId === asset.id.raw ||
972
+ // NoteDeposit, Deposit, Withdraw events
973
+ event.args.asset?.toLowerCase() === asset.address?.toLowerCase()));
974
+ },
975
+ }, chainId)))));
976
+ }
977
+ /** @internal */
978
+ _investorOrders() {
979
+ return this._root._queryIndexer(`query ($scId: String!) {
980
+ outstandingInvests(where: {tokenId: $scId}) {
981
+ items {
982
+ investor: account
983
+ assetId
984
+ queuedAmount
985
+ depositAmount
986
+ pendingAmount
987
+ }
988
+ }
989
+ outstandingRedeems(where: {tokenId: $scId}) {
990
+ items {
991
+ assetId
992
+ investor: account
993
+ queuedAmount
994
+ depositAmount
995
+ pendingAmount
996
+ }
997
+ }
998
+ }`, { scId: this.id.raw }, (data) => ({
999
+ outstandingInvests: data.outstandingInvests.items.map((item) => ({
1000
+ ...item,
1001
+ assetId: new AssetId(item.assetId),
1002
+ })),
1003
+ outstandingRedeems: data.outstandingRedeems.items.map((item) => ({
1004
+ ...item,
1005
+ assetId: new AssetId(item.assetId),
1006
+ })),
1007
+ }));
1008
+ }
1009
+ /** @internal */
1010
+ _investorOrder(assetId, investor) {
1011
+ return this._query(['investorOrder', assetId.toString(), investor.toLowerCase()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1012
+ const contract = getContract({
1013
+ address: shareClassManager,
1014
+ abi: ABI.ShareClassManager,
1015
+ client: this._root.getClient(this.pool.chainId),
1016
+ });
1017
+ const [maxDepositClaims, maxRedeemClaims, [pendingDeposit], [pendingRedeem]] = await Promise.all([
1018
+ contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
1019
+ contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
1020
+ contract.read.depositRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
1021
+ contract.read.redeemRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
1022
+ ]);
1023
+ return {
1024
+ assetId,
1025
+ investor,
1026
+ maxDepositClaims,
1027
+ maxRedeemClaims,
1028
+ pendingDeposit,
1029
+ pendingRedeem,
1030
+ };
1031
+ }).pipe(repeatOnEvents(this._root, {
1032
+ address: shareClassManager,
1033
+ eventName: [
1034
+ 'UpdateDepositRequest',
1035
+ 'UpdateRedeemRequest',
1036
+ 'ClaimDeposit',
1037
+ 'ClaimRedeem',
1038
+ 'ApproveDeposits',
1039
+ 'ApproveRedeems',
1040
+ ],
1041
+ filter: (events) => {
1042
+ return events.some((event) => event.args.scId === this.id.raw &&
1043
+ (event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
1044
+ },
1045
+ }, this.pool.chainId)))));
1046
+ }
1047
+ /** @internal */
1048
+ _allVaults() {
1049
+ return this._root._queryIndexer(`query ($scId: String!) {
1050
+ vaults(where: { tokenId: $scId }) {
1051
+ items {
1052
+ asset {
1053
+ id
1054
+ }
1055
+ address: id
1056
+ poolId
1057
+ assetAddress
1058
+ status
1059
+ blockchain {
1060
+ id
1061
+ }
1062
+ }
1063
+ }
1064
+ }`, { scId: this.id.raw }, (data) => data.vaults.items.map(({ blockchain, asset, ...rest }) => ({
1065
+ ...rest,
1066
+ chainId: Number(blockchain.id),
1067
+ assetId: new AssetId(asset.id),
1068
+ })));
1069
+ }
1070
+ /** @internal */
1071
+ _metadata() {
1072
+ return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1073
+ const [name, symbol] = await this._root.getClient(this.pool.chainId).readContract({
1074
+ address: shareClassManager,
1075
+ abi: ABI.ShareClassManager,
1076
+ functionName: 'metadata',
1077
+ args: [this.id.raw],
1078
+ });
1079
+ return {
1080
+ name,
1081
+ symbol,
1082
+ };
1083
+ }).pipe(repeatOnEvents(this._root, {
1084
+ address: shareClassManager,
1085
+ eventName: 'UpdateMetadata',
1086
+ filter: (events) => {
1087
+ return events.some((event) => {
1088
+ return event.args.scId === this.id;
1089
+ });
1090
+ },
1091
+ }, this.pool.chainId)))));
1092
+ }
1093
+ /** @internal */
1094
+ _metrics() {
1095
+ return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
1096
+ const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
1097
+ address: shareClassManager,
1098
+ abi: ABI.ShareClassManager,
1099
+ functionName: 'metrics',
1100
+ args: [this.id.raw],
1101
+ });
1102
+ return {
1103
+ totalIssuance: new Balance(totalIssuance, 18),
1104
+ pricePerShare: new Price(pricePerShare),
1105
+ };
1106
+ }).pipe(repeatOnEvents(this._root, {
1107
+ address: shareClassManager,
1108
+ eventName: [
1109
+ 'RevokeShares',
1110
+ 'IssueShares',
1111
+ 'RemoteIssueShares',
1112
+ 'RemoteRevokeShares',
1113
+ 'UpdateShareClass',
1114
+ ],
1115
+ filter: (events) => {
1116
+ return events.some((event) => {
1117
+ return event.args.scId === this.id.raw;
1118
+ });
1119
+ },
1120
+ }, this.pool.chainId)))));
1121
+ }
1122
+ /** @internal */
1123
+ _epochInvestOrders() {
1124
+ return this._query(null, () => this._root._queryIndexer(`query ($scId: String!) {
1125
+ epochInvestOrders(where: {tokenId: $scId, issuedAt: null, approvedAt_not: null}, limit: 1000) {
1126
+ items {
1127
+ approvedAt
1128
+ assetId
1129
+ index
1130
+ }
1131
+ }
1132
+ }`, { scId: this.id.raw }, (data) => {
1133
+ const ordersMap = new Map();
1134
+ data.epochInvestOrders.items.forEach((item) => {
1135
+ const key = item.assetId.toString();
1136
+ if (!ordersMap.has(key)) {
1137
+ ordersMap.set(key, []);
1138
+ }
1139
+ ordersMap.get(key)[item.index] = {
1140
+ approvedAt: item.approvedAt,
1141
+ assetId: item.assetId,
1142
+ index: item.index,
1143
+ };
1144
+ });
1145
+ return ordersMap;
1146
+ }));
1147
+ }
1148
+ /** @internal */
1149
+ _epochRedeemOrders() {
1150
+ return this._query(null, () => this._root._queryIndexer(`query ($scId: String!) {
1151
+ epochRedeemOrders(where: {tokenId: $scId, revokedAt: null, approvedAt_not: null}, limit: 1000) {
1152
+ items {
1153
+ approvedAt
1154
+ assetId
1155
+ index
1156
+ }
1157
+ }
1158
+ }`, { scId: this.id.raw }, (data) => {
1159
+ const ordersMap = new Map();
1160
+ data.epochRedeemOrders.items.forEach((item) => {
1161
+ const key = item.assetId.toString();
1162
+ if (!ordersMap.has(key)) {
1163
+ ordersMap.set(key, []);
1164
+ }
1165
+ ordersMap.get(key)[item.index] = {
1166
+ approvedAt: item.approvedAt,
1167
+ assetId: item.assetId,
1168
+ index: item.index,
1169
+ };
1170
+ });
1171
+ return ordersMap;
1172
+ }));
1173
+ }
1174
+ /** @internal */
1175
+ _epoch(assetId) {
1176
+ return this._query(['epoch', assetId.toString()], () => combineLatest([
1177
+ this._root._protocolAddresses(this.pool.chainId),
1178
+ this.pool.currency(),
1179
+ this._root._assetDecimals(assetId, this.pool.chainId),
1180
+ this._epochInvestOrders(),
1181
+ this._epochRedeemOrders(),
1182
+ ]).pipe(switchMap(([{ shareClassManager }, poolCurrency, assetDecimals, epochInvestOrders, epochRedeemOrders]) => defer(async () => {
1183
+ const scm = getContract({
1184
+ address: shareClassManager,
1185
+ abi: ABI.ShareClassManager,
1186
+ client: this._root.getClient(this.pool.chainId),
1187
+ });
1188
+ const [epoch, pendingDeposit, pendingRedeem] = await Promise.all([
1189
+ scm.read.epochId([this.id.raw, assetId.raw]),
1190
+ scm.read.pendingDeposit([this.id.raw, assetId.raw]),
1191
+ scm.read.pendingRedeem([this.id.raw, assetId.raw]),
1192
+ ]);
1193
+ const depositEpoch = epoch[0] + 1;
1194
+ const redeemEpoch = epoch[1] + 1;
1195
+ const issueEpoch = epoch[2] + 1;
1196
+ const revokeEpoch = epoch[3] + 1;
1197
+ const [depositEpochAmounts, redeemEpochAmount] = await Promise.all([
1198
+ Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.id.raw, assetId.raw, issueEpoch + i]))),
1199
+ Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.id.raw, assetId.raw, revokeEpoch + i]))),
1200
+ ]);
1201
+ const approvedDeposit = depositEpochAmounts.reduce((acc, amount) => acc + amount[1], 0n);
1202
+ const approvedRedeem = redeemEpochAmount.reduce((acc, amount) => acc + amount[1], 0n);
1203
+ return {
1204
+ depositEpoch,
1205
+ redeemEpoch,
1206
+ issueEpoch,
1207
+ revokeEpoch,
1208
+ pendingDeposit: new Balance(pendingDeposit, assetDecimals),
1209
+ pendingRedeem: new Balance(pendingRedeem, poolCurrency.decimals),
1210
+ pendingIssuancesTotal: new Balance(approvedDeposit, assetDecimals),
1211
+ pendingIssuances: depositEpochAmounts.map(([, amount], i) => ({
1212
+ amount: new Balance(amount, assetDecimals),
1213
+ approvedAt: epochInvestOrders.get(assetId.toString())?.[issueEpoch + i]?.approvedAt,
1214
+ epoch: issueEpoch + i,
1215
+ })),
1216
+ pendingRevocationsTotal: new Balance(approvedRedeem, poolCurrency.decimals),
1217
+ pendingRevocations: redeemEpochAmount.map(([, amount], i) => ({
1218
+ amount: new Balance(amount, poolCurrency.decimals),
1219
+ approvedAt: epochRedeemOrders.get(assetId.toString())?.[revokeEpoch + i]?.approvedAt,
1220
+ epoch: revokeEpoch + i,
1221
+ })),
1222
+ };
1223
+ }).pipe(repeatOnEvents(this._root, {
1224
+ address: shareClassManager,
1225
+ eventName: [
1226
+ 'ApproveDeposits',
1227
+ 'ApproveRedeems',
1228
+ 'IssueShares',
1229
+ 'RevokeShares',
1230
+ 'RemoteIssueShares',
1231
+ 'RemoteRevokeShares',
1232
+ 'UpdateDepositRequest',
1233
+ 'UpdateRedeemRequest',
1234
+ ],
1235
+ filter: (events) => {
1236
+ return events.some((event) => {
1237
+ return event.args.scId === this.id.raw;
1238
+ });
1239
+ },
1240
+ }, this.pool.chainId)))));
1241
+ }
1242
+ /** @internal */
1243
+ _updateContract(chainId, target, payload) {
1244
+ const self = this;
1245
+ return this._transact(async function* (ctx) {
1246
+ const [id, { hub }] = await Promise.all([
1247
+ self._root.id(chainId),
1248
+ self._root._protocolAddresses(self.pool.chainId),
1249
+ ]);
1250
+ yield* wrapTransaction('Update contract', ctx, {
1251
+ contract: hub,
1252
+ data: encodeFunctionData({
1253
+ abi: ABI.Hub,
1254
+ functionName: 'updateContract',
1255
+ args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(target), payload, 0n],
1256
+ }),
1257
+ messages: { [id]: [MessageType.UpdateContract] },
1258
+ });
1259
+ }, this.pool.chainId);
1260
+ }
1261
+ /** @internal */
1262
+ _share(chainId) {
1263
+ return this._query(null, () => this.pool.network(chainId).pipe(switchMap((network) => network._share(this.id))));
1264
+ }
1265
+ /** @internal */
1266
+ _restrictionManager(chainId) {
1267
+ return this._query(['restrictionManager', chainId], () => this._share(chainId).pipe(switchMap((share) => defer(async () => {
1268
+ const address = await this._root.getClient(chainId).readContract({
1269
+ address: share,
1270
+ abi: ABI.Currency,
1271
+ functionName: 'hook',
1272
+ });
1273
+ return address.toLowerCase();
1274
+ }))));
1275
+ }
1276
+ /** @internal */
1277
+ _getFreeAccountId() {
1278
+ return this._query(null, () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
1279
+ const id = Number(randomUint(32));
1280
+ if (triesLeft <= 0)
1281
+ return EMPTY;
1282
+ return defer(async () => {
1283
+ const exists = await this._root.getClient(this.pool.chainId).readContract({
1284
+ address: accounting,
1285
+ abi: ABI.Accounting,
1286
+ functionName: 'exists',
1287
+ args: [this.pool.id.raw, id],
1288
+ });
1289
+ return { accounting, id: exists ? null : id, triesLeft: triesLeft - 1 };
1290
+ });
1291
+ }), filter(({ id }) => !!id), map(({ id }) => id)));
1292
+ }
1293
+ /** @internal */
1294
+ _tokenInstancePositions() {
1295
+ return this._query(null, () => this._root
1296
+ ._queryIndexer(`query ($scId: String!) {
1297
+ tokenInstancePositions(where: { tokenId: $scId }, limit: 1000) {
1298
+ items {
1299
+ accountAddress
1300
+ centrifugeId
1301
+ balance
1302
+ isFrozen
1303
+ }
1304
+ }
1305
+
1306
+ assets{
1307
+ items {
1308
+ decimals
1309
+ id
1310
+ }
1311
+ }
1312
+ }`, { scId: this.id.raw })
1313
+ .pipe(map((data) => {
1314
+ return {
1315
+ items: data.tokenInstancePositions.items,
1316
+ assets: data.assets.items,
1317
+ };
1318
+ })));
1319
+ }
1320
+ }
1321
+ //# sourceMappingURL=ShareClass.js.map