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