@centrifuge/sdk 0.0.0-alpha.5 → 0.0.0-alpha.51

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