@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
@@ -1,40 +1,35 @@
1
- import { concatWith, defaultIfEmpty, defer, filter, identity, isObservable, map, mergeMap, of, Subject, switchMap, using, } from 'rxjs';
1
+ import { combineLatest, concatWith, defaultIfEmpty, defer, filter, first, identity, isObservable, map, mergeMap, of, Subject, switchMap, timer, using, } from 'rxjs';
2
2
  import { fromFetch } from 'rxjs/fetch';
3
- import { createPublicClient, createWalletClient, custom, getContract, http, parseEventLogs, } from 'viem';
3
+ import { createPublicClient, createWalletClient, custom, encodeFunctionData, fallback, getContract, http, keccak256, parseAbi, toHex, } from 'viem';
4
4
  import { ABI } from './abi/index.js';
5
- import { Account } from './Account.js';
6
5
  import { chains } from './config/chains.js';
7
6
  import { PERMIT_TYPEHASH } from './constants.js';
8
- import { Pool } from './Pool.js';
9
- import { Currency } from './utils/BigInt.js';
7
+ import { Investor } from './entities/Investor.js';
8
+ import { Pool } from './entities/Pool.js';
9
+ import { emptyMessage, MessageType, } from './types/transaction.js';
10
+ import { Balance } from './utils/BigInt.js';
11
+ import { randomUint } from './utils/index.js';
12
+ import { createPinning, getUrlFromHash } from './utils/ipfs.js';
10
13
  import { hashKey } from './utils/query.js';
11
14
  import { makeThenable, repeatOnEvents, shareReplayWithDelayedReset } from './utils/rx.js';
12
- import { doTransaction, isLocalAccount } from './utils/transaction.js';
15
+ import { doTransaction, isLocalAccount, parseEventLogs, wrapTransaction, } from './utils/transaction.js';
16
+ import { AssetId, PoolId, ShareClassId } from './utils/types.js';
17
+ const PINNING_API_DEMO = 'https://europe-central2-peak-vista-185616.cloudfunctions.net/pinning-api-demo';
13
18
  const envConfig = {
14
19
  mainnet: {
15
- indexerUrl: 'https://subql.embrio.tech/',
16
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
17
- infuraKey: '8ed99a9a115349bbbc01dcf3a24edc96',
18
- defaultChain: 1,
20
+ indexerUrl: 'https://api.centrifuge.io',
19
21
  ipfsUrl: 'https://centrifuge.mypinata.cloud',
22
+ ...createPinning(PINNING_API_DEMO),
20
23
  },
21
- demo: {
22
- indexerUrl: 'https://api.subquery.network/sq/centrifuge/pools-demo-multichain',
23
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
24
- infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
25
- defaultChain: 11155111,
26
- ipfsUrl: 'https://centrifuge.mypinata.cloud',
27
- },
28
- dev: {
29
- indexerUrl: 'https://api.subquery.network/sq/centrifuge/pools-demo-multichain',
30
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
31
- infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
32
- defaultChain: 11155111,
24
+ testnet: {
25
+ indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
33
26
  ipfsUrl: 'https://centrifuge.mypinata.cloud',
27
+ ...createPinning(PINNING_API_DEMO),
34
28
  },
35
29
  };
36
30
  const defaultConfig = {
37
31
  environment: 'mainnet',
32
+ cache: true,
38
33
  };
39
34
  export class Centrifuge {
40
35
  #config;
@@ -43,13 +38,16 @@ export class Centrifuge {
43
38
  }
44
39
  #clients = new Map();
45
40
  getClient(chainId) {
46
- return this.#clients.get(chainId ?? this.config.defaultChain);
41
+ const client = this.#clients.get(chainId);
42
+ if (!client)
43
+ throw new Error(`No client found for chain ID "${chainId}"`);
44
+ return client;
47
45
  }
48
46
  get chains() {
49
47
  return [...this.#clients.keys()];
50
48
  }
51
49
  getChainConfig(chainId) {
52
- return this.getClient(chainId ?? this.config.defaultChain).chain;
50
+ return this.getClient(chainId).chain;
53
51
  }
54
52
  #signer = null;
55
53
  setSigner(signer) {
@@ -58,8 +56,9 @@ export class Centrifuge {
58
56
  get signer() {
59
57
  return this.#signer;
60
58
  }
59
+ #isBatching = new WeakSet();
61
60
  constructor(config = {}) {
62
- const defaultConfigForEnv = envConfig[config?.environment ?? 'mainnet'];
61
+ const defaultConfigForEnv = envConfig[config?.environment || 'mainnet'];
63
62
  this.#config = {
64
63
  ...defaultConfig,
65
64
  ...defaultConfigForEnv,
@@ -73,47 +72,253 @@ export class Centrifuge {
73
72
  if (!rpcUrl) {
74
73
  console.warn(`No rpcUrl defined for chain ${chain.id}. Using public RPC endpoint.`);
75
74
  }
76
- this.#clients.set(chain.id, createPublicClient({ chain, transport: http(rpcUrl), batch: { multicall: true } }));
75
+ this.#clients.set(chain.id, createPublicClient({
76
+ chain,
77
+ transport: Array.isArray(rpcUrl)
78
+ ? fallback(rpcUrl.map((url) => http(url)), {
79
+ rank: {
80
+ interval: 30_000,
81
+ sampleCount: 5,
82
+ },
83
+ })
84
+ : http(rpcUrl),
85
+ batch: { multicall: true },
86
+ pollingInterval: this.#config.pollingInterval,
87
+ cacheTime: 100,
88
+ }));
77
89
  });
78
90
  }
79
- pool(id, metadataHash) {
80
- return this._query(null, () => of(new Pool(this, String(id), metadataHash)));
91
+ /**
92
+ * Create a new pool on the given chain.
93
+ * @param metadataInput - The metadata for the pool
94
+ * @param currencyCode - The currency code for the pool
95
+ * @param chainId - The chain ID to create the pool on
96
+ * @param counter - The pool counter, used to create a unique pool ID (uint48)
97
+ */
98
+ createPool(metadataInput, currencyCode = 840, chainId, counter) {
99
+ const self = this;
100
+ return this._transact(async function* (ctx) {
101
+ const [addresses, id] = await Promise.all([self._protocolAddresses(chainId), self.id(chainId)]);
102
+ const poolId = PoolId.from(id, counter ?? randomUint(48));
103
+ const createPoolData = encodeFunctionData({
104
+ abi: ABI.Hub,
105
+ functionName: 'createPool',
106
+ args: [poolId.raw, ctx.signingAddress, BigInt(currencyCode)],
107
+ });
108
+ const scIds = Array.from({ length: metadataInput.shareClasses.length }, (_, i) => ShareClassId.from(poolId, i + 1));
109
+ const shareClassesById = {};
110
+ metadataInput.shareClasses.forEach((sc, index) => {
111
+ shareClassesById[scIds[index].raw] = {
112
+ minInitialInvestment: sc.minInvestment,
113
+ apyPercentage: sc.apyPercentage,
114
+ apy: sc.apy,
115
+ defaultAccounts: sc.defaultAccounts,
116
+ };
117
+ });
118
+ const formattedMetadata = {
119
+ version: 1,
120
+ pool: {
121
+ name: metadataInput.poolName,
122
+ icon: metadataInput.poolIcon,
123
+ asset: {
124
+ class: metadataInput.assetClass,
125
+ subClass: metadataInput.subAssetClass,
126
+ },
127
+ issuer: {
128
+ name: metadataInput.issuerName,
129
+ repName: metadataInput.issuerRepName,
130
+ description: metadataInput.issuerDescription,
131
+ email: metadataInput.email,
132
+ logo: metadataInput.issuerLogo,
133
+ shortDescription: metadataInput.issuerShortDescription,
134
+ categories: metadataInput.issuerCategories,
135
+ },
136
+ poolStructure: metadataInput.poolStructure,
137
+ investorType: metadataInput.investorType,
138
+ links: {
139
+ executiveSummary: metadataInput.executiveSummary,
140
+ forum: metadataInput.forum,
141
+ website: metadataInput.website,
142
+ },
143
+ details: metadataInput.details,
144
+ status: 'open',
145
+ listed: metadataInput.listed ?? true,
146
+ poolRatings: metadataInput.poolRatings.length > 0 ? metadataInput.poolRatings : [],
147
+ reports: metadataInput.report
148
+ ? [
149
+ {
150
+ author: {
151
+ name: metadataInput.report.author.name,
152
+ title: metadataInput.report.author.title,
153
+ avatar: metadataInput.report.author.avatar,
154
+ },
155
+ uri: metadataInput.report.uri,
156
+ },
157
+ ]
158
+ : [],
159
+ },
160
+ shareClasses: shareClassesById,
161
+ onboarding: {
162
+ shareClasses: metadataInput.onboarding?.shareClasses || {},
163
+ taxInfoRequired: metadataInput.onboarding?.taxInfoRequired,
164
+ externalOnboardingUrl: metadataInput.onboarding?.externalOnboardingUrl,
165
+ },
166
+ };
167
+ const cid = await self.config.pinJson(formattedMetadata);
168
+ const setMetadataData = encodeFunctionData({
169
+ abi: ABI.Hub,
170
+ functionName: 'setPoolMetadata',
171
+ args: [poolId.raw, toHex(cid)],
172
+ });
173
+ const addScData = metadataInput.shareClasses.map((sc) => encodeFunctionData({
174
+ abi: ABI.Hub,
175
+ functionName: 'addShareClass',
176
+ args: [
177
+ poolId.raw,
178
+ sc.tokenName,
179
+ sc.symbolName,
180
+ sc.salt?.startsWith('0x') ? sc.salt : toHex(sc.salt ?? randomUint(256), { size: 32 }),
181
+ ],
182
+ }));
183
+ const accountIsDebitNormal = new Map();
184
+ const accountNumbers = [
185
+ ...new Set(metadataInput.shareClasses.flatMap((sc) => Object.entries(sc.defaultAccounts ?? {})
186
+ .filter(([k, v]) => {
187
+ if (!v)
188
+ return false;
189
+ if (['asset', 'expense'].includes(k)) {
190
+ if (accountIsDebitNormal.get(v) === false)
191
+ throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
192
+ accountIsDebitNormal.set(v, true);
193
+ }
194
+ else {
195
+ if (accountIsDebitNormal.get(v) === true)
196
+ throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
197
+ accountIsDebitNormal.set(v, false);
198
+ }
199
+ return true;
200
+ })
201
+ .map(([, v]) => v))),
202
+ ];
203
+ const createAccountsData = accountNumbers.map((account) => encodeFunctionData({
204
+ abi: ABI.Hub,
205
+ functionName: 'createAccount',
206
+ args: [poolId.raw, account, accountIsDebitNormal.get(account)],
207
+ }));
208
+ yield* doTransaction('Create pool', ctx, () => {
209
+ return ctx.walletClient.writeContract({
210
+ address: addresses.hub,
211
+ abi: ABI.Hub,
212
+ functionName: 'multicall',
213
+ args: [[createPoolData, setMetadataData, ...addScData, ...createAccountsData]],
214
+ });
215
+ });
216
+ }, chainId);
217
+ }
218
+ id(chainId) {
219
+ return this._query(['centrifugeId', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(({ messageDispatcher }) => {
220
+ return this.getClient(chainId).readContract({
221
+ address: messageDispatcher,
222
+ abi: ABI.MessageDispatcher,
223
+ functionName: 'localCentrifugeId',
224
+ });
225
+ })));
226
+ }
227
+ /**
228
+ * Get the existing pools on the different chains.
229
+ */
230
+ pools() {
231
+ return this._queryIndexer(`{
232
+ pools {
233
+ items {
234
+ id
235
+ blockchain {
236
+ id
237
+ }
238
+ }
239
+ }
240
+ }`, {}, (data) => {
241
+ return data.pools.items.map((pool) => {
242
+ const poolId = new PoolId(pool.id);
243
+ return new Pool(this, poolId.toString(), Number(pool.blockchain.id));
244
+ });
245
+ });
81
246
  }
82
- account(address, chainId) {
83
- return this._query(null, () => of(new Account(this, address, chainId ?? this.config.defaultChain)));
247
+ pool(id) {
248
+ return this._query(null, () => this.pools().pipe(map((pools) => {
249
+ const pool = pools.find((pool) => pool.id.equals(id));
250
+ if (!pool)
251
+ throw new Error(`Pool with id ${id} not found`);
252
+ return pool;
253
+ })));
84
254
  }
85
255
  /**
86
- * Get the metadata for an ERC20 token
256
+ * Get the metadata for an ERC20 or ERC6909 token
87
257
  * @param address - The token address
88
258
  * @param chainId - The chain ID
89
259
  */
90
- currency(address, chainId) {
260
+ currency(address, chainId, tokenId = 0n) {
91
261
  const curAddress = address.toLowerCase();
92
- const cid = chainId ?? this.config.defaultChain;
93
- return this._query(['currency', curAddress, cid], () => defer(async () => {
94
- const contract = getContract({
95
- address: curAddress,
96
- abi: ABI.Currency,
97
- client: this.getClient(cid),
98
- });
99
- const [decimals, name, symbol, supportsPermit] = await Promise.all([
100
- contract.read.decimals(),
101
- contract.read.name(),
102
- contract.read.symbol(),
103
- contract.read.PERMIT_TYPEHASH()
104
- .then((hash) => hash === PERMIT_TYPEHASH)
105
- .catch(() => false),
106
- ]);
262
+ return this._query(['currency', curAddress, chainId, tokenId], () => defer(async () => {
263
+ let decimals, name, symbol, supportsPermit;
264
+ if (tokenId) {
265
+ const contract = getContract({
266
+ address: curAddress,
267
+ abi: ABI.ERC6909,
268
+ client: this.getClient(chainId),
269
+ });
270
+ [decimals, name, symbol] = await Promise.all([
271
+ contract.read.decimals([tokenId]),
272
+ contract.read.name([tokenId]),
273
+ contract.read.symbol([tokenId]),
274
+ ]);
275
+ supportsPermit = false;
276
+ }
277
+ else {
278
+ const contract = getContract({
279
+ address: curAddress,
280
+ abi: ABI.Currency,
281
+ client: this.getClient(chainId),
282
+ });
283
+ [decimals, name, symbol, supportsPermit] = await Promise.all([
284
+ contract.read.decimals(),
285
+ contract.read.name(),
286
+ contract.read.symbol(),
287
+ contract.read
288
+ .PERMIT_TYPEHASH()
289
+ .then((hash) => hash === PERMIT_TYPEHASH)
290
+ .catch(() => false),
291
+ ]);
292
+ }
107
293
  return {
108
294
  address: curAddress,
295
+ tokenId,
109
296
  decimals,
110
297
  name,
111
298
  symbol,
112
- chainId: cid,
299
+ chainId,
113
300
  supportsPermit,
114
301
  };
115
302
  }));
116
303
  }
304
+ /**
305
+ * Get the asset currency details for a given asset ID
306
+ * @param assetId - The asset ID to query
307
+ */
308
+ assetCurrency(assetId) {
309
+ return this._query(['asset', assetId.toString()], () => this._idToChain(assetId.centrifugeId).pipe(switchMap((chainId) => this._protocolAddresses(chainId).pipe(map(({ spoke }) => ({ chainId, spoke })))), switchMap(async ({ spoke, chainId }) => {
310
+ const [assetAddress, tokenId] = await this.getClient(chainId).readContract({
311
+ address: spoke,
312
+ abi: ABI.Spoke,
313
+ functionName: 'idToAsset',
314
+ args: [assetId.raw],
315
+ });
316
+ return this.currency(assetAddress, chainId, tokenId);
317
+ })));
318
+ }
319
+ investor(address) {
320
+ return this._query(null, () => of(new Investor(this, address)));
321
+ }
117
322
  /**
118
323
  * Get the balance of an ERC20 token for a given owner.
119
324
  * @param currency - The token address
@@ -122,36 +327,219 @@ export class Centrifuge {
122
327
  */
123
328
  balance(currency, owner, chainId) {
124
329
  const address = owner.toLowerCase();
125
- const cid = chainId ?? this.config.defaultChain;
126
- return this._query(['balance', currency, owner, cid], () => {
127
- return this.currency(currency, cid).pipe(switchMap((currencyMeta) => defer(() => this.getClient(cid)
128
- .readContract({
330
+ return this._query(['balance', currency, owner, chainId], () => {
331
+ return this.currency(currency, chainId).pipe(switchMap((currencyMeta) => defer(async () => {
332
+ const val = await this.getClient(chainId).readContract({
333
+ address: currency,
334
+ abi: ABI.Currency,
335
+ functionName: 'balanceOf',
336
+ args: [address],
337
+ });
338
+ return {
339
+ balance: new Balance(val, currencyMeta.decimals),
340
+ currency: currencyMeta,
341
+ };
342
+ }).pipe(repeatOnEvents(this, {
129
343
  address: currency,
130
- abi: ABI.Currency,
131
- functionName: 'balanceOf',
132
- args: [address],
133
- })
134
- .then((val) => new Currency(val, currencyMeta.decimals))).pipe(repeatOnEvents(this, {
135
- address: currency,
136
- abi: ABI.Currency,
137
344
  eventName: 'Transfer',
138
345
  filter: (events) => {
139
346
  return events.some((event) => {
140
347
  return event.args.from?.toLowerCase() === address || event.args.to?.toLowerCase() === address;
141
348
  });
142
349
  },
143
- }, cid))));
350
+ }, chainId))));
144
351
  });
145
352
  }
353
+ /**
354
+ * Get the assets that exist on a given spoke chain that have been registered on a given hub chain.
355
+ * @param spokeChainId - The chain ID where the assets exist
356
+ * @param hubChainId - The chain ID where the assets should optionally be registered
357
+ */
358
+ assets(spokeChainId, hubChainId = spokeChainId) {
359
+ return this._query(null, () => combineLatest([this.id(spokeChainId), this.id(hubChainId)]).pipe(switchMap(([spokeCentId, hubCentId]) => this._queryIndexer(`query ($hubCentId: String!) {
360
+ assetRegistrations(where: { centrifugeId: $hubCentId }, limit: 1000) {
361
+ items {
362
+ assetId
363
+ asset {
364
+ centrifugeId
365
+ address
366
+ name
367
+ symbol
368
+ decimals
369
+ }
370
+ }
371
+ }
372
+ }`, { hubCentId: String(hubCentId) }).pipe(map((data) => {
373
+ return data.assetRegistrations.items
374
+ .filter((assetReg) => assetReg.asset && Number(assetReg.asset.centrifugeId) === spokeCentId)
375
+ .map((assetReg) => {
376
+ return {
377
+ id: new AssetId(assetReg.assetId),
378
+ address: assetReg.asset.address,
379
+ name: assetReg.asset.name,
380
+ symbol: assetReg.asset.symbol,
381
+ decimals: assetReg.asset.decimals,
382
+ };
383
+ });
384
+ })))));
385
+ }
386
+ /**
387
+ * Get the valuation addresses that can be used for holdings.
388
+ */
389
+ valuations(chainId) {
390
+ return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ identityValuation }) => {
391
+ return {
392
+ identityValuation,
393
+ };
394
+ })));
395
+ }
396
+ /**
397
+ * Get the restriction hook addresses that can be used for share tokens.
398
+ */
399
+ restrictionHooks(chainId) {
400
+ return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ freezeOnlyHook, redemptionRestrictionsHook, fullRestrictionsHook /* freelyTransferableHook */ }) => {
401
+ return {
402
+ freezeOnlyHook,
403
+ redemptionRestrictionsHook,
404
+ fullRestrictionsHook,
405
+ };
406
+ })));
407
+ }
408
+ /**
409
+ * Register an asset
410
+ * @param originChainId - The chain ID where the asset exists
411
+ * @param registerOnChainId - The chain ID where the asset should be registered
412
+ * @param assetAddress - The address of the asset to register
413
+ * @param tokenId - Optional token ID for ERC6909 assets
414
+ */
415
+ registerAsset(originChainId, registerOnChainId, assetAddress, tokenId = 0) {
416
+ const self = this;
417
+ return this._transact(async function* (ctx) {
418
+ const [addresses, id, estimate] = await Promise.all([
419
+ self._protocolAddresses(originChainId),
420
+ self.id(registerOnChainId),
421
+ self._estimate(originChainId, { chainId: registerOnChainId }, MessageType.RegisterAsset),
422
+ ]);
423
+ yield* doTransaction('Register asset', ctx, () => ctx.walletClient.writeContract({
424
+ address: addresses.spoke,
425
+ abi: ABI.Spoke,
426
+ functionName: 'registerAsset',
427
+ args: [id, assetAddress, BigInt(tokenId)],
428
+ value: estimate,
429
+ }));
430
+ }, originChainId);
431
+ }
432
+ /**
433
+ * Repay an underpaid batch of messages on the Gateway
434
+ */
435
+ repayBatch(fromChain, to, batch, extraPayment = 0n) {
436
+ const self = this;
437
+ return this._transact(async function* (ctx) {
438
+ const [addresses, toCentId] = await Promise.all([
439
+ self._protocolAddresses(fromChain),
440
+ 'chainId' in to ? self.id(to.chainId) : to.centId,
441
+ ]);
442
+ const client = self.getClient(fromChain);
443
+ const batchHash = keccak256(batch);
444
+ const [counter, gasLimit] = await client.readContract({
445
+ address: addresses.gateway,
446
+ abi: ABI.Gateway,
447
+ functionName: 'underpaid',
448
+ args: [toCentId, batchHash],
449
+ });
450
+ if (counter === 0n) {
451
+ throw new Error(`Batch is not underpaid and can't be repaid. Batch hash: "${batchHash}"`);
452
+ }
453
+ const estimate = await client.readContract({
454
+ address: addresses.multiAdapter,
455
+ abi: ABI.MultiAdapter,
456
+ functionName: 'estimate',
457
+ args: [toCentId, batch, gasLimit],
458
+ });
459
+ yield* doTransaction('Repay', ctx, () => ctx.walletClient.writeContract({
460
+ address: addresses.gateway,
461
+ abi: ABI.Gateway,
462
+ functionName: 'repay',
463
+ args: [toCentId, batch],
464
+ value: estimate + extraPayment,
465
+ }));
466
+ }, fromChain);
467
+ }
468
+ /**
469
+ * Retry a failed message on the destination chain
470
+ */
471
+ retryMessage(fromChain, toChain, message) {
472
+ const self = this;
473
+ return this._transact(async function* (ctx) {
474
+ const [addresses, fromCentId] = await Promise.all([self._protocolAddresses(toChain), self.id(fromChain)]);
475
+ yield* doTransaction('Retry', ctx, () => ctx.walletClient.writeContract({
476
+ address: addresses.gateway,
477
+ abi: ABI.Gateway,
478
+ functionName: 'retry',
479
+ args: [fromCentId, message],
480
+ }));
481
+ }, toChain);
482
+ }
483
+ /**
484
+ * Get the decimals of asset on the Hub side
485
+ * @internal
486
+ */
487
+ _assetDecimals(assetId, chainId) {
488
+ return this._query(['assetDecimals', assetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => this.getClient(chainId).readContract({
489
+ address: hubRegistry,
490
+ // Use inline ABI because of function overload
491
+ abi: parseAbi(['function decimals(uint128) view returns (uint8)']),
492
+ functionName: 'decimals',
493
+ args: [assetId.raw],
494
+ }))));
495
+ }
496
+ /**
497
+ * Get the allowance of an ERC20 or ERC6909 token.
498
+ * which is the contract that moves funds into the vault on behalf of the investor.
499
+ * @param owner - The address of the owner
500
+ * @param spender - The address of the spender
501
+ * @param chainId - The chain ID where the asset is located
502
+ * @param asset - The address of the asset
503
+ * @param tokenId - Optional token ID for ERC6909 assets
504
+ * @internal
505
+ */
506
+ _allowance(owner, spender, chainId, asset, tokenId) {
507
+ return this._query(['allowance', owner.toLowerCase(), spender.toLowerCase(), asset.toLowerCase(), chainId, tokenId], () => defer(async () => {
508
+ const client = this.getClient(chainId);
509
+ if (tokenId) {
510
+ return client.readContract({
511
+ address: asset,
512
+ abi: ABI.ERC6909,
513
+ functionName: 'allowance',
514
+ args: [owner, spender, tokenId],
515
+ });
516
+ }
517
+ return client.readContract({
518
+ address: asset,
519
+ abi: ABI.Currency,
520
+ functionName: 'allowance',
521
+ args: [owner, spender],
522
+ });
523
+ }).pipe(repeatOnEvents(this, {
524
+ address: asset,
525
+ eventName: ['Approval', 'Transfer'],
526
+ filter: (events) => {
527
+ return events.some((event) => {
528
+ return (event.args.owner?.toLowerCase() === owner.toLowerCase() ||
529
+ event.args.spender?.toLowerCase() === owner.toLowerCase() ||
530
+ event.args.from?.toLowerCase() === owner.toLowerCase());
531
+ });
532
+ },
533
+ }, chainId)));
534
+ }
146
535
  /**
147
536
  * Returns an observable of all events on a given chain.
148
537
  * @internal
149
538
  */
150
539
  _events(chainId) {
151
- const cid = chainId ?? this.config.defaultChain;
152
- return this._query(['events', cid], () => using(() => {
540
+ return this._query(['events', chainId], () => using(() => {
153
541
  const subject = new Subject();
154
- const unwatch = this.getClient(cid).watchEvent({
542
+ const unwatch = this.getClient(chainId).watchEvent({
155
543
  onLogs: (logs) => subject.next(logs),
156
544
  });
157
545
  return {
@@ -165,17 +553,13 @@ export class Centrifuge {
165
553
  * Returns an observable of events on a given chain, filtered by name(s) and address(es).
166
554
  * @internal
167
555
  */
168
- _filteredEvents(address, abi, eventName, chainId) {
169
- const addresses = (Array.isArray(address) ? address : [address]).map((a) => a.toLowerCase());
170
- const eventNames = Array.isArray(eventName) ? eventName : [eventName];
556
+ _filteredEvents(address, eventName, chainId) {
171
557
  return this._events(chainId).pipe(map((logs) => {
172
- const parsed = parseEventLogs({
173
- abi: abi.flat(),
174
- eventName: eventNames,
558
+ return parseEventLogs({
559
+ address,
560
+ eventName,
175
561
  logs,
176
562
  });
177
- const filtered = parsed.filter((log) => (addresses.length ? addresses.includes(log.address) : true));
178
- return filtered;
179
563
  }), filter((logs) => logs.length > 0));
180
564
  }
181
565
  /**
@@ -198,31 +582,27 @@ export class Centrifuge {
198
582
  },
199
583
  });
200
584
  }
201
- _queryIndexer(query, variables, postProcess) {
202
- return this._query([query, variables], () => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)), {
203
- valueCacheTime: 120,
204
- });
205
- }
206
- /**
207
- * @internal
208
- */
209
- _getIPFSObservable(hash) {
210
- return fromFetch(`${this.config.ipfsUrl}/ipfs/${hash}`, {
211
- method: 'GET',
212
- selector: async (res) => {
213
- if (!res.ok) {
214
- console.warn(`Failed to fetch IPFS data: ${res.statusText}`);
215
- }
216
- const data = await res.json();
217
- return data;
218
- },
219
- });
585
+ _queryIndexer(query, variables, postProcess, pollInterval = 120_000) {
586
+ return this._query([query, variables], () =>
587
+ // If subscribed, refetch every `pollInterval` milliseconds
588
+ timer(0, pollInterval).pipe(switchMap(() => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)))));
220
589
  }
221
590
  /**
222
591
  * @internal
223
592
  */
224
593
  _queryIPFS(hash) {
225
- return this._query([hash], () => this._getIPFSObservable(hash));
594
+ return this._query([hash], () => defer(async () => {
595
+ const url = getUrlFromHash(hash, this.#config.ipfsUrl);
596
+ if (!url) {
597
+ throw new Error(`Invalid IPFS hash: ${hash}`);
598
+ }
599
+ const res = await fetch(url);
600
+ if (!res.ok) {
601
+ throw new Error(`Error fetching IPFS hash ${hash}: ${res.statusText}`);
602
+ }
603
+ const data = (await res.json());
604
+ return data;
605
+ }));
226
606
  }
227
607
  #memoized = new Map();
228
608
  #memoizeWith(keys, callback) {
@@ -256,7 +636,6 @@ export class Centrifuge {
256
636
  * this,
257
637
  * {
258
638
  * address: tUSD,
259
- * abi: ABI.Currency,
260
639
  * eventName: 'Transfer',
261
640
  * },
262
641
  * chainId
@@ -289,10 +668,9 @@ export class Centrifuge {
289
668
  * const chainId = 1
290
669
  *
291
670
  * // Wrap an observable that only emits one value and then completes
292
- * //
293
671
  * const query = this._query(['balance', address, tUSD, chainId], () => {
294
672
  * return defer(() => fetchBalance(address, tUSD, chainId))
295
- * }, { valueCacheTime: 60 })
673
+ * }, { valueCacheTime: 60_000 })
296
674
  *
297
675
  * // Logs the current balance and updated balances whenever a new
298
676
  * const obs1 = query.subscribe(balance => console.log(balance))
@@ -316,14 +694,17 @@ export class Centrifuge {
316
694
  * @internal
317
695
  */
318
696
  _query(keys, observableCallback, options) {
697
+ const cache = options?.cache !== false && this.#config.cache !== false;
698
+ const obsCacheTime = options?.observableCacheTime ?? this.#config.pollingInterval ?? 4000;
319
699
  function get() {
320
700
  const sharedSubject = new Subject();
321
701
  function createShared() {
322
702
  const $shared = observableCallback().pipe(keys
323
703
  ? shareReplayWithDelayedReset({
324
- bufferSize: (options?.cache ?? true) ? 1 : 0,
325
- resetDelay: (options?.cache === false ? 0 : (options?.observableCacheTime ?? 60)) * 1000,
326
- windowTime: (options?.valueCacheTime ?? Infinity) * 1000,
704
+ bufferSize: cache ? 1 : 0,
705
+ resetDelay: cache ? obsCacheTime : 0,
706
+ // TODO: Fix valueCacheTime to not cause an infinite loop when the value is expired.
707
+ // windowTime: options?.valueCacheTime ?? Infinity,
327
708
  })
328
709
  : map((val) => val));
329
710
  sharedSubject.next($shared);
@@ -343,50 +724,9 @@ export class Centrifuge {
343
724
  return keys ? this.#memoizeWith(keys, get) : get();
344
725
  }
345
726
  /**
346
- * Executes a transaction on a given chain.
727
+ * Executes one or more transactions on a given chain.
347
728
  * When subscribed to, it emits status updates as it progresses.
348
- * When awaited, it returns the final confirmed if successful.
349
- * Will additionally prompt the user to switch chains if they're not on the correct chain.
350
- *
351
- * @example
352
- * ```ts
353
- * const tx = this._transact(
354
- * 'Transfer',
355
- * ({ walletClient }) =>
356
- * walletClient.writeContract({
357
- * address: '0xabc...123',
358
- * abi: ABI.Currency,
359
- * functionName: 'transfer',
360
- * args: ['0xdef...456', 1000000n],
361
- * }),
362
- * 1
363
- * )
364
- * tx.subscribe(status => console.log(status))
365
- *
366
- * // Results in something like the following values being emitted (assuming the user wasn't connected to mainnet):
367
- * // { type: 'SwitchingChain', chainId: 1 }
368
- * // { type: 'SigningTransaction', title: 'Transfer' }
369
- * // { type: 'TransactionPending', title: 'Transfer', hash: '0x123...abc' }
370
- * // { type: 'TransactionConfirmed', title: 'Transfer', hash: '0x123...abc', receipt: { ... } }
371
- * ```
372
- *
373
- * ```ts
374
- * const finalResult = await this._transact(...)
375
- * console.log(finalResult) // { type: 'TransactionConfirmed', title: 'Transfer', hash: '0x123...abc', receipt: { ... } }
376
- * ```
377
- *
378
- * @internal
379
- */
380
- _transact(title, transactionCallback, chainId) {
381
- return this._transactSequence(async function* (params) {
382
- const transaction = transactionCallback(params);
383
- yield* doTransaction(title, params.publicClient, () => transaction);
384
- }, chainId);
385
- }
386
- /**
387
- * Executes a sequence of transactions on a given chain.
388
- * When subscribed to, it emits status updates as it progresses.
389
- * When awaited, it returns the final confirmed if successful.
729
+ * When awaited, it returns the final confirmed result if successful.
390
730
  * Will additionally prompt the user to switch chains if they're not on the correct chain.
391
731
  *
392
732
  * @example
@@ -417,38 +757,49 @@ export class Centrifuge {
417
757
  *
418
758
  * @internal
419
759
  */
420
- _transactSequence(transactionCallback, chainId) {
421
- const targetChainId = chainId ?? this.config.defaultChain;
760
+ _transact(transactionCallback, chainId) {
422
761
  const self = this;
423
762
  async function* transact() {
763
+ let isBatching = false;
764
+ if (self.#isBatching.has($tx)) {
765
+ isBatching = true;
766
+ }
424
767
  const { signer } = self;
425
768
  if (!signer)
426
769
  throw new Error('Signer not set');
427
- const publicClient = self.getClient(targetChainId);
428
- const chain = self.getChainConfig(targetChainId);
429
- const bareWalletClient = isLocalAccount(signer)
430
- ? createWalletClient({ account: signer, chain, transport: http(self.#config.rpcUrls?.[chain.id]) })
770
+ const publicClient = self.getClient(chainId);
771
+ const chain = self.getChainConfig(chainId);
772
+ let walletClient = isLocalAccount(signer)
773
+ ? createWalletClient({
774
+ account: signer,
775
+ chain,
776
+ transport: http(),
777
+ })
431
778
  : createWalletClient({ transport: custom(signer) });
432
- const [address] = await bareWalletClient.getAddresses();
779
+ const [address] = await walletClient.getAddresses();
433
780
  if (!address)
434
781
  throw new Error('No account selected');
435
- const selectedChain = await bareWalletClient.getChainId();
436
- if (selectedChain !== targetChainId) {
437
- yield { type: 'SwitchingChain', chainId: targetChainId };
438
- await bareWalletClient.switchChain({ id: targetChainId });
782
+ if (!isBatching) {
783
+ const selectedChain = await walletClient.getChainId();
784
+ if (selectedChain !== chainId) {
785
+ yield { type: 'SwitchingChain', chainId };
786
+ await walletClient.switchChain({ id: chainId });
787
+ }
439
788
  }
440
789
  // Re-create the wallet client with the correct chain and account
441
790
  // Saves having to pass `account` and `chain` to every `writeContract` call
442
- const walletClient = isLocalAccount(signer)
443
- ? bareWalletClient
791
+ walletClient = isLocalAccount(signer)
792
+ ? walletClient
444
793
  : createWalletClient({ account: address, chain, transport: custom(signer) });
445
794
  const transaction = transactionCallback({
795
+ isBatching,
446
796
  signingAddress: address,
447
797
  chain,
448
- chainId: targetChainId,
798
+ chainId,
449
799
  publicClient,
450
800
  walletClient,
451
801
  signer,
802
+ root: self,
452
803
  });
453
804
  if (Symbol.asyncIterator in transaction) {
454
805
  yield* transaction;
@@ -461,7 +812,201 @@ export class Centrifuge {
461
812
  }
462
813
  }
463
814
  const $tx = defer(transact).pipe(mergeMap((d) => (isObservable(d) ? d : of(d))));
464
- return makeThenable($tx, true);
815
+ makeThenable($tx, true);
816
+ Object.assign($tx, {
817
+ chainId,
818
+ });
819
+ return $tx;
820
+ }
821
+ /**
822
+ * Batch multiple transactions together into a single transaction.
823
+ * It's not exposed, because it is somewhat limited and requires knowledge of internals.
824
+ * It only works when there's only a single transaction being done in the method.
825
+ * It only works for methods that wrap the transaction in `wrapTransaction`.
826
+ * It only works when the transactions are executed on the same contract on the same chain,
827
+ * and that contract supports multicall
828
+ * @internal
829
+ */
830
+ _experimental_batch(title, transactions) {
831
+ const chainIds = [...new Set(transactions.map((tx) => tx.chainId))];
832
+ if (chainIds.length !== 1) {
833
+ throw new Error(`Cannot batch transactions on different chains: ${chainIds.join(', ')}`);
834
+ }
835
+ for (const tx of transactions) {
836
+ this.#isBatching.add(tx);
837
+ }
838
+ return this._transact((ctx) => {
839
+ if (transactions.length === 0)
840
+ throw new Error('No transactions to batch');
841
+ return combineLatest(transactions.map((tx) => tx.pipe(first()))).pipe(switchMap(async function* (batches_) {
842
+ const batches = batches_;
843
+ if (!batches.every((b) => b.data && b.contract)) {
844
+ throw new Error('Not all transactions can be batched');
845
+ }
846
+ const value = batches.reduce((acc, b) => acc + (b.value ?? 0n), 0n);
847
+ const data = batches.map((b) => b.data).flat();
848
+ const messages = batches.reduce((acc, b) => {
849
+ if (b.messages) {
850
+ Object.entries(b.messages).forEach(([cid, types]) => {
851
+ const chainId = Number(cid);
852
+ if (!acc[chainId])
853
+ acc[chainId] = [];
854
+ acc[chainId].push(...types);
855
+ });
856
+ }
857
+ return acc;
858
+ }, {});
859
+ const contracts = [...new Set(batches.map((b) => b.contract))];
860
+ if (contracts.length !== 1) {
861
+ throw new Error(`Cannot batch transactions to different contracts: ${contracts.join(', ')}`);
862
+ }
863
+ yield* wrapTransaction(title, ctx, { data, value, contract: contracts[0], messages });
864
+ }));
865
+ }, chainIds[0]);
866
+ }
867
+ /** @internal */
868
+ _protocolAddresses(chainId) {
869
+ return this._query(null, () => this._deployments().pipe(map((data) => {
870
+ if (!this.chains.includes(chainId)) {
871
+ throw new Error(`Chain ID "${chainId}" not supported`);
872
+ }
873
+ const deployment = data.deployments.items.find((d) => Number(d.chainId) === chainId);
874
+ if (!deployment) {
875
+ throw new Error(`No protocol contracts found for chain ID "${chainId}"`);
876
+ }
877
+ return deployment;
878
+ })));
879
+ }
880
+ /** @internal */
881
+ _getQuote(valuationAddress, baseAmount, baseAssetId, quoteAssetId, chainId) {
882
+ return this._query(['getQuote', baseAmount, baseAssetId.toString(), quoteAssetId.toString()], () => timer(0, 60_000).pipe(switchMap(() => this._protocolAddresses(chainId)), switchMap(({ hubRegistry }) => defer(async () => {
883
+ const [quote, quoteDecimals] = await Promise.all([
884
+ this.getClient(chainId).readContract({
885
+ address: valuationAddress,
886
+ abi: ABI.Valuation,
887
+ functionName: 'getQuote',
888
+ args: [baseAmount.toBigInt(), baseAssetId.raw, quoteAssetId.raw],
889
+ }),
890
+ this.getClient(chainId).readContract({
891
+ address: hubRegistry,
892
+ // Use inline ABI because of function overload
893
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
894
+ functionName: 'decimals',
895
+ args: [quoteAssetId.raw],
896
+ }),
897
+ ]);
898
+ return new Balance(quote, quoteDecimals);
899
+ }))));
900
+ }
901
+ /**
902
+ * Estimates the gas cost needed to bridge the message from one chain to another,
903
+ * that results from a transaction
904
+ * @internal
905
+ */
906
+ _estimate(fromChain, to, messageType) {
907
+ return this._query(['estimate', fromChain, to, messageType], () => this._protocolAddresses(fromChain).pipe(switchMap(({ multiAdapter, gasService }) => {
908
+ const types = Array.isArray(messageType) ? messageType : [messageType];
909
+ return combineLatest([
910
+ 'chainId' in to ? this.id(to.chainId) : of(to.centId),
911
+ ...types.map((typeAndMaybeSubtype) => {
912
+ const type = typeof typeAndMaybeSubtype === 'number' ? typeAndMaybeSubtype : typeAndMaybeSubtype.type;
913
+ const subtype = typeof typeAndMaybeSubtype === 'number' ? undefined : typeAndMaybeSubtype.subtype;
914
+ const data = emptyMessage(type, subtype);
915
+ return this.getClient(fromChain).readContract({
916
+ address: gasService,
917
+ abi: ABI.GasService,
918
+ functionName: 'messageGasLimit',
919
+ args: [0, data],
920
+ });
921
+ }),
922
+ ]).pipe(switchMap(async ([toCentId, ...gasLimits]) => {
923
+ const estimate = await this.getClient(fromChain).readContract({
924
+ address: multiAdapter,
925
+ abi: ABI.MultiAdapter,
926
+ functionName: 'estimate',
927
+ args: [toCentId, '0x0', gasLimits.reduce((acc, val) => acc + val, 0n)],
928
+ });
929
+ return (estimate * 3n) / 2n; // Add 50% buffer to the estimate
930
+ }));
931
+ })));
932
+ }
933
+ /** @internal */
934
+ _maxBatchGasLimit(chainId) {
935
+ return this._query(['maxBatchGasLimit', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(async ({ gasService }) => {
936
+ try {
937
+ // `batchGasLimit` was renamed to `maxBatchGasLimit`, support both for backwards compatibility,
938
+ // until all chains are updated
939
+ return await this.getClient(chainId).readContract({
940
+ address: gasService,
941
+ abi: ABI.GasService,
942
+ functionName: 'maxBatchGasLimit',
943
+ args: [0],
944
+ });
945
+ }
946
+ catch {
947
+ return await this.getClient(chainId).readContract({
948
+ address: gasService,
949
+ abi: ABI.GasService,
950
+ functionName: 'batchGasLimit',
951
+ args: [0],
952
+ });
953
+ }
954
+ })));
955
+ }
956
+ /** @internal */
957
+ _idToChain(centrifugeId) {
958
+ return this._query(null, () => this._deployments().pipe(map((data) => {
959
+ const item = data.blockchains.items.find((b) => Number(b.centrifugeId) === centrifugeId);
960
+ if (!item)
961
+ throw new Error(`Chain with Centrifuge ID "${centrifugeId}" not found`);
962
+ return Number(item.id);
963
+ })));
964
+ }
965
+ /** @internal */
966
+ _deployments() {
967
+ return this._query(['deployments'], () => this._getIndexerObservable(`{
968
+ blockchains {
969
+ items {
970
+ centrifugeId
971
+ id
972
+ }
973
+ }
974
+ deployments {
975
+ items {
976
+ accounting
977
+ asyncRequestManager
978
+ asyncVaultFactory
979
+ axelarAdapter
980
+ balanceSheet
981
+ centrifugeId
982
+ chainId
983
+ freezeOnlyHook
984
+ fullRestrictionsHook
985
+ gasService
986
+ gateway
987
+ globalEscrow
988
+ guardian
989
+ holdings
990
+ hub
991
+ hubRegistry
992
+ identityValuation
993
+ messageDispatcher
994
+ messageProcessor
995
+ multiAdapter
996
+ poolEscrowFactory
997
+ redemptionRestrictionsHook
998
+ root
999
+ routerEscrow
1000
+ shareClassManager
1001
+ spoke
1002
+ syncDepositVaultFactory
1003
+ syncManager
1004
+ wormholeAdapter
1005
+ vaultRouter
1006
+ tokenFactory
1007
+ }
1008
+ }
1009
+ }`));
465
1010
  }
466
1011
  }
467
1012
  //# sourceMappingURL=Centrifuge.js.map