@centrifuge/sdk 0.0.0-alpha.2 → 0.0.0-alpha.21
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 +58 -0
- package/dist/Centrifuge.d.ts +286 -259
- package/dist/Centrifuge.d.ts.map +1 -1
- package/dist/Centrifuge.js +538 -67
- 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 +487 -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/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 +88 -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 +8243 -8
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +32 -16
- package/dist/abi/index.js.map +1 -1
- package/dist/config/chains.d.ts +41 -0
- package/dist/config/chains.d.ts.map +1 -1
- package/dist/config/chains.js +11 -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/Entity.d.ts +8 -0
- package/dist/entities/Entity.d.ts.map +1 -0
- package/dist/{Entity.js → entities/Entity.js} +6 -1
- 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 +37 -0
- package/dist/entities/Investor.d.ts.map +1 -0
- package/dist/entities/Investor.js +29 -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 +89 -0
- package/dist/entities/Pool.d.ts.map +1 -0
- package/dist/entities/Pool.js +254 -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 +82 -0
- package/dist/entities/Pool.test.js.map +1 -0
- package/dist/entities/PoolNetwork.d.ts +63 -0
- package/dist/entities/PoolNetwork.d.ts.map +1 -0
- package/dist/entities/PoolNetwork.js +274 -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 +61 -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 +153 -0
- package/dist/entities/ShareClass.d.ts.map +1 -0
- package/dist/entities/ShareClass.js +833 -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 +109 -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/{Vault.js → entities/Vault.js} +217 -145
- 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 +277 -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 +5 -15
- 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 +65 -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 +13 -12
- 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 +5 -0
- package/dist/types/transaction.d.ts.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.map +1 -1
- package/dist/utils/transaction.js +21 -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 +11 -6
- 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 -235
- 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.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,833 @@
|
|
|
1
|
+
import { catchError, combineLatest, defer, EMPTY, expand, filter, map, of, switchMap } from 'rxjs';
|
|
2
|
+
import { encodeFunctionData, encodePacked, getAddress, getContract, parseAbi } from 'viem';
|
|
3
|
+
import { ABI } from '../abi/index.js';
|
|
4
|
+
import { AccountType } from '../types/holdings.js';
|
|
5
|
+
import { Balance, Price } from '../utils/BigInt.js';
|
|
6
|
+
import { addressToBytes32, randomUint } from '../utils/index.js';
|
|
7
|
+
import { repeatOnEvents } from '../utils/rx.js';
|
|
8
|
+
import { doTransaction } from '../utils/transaction.js';
|
|
9
|
+
import { AssetId, ShareClassId } from '../utils/types.js';
|
|
10
|
+
import { Entity } from './Entity.js';
|
|
11
|
+
import { PoolNetwork } from './PoolNetwork.js';
|
|
12
|
+
import { Vault } from './Vault.js';
|
|
13
|
+
/**
|
|
14
|
+
* Query and interact with a share class, which allows querying total issuance, NAV per share,
|
|
15
|
+
* and allows interactions related to asynchronous deposits and redemptions.
|
|
16
|
+
*/
|
|
17
|
+
export class ShareClass extends Entity {
|
|
18
|
+
pool;
|
|
19
|
+
id;
|
|
20
|
+
/** @internal */
|
|
21
|
+
constructor(_root, pool, id) {
|
|
22
|
+
const _id = id instanceof ShareClassId ? id : new ShareClassId(id);
|
|
23
|
+
super(_root, ['shareclass', _id.toString()]);
|
|
24
|
+
this.pool = pool;
|
|
25
|
+
this.id = _id;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Query the details of the share class.
|
|
29
|
+
* @returns The details of the share class, including name, symbol, total issuance, and NAV per share.
|
|
30
|
+
*/
|
|
31
|
+
details() {
|
|
32
|
+
return this._query(null, () => combineLatest([this._metrics(), this._metadata()]).pipe(map(([metrics, metadata]) => {
|
|
33
|
+
return {
|
|
34
|
+
id: this.id,
|
|
35
|
+
name: metadata.name,
|
|
36
|
+
symbol: metadata.symbol,
|
|
37
|
+
totalIssuance: metrics.totalIssuance,
|
|
38
|
+
pricePerShare: metrics.pricePerShare,
|
|
39
|
+
nav: metrics.totalIssuance.mul(metrics.pricePerShare),
|
|
40
|
+
};
|
|
41
|
+
})));
|
|
42
|
+
}
|
|
43
|
+
navPerNetwork() {
|
|
44
|
+
return this._root._queryIndexer(`query ($scId: String!) {
|
|
45
|
+
tokenInstances(where: { tokenId: $scId }) {
|
|
46
|
+
items {
|
|
47
|
+
totalIssuance
|
|
48
|
+
tokenPrice
|
|
49
|
+
blockchain {
|
|
50
|
+
id
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
|
|
55
|
+
chainId: Number(item.blockchain.id),
|
|
56
|
+
totalIssuance: new Balance(item.totalIssuance, 18), // TODO: Replace with pool currency decimals
|
|
57
|
+
pricePerShare: new Price(item.tokenPrice),
|
|
58
|
+
nav: new Balance(item.totalIssuance, 18).mul(new Price(item.tokenPrice)),
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Query the vaults of the share class.
|
|
63
|
+
* @param chainId The chain ID to query the vaults on.
|
|
64
|
+
* @returns The vaults of the share class on the given chain.
|
|
65
|
+
*/
|
|
66
|
+
vaults(chainId) {
|
|
67
|
+
if (!chainId) {
|
|
68
|
+
return this._root._queryIndexer(`query ($scId: String!) {
|
|
69
|
+
vaults(where: { tokenId: $scId }) {
|
|
70
|
+
items {
|
|
71
|
+
address: id
|
|
72
|
+
poolId
|
|
73
|
+
assetAddress
|
|
74
|
+
tokenId
|
|
75
|
+
blockchain {
|
|
76
|
+
id
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}`, { scId: this.id.raw }, (data) => data.vaults.items.map((item) => new Vault(this._root, new PoolNetwork(this._root, this.pool, Number(item.blockchain.id)), this, item.assetAddress, item.address)));
|
|
81
|
+
}
|
|
82
|
+
return this._query(null, () => new PoolNetwork(this._root, this.pool, chainId).vaults(this.id));
|
|
83
|
+
}
|
|
84
|
+
holdings() {
|
|
85
|
+
return this._query(null, () => this._root
|
|
86
|
+
._queryIndexer(`query ($scId: String!) {
|
|
87
|
+
holdings(where: { tokenId: $scId }) {
|
|
88
|
+
items {
|
|
89
|
+
assetRegistrationId
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}`, {
|
|
93
|
+
scId: this.id.raw,
|
|
94
|
+
})
|
|
95
|
+
.pipe(switchMap((res) => combineLatest(res.holdings.items.map((holding) => {
|
|
96
|
+
const assetId = new AssetId(holding.assetRegistrationId);
|
|
97
|
+
return this.holding(assetId);
|
|
98
|
+
})))));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Query a holding of the share class.
|
|
102
|
+
* @param assetId The asset ID
|
|
103
|
+
* @returns The details of the holding
|
|
104
|
+
*/
|
|
105
|
+
holding(assetId) {
|
|
106
|
+
return this._query(['holding', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ holdings: holdingsAddr, hubRegistry }) => defer(async () => {
|
|
107
|
+
const holdings = getContract({
|
|
108
|
+
address: holdingsAddr,
|
|
109
|
+
abi: ABI.Holdings,
|
|
110
|
+
client: this._root.getClient(this.pool.chainId),
|
|
111
|
+
});
|
|
112
|
+
const [valuation, amount, value, assetDecimals, isLiability, ...accounts] = await Promise.all([
|
|
113
|
+
holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
114
|
+
holdings.read.amount([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
115
|
+
holdings.read.value([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
116
|
+
this._root.getClient(this.pool.chainId).readContract({
|
|
117
|
+
address: hubRegistry,
|
|
118
|
+
// Use inline ABI because of function overload
|
|
119
|
+
abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
|
|
120
|
+
functionName: 'decimals',
|
|
121
|
+
args: [assetId.raw],
|
|
122
|
+
}),
|
|
123
|
+
holdings.read.isLiability([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
124
|
+
...[
|
|
125
|
+
AccountType.Asset,
|
|
126
|
+
AccountType.Equity,
|
|
127
|
+
AccountType.Loss,
|
|
128
|
+
AccountType.Gain,
|
|
129
|
+
AccountType.Expense,
|
|
130
|
+
AccountType.Liability,
|
|
131
|
+
].map((kind) => holdings.read.accountId([this.pool.id.raw, this.id.raw, assetId.raw, kind])),
|
|
132
|
+
]);
|
|
133
|
+
return {
|
|
134
|
+
assetId,
|
|
135
|
+
assetDecimals,
|
|
136
|
+
valuation,
|
|
137
|
+
amount: new Balance(amount, assetDecimals),
|
|
138
|
+
value: new Balance(value, 18), // TODO: Replace with pool currency decimals
|
|
139
|
+
isLiability,
|
|
140
|
+
accounts: {
|
|
141
|
+
[AccountType.Asset]: accounts[0] || null,
|
|
142
|
+
[AccountType.Equity]: accounts[1] || null,
|
|
143
|
+
[AccountType.Loss]: accounts[2] || null,
|
|
144
|
+
[AccountType.Gain]: accounts[3] || null,
|
|
145
|
+
[AccountType.Expense]: accounts[4] || null,
|
|
146
|
+
[AccountType.Liability]: accounts[5] || null,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
150
|
+
address: holdingsAddr,
|
|
151
|
+
abi: ABI.Holdings,
|
|
152
|
+
eventName: ['Increase', 'Decrease', 'Update', 'UpdateValuation'],
|
|
153
|
+
filter: (events) => {
|
|
154
|
+
return events.some((event) => {
|
|
155
|
+
return event.args.scId === this.id && event.args.assetId === assetId.raw;
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
}, this.pool.chainId)))));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the pending and approved amounts for deposits and redemptions for each asset.
|
|
162
|
+
*/
|
|
163
|
+
pendingAmounts() {
|
|
164
|
+
return this._query(null, () =>
|
|
165
|
+
// TODO: Simplify when indexer includes the asset ID in the Asset entity
|
|
166
|
+
// can then query the asset id on { vaults { asset { id } }}
|
|
167
|
+
this.vaults().pipe(switchMap((vaults) => this._assetIdsByAddress(vaults.map((vault) => vault._asset)).pipe(switchMap((assetIdsByAddress) => combineLatest(vaults.map((vault) => this._epoch(assetIdsByAddress[vault._asset]))).pipe(map((epochs) => {
|
|
168
|
+
return epochs.map((epoch, i) => {
|
|
169
|
+
const vault = vaults[i];
|
|
170
|
+
const assetId = assetIdsByAddress[vault._asset];
|
|
171
|
+
return {
|
|
172
|
+
assetId,
|
|
173
|
+
chainId: vault.chainId,
|
|
174
|
+
...epoch,
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
})))))));
|
|
178
|
+
}
|
|
179
|
+
investorOrder(assetId, investor) {
|
|
180
|
+
return this._query(['maxClaims', assetId.toString(), investor.toLowerCase()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
|
|
181
|
+
const contract = getContract({
|
|
182
|
+
address: shareClassManager,
|
|
183
|
+
abi: ABI.ShareClassManager,
|
|
184
|
+
client: this._root.getClient(this.pool.chainId),
|
|
185
|
+
});
|
|
186
|
+
const [maxDepositClaims, maxRedeemClaims] = await Promise.all([
|
|
187
|
+
contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
188
|
+
contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
189
|
+
]);
|
|
190
|
+
return {
|
|
191
|
+
maxDepositClaims,
|
|
192
|
+
maxRedeemClaims,
|
|
193
|
+
};
|
|
194
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
195
|
+
address: shareClassManager,
|
|
196
|
+
abi: ABI.ShareClassManager,
|
|
197
|
+
eventName: [
|
|
198
|
+
'UpdateDepositRequest',
|
|
199
|
+
'UpdateRedeemRequest',
|
|
200
|
+
'ClaimDeposit',
|
|
201
|
+
'ClaimRedeem',
|
|
202
|
+
'ApproveDeposits',
|
|
203
|
+
'ApproveRedeems',
|
|
204
|
+
],
|
|
205
|
+
filter: (events) => {
|
|
206
|
+
return events.some((event) => event.args.scId === this.id.raw &&
|
|
207
|
+
(event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
|
|
208
|
+
},
|
|
209
|
+
}, this.pool.chainId)))));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Check if an address is a member of the share class.
|
|
213
|
+
* @param address Address to check
|
|
214
|
+
* @param chainId Chain ID of the network on which to check the member
|
|
215
|
+
*/
|
|
216
|
+
member(address, chainId) {
|
|
217
|
+
const addr = address.toLowerCase();
|
|
218
|
+
return this._query(['member', addr, chainId], () => combineLatest([this._share(chainId), this._restrictionManager(chainId)]).pipe(switchMap(([share, restrictionManager]) => defer(async () => {
|
|
219
|
+
const res = await this._root.getClient(this.pool.chainId).readContract({
|
|
220
|
+
address: restrictionManager,
|
|
221
|
+
abi: ABI.RestrictionManager,
|
|
222
|
+
functionName: 'isMember',
|
|
223
|
+
args: [share, addr],
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
isMember: res[0],
|
|
227
|
+
validUntil: new Date(Number(res[1]) * 1000),
|
|
228
|
+
};
|
|
229
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
230
|
+
address: restrictionManager,
|
|
231
|
+
abi: ABI.RestrictionManager,
|
|
232
|
+
eventName: 'UpdateMember',
|
|
233
|
+
filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
|
|
234
|
+
}, chainId), catchError(() => {
|
|
235
|
+
// Freeze-only hook doesn't have isMember function
|
|
236
|
+
return of({
|
|
237
|
+
isMember: false,
|
|
238
|
+
validUntil: new Date(0),
|
|
239
|
+
});
|
|
240
|
+
})))));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a holding for a registered asset in the share class.
|
|
244
|
+
* @param assetId - Asset ID of the asset to create a holding for
|
|
245
|
+
* @param valuation - Valuation of the asset
|
|
246
|
+
* @param isLiability - Whether the holding is a liability or not
|
|
247
|
+
* @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
|
|
248
|
+
* Other accounts are expected to be provided or to exist in the pool metadata.
|
|
249
|
+
*/
|
|
250
|
+
createHolding(assetId, valuation, isLiability, accounts) {
|
|
251
|
+
const self = this;
|
|
252
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
253
|
+
const [{ hub }, metadata] = await Promise.all([
|
|
254
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
255
|
+
self.pool.metadata(),
|
|
256
|
+
]);
|
|
257
|
+
let tx;
|
|
258
|
+
if (isLiability) {
|
|
259
|
+
const expenseAccount = accounts[AccountType.Expense] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.expense;
|
|
260
|
+
const liabilityAccount = accounts[AccountType.Liability] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.liability;
|
|
261
|
+
if (liabilityAccount === undefined) {
|
|
262
|
+
throw new Error('Missing required accounts for liability creation');
|
|
263
|
+
}
|
|
264
|
+
if (expenseAccount) {
|
|
265
|
+
tx = walletClient.writeContract({
|
|
266
|
+
address: hub,
|
|
267
|
+
abi: ABI.Hub,
|
|
268
|
+
functionName: 'initializeLiability',
|
|
269
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, expenseAccount, liabilityAccount],
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
const newExpenseAccount = await self._getFreeAccountId();
|
|
274
|
+
const createAccountData = encodeFunctionData({
|
|
275
|
+
abi: ABI.Hub,
|
|
276
|
+
functionName: 'createAccount',
|
|
277
|
+
args: [self.pool.id.raw, newExpenseAccount, true],
|
|
278
|
+
});
|
|
279
|
+
const initHoldingData = encodeFunctionData({
|
|
280
|
+
abi: ABI.Hub,
|
|
281
|
+
functionName: 'initializeLiability',
|
|
282
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, newExpenseAccount, liabilityAccount],
|
|
283
|
+
});
|
|
284
|
+
tx = walletClient.writeContract({
|
|
285
|
+
address: hub,
|
|
286
|
+
abi: ABI.Hub,
|
|
287
|
+
functionName: 'multicall',
|
|
288
|
+
args: [[createAccountData, initHoldingData]],
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const assetAccount = accounts[AccountType.Asset] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.asset;
|
|
294
|
+
const equityAccount = accounts[AccountType.Equity] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.equity;
|
|
295
|
+
const gainAccount = accounts[AccountType.Gain] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.gain;
|
|
296
|
+
const lossAccount = accounts[AccountType.Loss] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.loss;
|
|
297
|
+
if (equityAccount === undefined || gainAccount === undefined || lossAccount === undefined) {
|
|
298
|
+
throw new Error('Missing required accounts for holding creation');
|
|
299
|
+
}
|
|
300
|
+
if (assetAccount) {
|
|
301
|
+
tx = walletClient.writeContract({
|
|
302
|
+
address: hub,
|
|
303
|
+
abi: ABI.Hub,
|
|
304
|
+
functionName: 'initializeHolding',
|
|
305
|
+
args: [
|
|
306
|
+
self.pool.id.raw,
|
|
307
|
+
self.id.raw,
|
|
308
|
+
assetId.raw,
|
|
309
|
+
valuation,
|
|
310
|
+
assetAccount,
|
|
311
|
+
equityAccount,
|
|
312
|
+
gainAccount,
|
|
313
|
+
lossAccount,
|
|
314
|
+
],
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
const newAssetAccount = await self._getFreeAccountId();
|
|
319
|
+
const createAccountData = encodeFunctionData({
|
|
320
|
+
abi: ABI.Hub,
|
|
321
|
+
functionName: 'createAccount',
|
|
322
|
+
args: [self.pool.id.raw, newAssetAccount, false],
|
|
323
|
+
});
|
|
324
|
+
const initHoldingData = encodeFunctionData({
|
|
325
|
+
abi: ABI.Hub,
|
|
326
|
+
functionName: 'initializeHolding',
|
|
327
|
+
args: [
|
|
328
|
+
self.pool.id.raw,
|
|
329
|
+
self.id.raw,
|
|
330
|
+
assetId.raw,
|
|
331
|
+
valuation,
|
|
332
|
+
newAssetAccount,
|
|
333
|
+
equityAccount,
|
|
334
|
+
gainAccount,
|
|
335
|
+
lossAccount,
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
tx = walletClient.writeContract({
|
|
339
|
+
address: hub,
|
|
340
|
+
abi: ABI.Hub,
|
|
341
|
+
functionName: 'multicall',
|
|
342
|
+
args: [[createAccountData, initHoldingData]],
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
yield* doTransaction('Create holding', publicClient, () => tx);
|
|
347
|
+
}, this.pool.chainId);
|
|
348
|
+
}
|
|
349
|
+
updateSharePrice(pricePerShare) {
|
|
350
|
+
const self = this;
|
|
351
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
352
|
+
const { hub } = await self._root._protocolAddresses(self.pool.chainId);
|
|
353
|
+
yield* doTransaction('Update price', publicClient, () => walletClient.writeContract({
|
|
354
|
+
address: hub,
|
|
355
|
+
abi: ABI.Hub,
|
|
356
|
+
functionName: 'updateSharePrice',
|
|
357
|
+
args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
|
|
358
|
+
}));
|
|
359
|
+
}, this.pool.chainId);
|
|
360
|
+
}
|
|
361
|
+
setMaxAssetPriceAge(assetId, maxPriceAge) {
|
|
362
|
+
const self = this;
|
|
363
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
364
|
+
const { hub } = await self._root._protocolAddresses(self.pool.chainId);
|
|
365
|
+
yield* doTransaction('Set max asset price age', publicClient, () => walletClient.writeContract({
|
|
366
|
+
address: hub,
|
|
367
|
+
abi: ABI.Hub,
|
|
368
|
+
functionName: 'setMaxAssetPriceAge',
|
|
369
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
|
|
370
|
+
}));
|
|
371
|
+
}, this.pool.chainId);
|
|
372
|
+
}
|
|
373
|
+
setMaxSharePriceAge(chainId, maxPriceAge) {
|
|
374
|
+
const self = this;
|
|
375
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
376
|
+
const [{ hub }, id] = await Promise.all([
|
|
377
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
378
|
+
self._root.id(chainId),
|
|
379
|
+
]);
|
|
380
|
+
yield* doTransaction('Set max share price age', publicClient, () => walletClient.writeContract({
|
|
381
|
+
address: hub,
|
|
382
|
+
abi: ABI.Hub,
|
|
383
|
+
functionName: 'setMaxSharePriceAge',
|
|
384
|
+
args: [id, self.pool.id.raw, self.id.raw, BigInt(maxPriceAge)],
|
|
385
|
+
}));
|
|
386
|
+
}, this.pool.chainId);
|
|
387
|
+
}
|
|
388
|
+
notifyAssetPrice(assetId) {
|
|
389
|
+
const self = this;
|
|
390
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
391
|
+
const { hub } = await self._root._protocolAddresses(self.pool.chainId);
|
|
392
|
+
yield* doTransaction('Notify asset price', publicClient, () => walletClient.writeContract({
|
|
393
|
+
address: hub,
|
|
394
|
+
abi: ABI.Hub,
|
|
395
|
+
functionName: 'notifyAssetPrice',
|
|
396
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw],
|
|
397
|
+
}));
|
|
398
|
+
}, this.pool.chainId);
|
|
399
|
+
}
|
|
400
|
+
notifySharePrice(chainId) {
|
|
401
|
+
const self = this;
|
|
402
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
403
|
+
const [{ hub }, id] = await Promise.all([
|
|
404
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
405
|
+
self._root.id(chainId),
|
|
406
|
+
]);
|
|
407
|
+
yield* doTransaction('Notify share price', publicClient, () => walletClient.writeContract({
|
|
408
|
+
address: hub,
|
|
409
|
+
abi: ABI.Hub,
|
|
410
|
+
functionName: 'notifySharePrice',
|
|
411
|
+
args: [self.pool.id.raw, self.id.raw, id],
|
|
412
|
+
}));
|
|
413
|
+
}, this.pool.chainId);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Approve deposits and issue shares for the given assets.
|
|
417
|
+
* @param assets - Array of assets to approve deposits and/or issue shares for
|
|
418
|
+
*/
|
|
419
|
+
approveDepositsAndIssueShares(assets) {
|
|
420
|
+
// TODO: Also claim orders
|
|
421
|
+
const self = this;
|
|
422
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
423
|
+
const centIds = [...new Set(assets.map((a) => a.assetId.centrifugeId))];
|
|
424
|
+
const [{ hub }, pendingAmounts,
|
|
425
|
+
// ...estimates
|
|
426
|
+
] = await Promise.all([
|
|
427
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
428
|
+
self.pendingAmounts(),
|
|
429
|
+
...centIds.map((centId) => self._root._estimate(self.pool.chainId, { centId })),
|
|
430
|
+
]);
|
|
431
|
+
// const estimateByCentId: Map<number, bigint> = new Map(centIds.map((centId, i) => [centId, estimates[i]!]))
|
|
432
|
+
const batch = [];
|
|
433
|
+
const estimate = 0n;
|
|
434
|
+
for (const asset of assets) {
|
|
435
|
+
const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
|
|
436
|
+
if (!pending) {
|
|
437
|
+
throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
|
|
438
|
+
}
|
|
439
|
+
let nextDepositEpoch = pending?.depositEpoch + 1;
|
|
440
|
+
if (asset.approveAssetAmount) {
|
|
441
|
+
if (asset.approveAssetAmount.gt(pending.pendingDeposit)) {
|
|
442
|
+
throw new Error(`Approve amount exceeds pending amount for asset "${asset.assetId.toString()}"`);
|
|
443
|
+
}
|
|
444
|
+
if (asset.approveAssetAmount.lte(0n)) {
|
|
445
|
+
throw new Error(`Approve amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
446
|
+
}
|
|
447
|
+
batch.push(encodeFunctionData({
|
|
448
|
+
abi: ABI.Hub,
|
|
449
|
+
functionName: 'approveDeposits',
|
|
450
|
+
args: [
|
|
451
|
+
self.pool.id.raw,
|
|
452
|
+
self.id.raw,
|
|
453
|
+
asset.assetId.raw,
|
|
454
|
+
nextDepositEpoch,
|
|
455
|
+
asset.approveAssetAmount.toBigInt(),
|
|
456
|
+
],
|
|
457
|
+
}));
|
|
458
|
+
nextDepositEpoch++;
|
|
459
|
+
}
|
|
460
|
+
const nextIssueEpoch = pending.issueEpoch + 1;
|
|
461
|
+
if (asset.issuePricePerShare) {
|
|
462
|
+
if (nextIssueEpoch >= nextDepositEpoch)
|
|
463
|
+
throw new Error('Nothing to issue');
|
|
464
|
+
batch.push(...Array.from({ length: nextDepositEpoch - nextIssueEpoch }, (_, i) => encodeFunctionData({
|
|
465
|
+
abi: ABI.Hub,
|
|
466
|
+
functionName: 'issueShares',
|
|
467
|
+
args: [
|
|
468
|
+
self.pool.id.raw,
|
|
469
|
+
self.id.raw,
|
|
470
|
+
asset.assetId.raw,
|
|
471
|
+
nextIssueEpoch + i,
|
|
472
|
+
asset.issuePricePerShare.toBigInt(),
|
|
473
|
+
],
|
|
474
|
+
})));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (batch.length === 0) {
|
|
478
|
+
throw new Error('No approve or issue actions provided');
|
|
479
|
+
}
|
|
480
|
+
yield* doTransaction('Approve and issue', publicClient, () => {
|
|
481
|
+
if (batch.length === 1) {
|
|
482
|
+
return walletClient.sendTransaction({
|
|
483
|
+
data: batch[0],
|
|
484
|
+
to: hub,
|
|
485
|
+
value: estimate,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return walletClient.writeContract({
|
|
489
|
+
address: hub,
|
|
490
|
+
abi: ABI.Hub,
|
|
491
|
+
functionName: 'multicall',
|
|
492
|
+
args: [batch],
|
|
493
|
+
value: estimate,
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
}, this.pool.chainId);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Approve redeems and revoke shares for the given assets.
|
|
500
|
+
* @param assets - Array of assets to approve redeems and/or revoke shares for
|
|
501
|
+
*/
|
|
502
|
+
approveRedeemsAndRevokeShares(assets) {
|
|
503
|
+
// TODO: Also claim orders
|
|
504
|
+
const self = this;
|
|
505
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
506
|
+
const centIds = [...new Set(assets.map((a) => a.assetId.centrifugeId))];
|
|
507
|
+
const [{ hub }, pendingAmounts,
|
|
508
|
+
// ...estimates
|
|
509
|
+
] = await Promise.all([
|
|
510
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
511
|
+
self.pendingAmounts(),
|
|
512
|
+
...centIds.map((centId) => self._root._estimate(self.pool.chainId, { centId })),
|
|
513
|
+
]);
|
|
514
|
+
// const estimateByCentId: Map<number, bigint> = new Map(centIds.map((centId, i) => [centId, estimates[i]!]))
|
|
515
|
+
const batch = [];
|
|
516
|
+
const estimate = 0n;
|
|
517
|
+
for (const asset of assets) {
|
|
518
|
+
const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
|
|
519
|
+
if (!pending) {
|
|
520
|
+
throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
|
|
521
|
+
}
|
|
522
|
+
let nextRedeemEpoch = pending.redeemEpoch + 1;
|
|
523
|
+
if (asset.approveShareAmount) {
|
|
524
|
+
if (asset.approveShareAmount.gt(pending.pendingRedeem)) {
|
|
525
|
+
throw new Error(`Share amount exceeds pending redeem for asset "${asset.assetId.toString()}"`);
|
|
526
|
+
}
|
|
527
|
+
if (asset.approveShareAmount.lte(0n)) {
|
|
528
|
+
throw new Error(`Share amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
529
|
+
}
|
|
530
|
+
batch.push(encodeFunctionData({
|
|
531
|
+
abi: ABI.Hub,
|
|
532
|
+
functionName: 'approveRedeems',
|
|
533
|
+
args: [
|
|
534
|
+
self.pool.id.raw,
|
|
535
|
+
self.id.raw,
|
|
536
|
+
asset.assetId.raw,
|
|
537
|
+
nextRedeemEpoch,
|
|
538
|
+
asset.approveShareAmount.toBigInt(),
|
|
539
|
+
],
|
|
540
|
+
}));
|
|
541
|
+
nextRedeemEpoch++;
|
|
542
|
+
}
|
|
543
|
+
const nextRevokeEpoch = pending.revokeEpoch + 1;
|
|
544
|
+
if (nextRevokeEpoch >= nextRedeemEpoch)
|
|
545
|
+
throw new Error('Nothing to revoke');
|
|
546
|
+
if (asset.revokePricePerShare) {
|
|
547
|
+
if (nextRevokeEpoch >= nextRedeemEpoch)
|
|
548
|
+
throw new Error('Nothing to revoke');
|
|
549
|
+
if (asset.revokePricePerShare.lte(0n)) {
|
|
550
|
+
throw new Error(`Revoke price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
551
|
+
}
|
|
552
|
+
batch.push(...Array.from({ length: nextRedeemEpoch - nextRevokeEpoch }, (_, i) => encodeFunctionData({
|
|
553
|
+
abi: ABI.Hub,
|
|
554
|
+
functionName: 'revokeShares',
|
|
555
|
+
args: [
|
|
556
|
+
self.pool.id.raw,
|
|
557
|
+
self.id.raw,
|
|
558
|
+
asset.assetId.raw,
|
|
559
|
+
nextRevokeEpoch + i,
|
|
560
|
+
asset.revokePricePerShare.toBigInt(),
|
|
561
|
+
],
|
|
562
|
+
})));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (batch.length === 0) {
|
|
566
|
+
throw new Error('No approve or revoke actions provided');
|
|
567
|
+
}
|
|
568
|
+
yield* doTransaction('Approve and revoke', publicClient, () => {
|
|
569
|
+
if (batch.length === 1) {
|
|
570
|
+
return walletClient.sendTransaction({
|
|
571
|
+
data: batch[0],
|
|
572
|
+
to: hub,
|
|
573
|
+
value: estimate,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return walletClient.writeContract({
|
|
577
|
+
address: hub,
|
|
578
|
+
abi: ABI.Hub,
|
|
579
|
+
functionName: 'multicall',
|
|
580
|
+
args: [batch],
|
|
581
|
+
value: estimate,
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
}, this.pool.chainId);
|
|
585
|
+
}
|
|
586
|
+
claimDeposit(assetId, investor) {
|
|
587
|
+
const self = this;
|
|
588
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
589
|
+
const [{ hub }, investorOrder, estimate] = await Promise.all([
|
|
590
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
591
|
+
self.investorOrder(assetId, investor),
|
|
592
|
+
self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
|
|
593
|
+
]);
|
|
594
|
+
yield* doTransaction('Claim deposit', publicClient, () => walletClient.writeContract({
|
|
595
|
+
address: hub,
|
|
596
|
+
abi: ABI.Hub,
|
|
597
|
+
functionName: 'notifyDeposit',
|
|
598
|
+
args: [
|
|
599
|
+
self.pool.id.raw,
|
|
600
|
+
self.id.raw,
|
|
601
|
+
assetId.raw,
|
|
602
|
+
addressToBytes32(investor),
|
|
603
|
+
investorOrder.maxDepositClaims,
|
|
604
|
+
],
|
|
605
|
+
value: estimate,
|
|
606
|
+
}));
|
|
607
|
+
}, this.pool.chainId);
|
|
608
|
+
}
|
|
609
|
+
claimRedeem(assetId, investor) {
|
|
610
|
+
const self = this;
|
|
611
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
612
|
+
const [{ hub }, investorOrder, estimate] = await Promise.all([
|
|
613
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
614
|
+
self.investorOrder(assetId, investor),
|
|
615
|
+
self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
|
|
616
|
+
]);
|
|
617
|
+
yield* doTransaction('Claim redeem', publicClient, () => walletClient.writeContract({
|
|
618
|
+
address: hub,
|
|
619
|
+
abi: ABI.Hub,
|
|
620
|
+
functionName: 'notifyRedeem',
|
|
621
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, addressToBytes32(investor), investorOrder.maxRedeemClaims],
|
|
622
|
+
value: estimate,
|
|
623
|
+
}));
|
|
624
|
+
}, this.pool.chainId);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Update a member of the share class.
|
|
628
|
+
* @param address Address of the investor
|
|
629
|
+
* @param validUntil Time in seconds from Unix epoch until the investor is valid
|
|
630
|
+
* @param chainId Chain ID of the network on which to update the member
|
|
631
|
+
*/
|
|
632
|
+
updateMember(address, validUntil, chainId) {
|
|
633
|
+
const self = this;
|
|
634
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
635
|
+
const [{ hub }, id, estimate] = await Promise.all([
|
|
636
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
637
|
+
self._root.id(chainId),
|
|
638
|
+
self._root._estimate(self.pool.chainId, { chainId }),
|
|
639
|
+
]);
|
|
640
|
+
const payload = encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(address), BigInt(validUntil)]);
|
|
641
|
+
yield* doTransaction('Update restriction', publicClient, () => walletClient.writeContract({
|
|
642
|
+
address: hub,
|
|
643
|
+
abi: ABI.Hub,
|
|
644
|
+
functionName: 'updateRestriction',
|
|
645
|
+
args: [self.pool.id.raw, self.id.raw, id, payload, 15000000n],
|
|
646
|
+
value: estimate,
|
|
647
|
+
}));
|
|
648
|
+
}, this.pool.chainId);
|
|
649
|
+
}
|
|
650
|
+
/** @internal */
|
|
651
|
+
_assetIdsByAddress(assetAddresses) {
|
|
652
|
+
return this._root._queryIndexer(`query ($assetAddresses: [String!]!) {
|
|
653
|
+
assetRegistrations(where: { assetAddress_in: $assetAddresses }) {
|
|
654
|
+
items {
|
|
655
|
+
id
|
|
656
|
+
assetAddress
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}`, { assetAddresses: assetAddresses.map((a) => getAddress(a)) }, (data) => {
|
|
660
|
+
return Object.fromEntries(data.assetRegistrations.items.map((item) => {
|
|
661
|
+
const assetId = new AssetId(item.id);
|
|
662
|
+
return [item.assetAddress.toLowerCase(), assetId];
|
|
663
|
+
}));
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
/** @internal */
|
|
667
|
+
_metadata() {
|
|
668
|
+
return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
|
|
669
|
+
const [name, symbol] = await this._root.getClient(this.pool.chainId).readContract({
|
|
670
|
+
address: shareClassManager,
|
|
671
|
+
abi: ABI.ShareClassManager,
|
|
672
|
+
functionName: 'metadata',
|
|
673
|
+
args: [this.id.raw],
|
|
674
|
+
});
|
|
675
|
+
return {
|
|
676
|
+
name,
|
|
677
|
+
symbol,
|
|
678
|
+
};
|
|
679
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
680
|
+
address: shareClassManager,
|
|
681
|
+
abi: ABI.ShareClassManager,
|
|
682
|
+
eventName: 'UpdateMetadata',
|
|
683
|
+
filter: (events) => {
|
|
684
|
+
return events.some((event) => {
|
|
685
|
+
return event.args.scId === this.id;
|
|
686
|
+
});
|
|
687
|
+
},
|
|
688
|
+
}, this.pool.chainId)))));
|
|
689
|
+
}
|
|
690
|
+
/** @internal */
|
|
691
|
+
_metrics() {
|
|
692
|
+
return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
|
|
693
|
+
const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
|
|
694
|
+
address: shareClassManager,
|
|
695
|
+
abi: ABI.ShareClassManager,
|
|
696
|
+
functionName: 'metrics',
|
|
697
|
+
args: [this.id.raw],
|
|
698
|
+
});
|
|
699
|
+
return {
|
|
700
|
+
totalIssuance: new Balance(totalIssuance, 18),
|
|
701
|
+
pricePerShare: new Price(pricePerShare),
|
|
702
|
+
};
|
|
703
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
704
|
+
address: shareClassManager,
|
|
705
|
+
abi: ABI.ShareClassManager,
|
|
706
|
+
eventName: [
|
|
707
|
+
'RevokeShares',
|
|
708
|
+
'IssueShares',
|
|
709
|
+
'RemoteIssueShares',
|
|
710
|
+
'RemoteRevokeShares',
|
|
711
|
+
'UpdateShareClass',
|
|
712
|
+
],
|
|
713
|
+
filter: (events) => {
|
|
714
|
+
return events.some((event) => {
|
|
715
|
+
return event.args.scId === this.id.raw;
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
}, this.pool.chainId)))));
|
|
719
|
+
}
|
|
720
|
+
/** @internal */
|
|
721
|
+
_epoch(assetId) {
|
|
722
|
+
return this._query(['epoch', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager, hubRegistry }) => defer(async () => {
|
|
723
|
+
const scm = getContract({
|
|
724
|
+
address: shareClassManager,
|
|
725
|
+
abi: ABI.ShareClassManager,
|
|
726
|
+
client: this._root.getClient(this.pool.chainId),
|
|
727
|
+
});
|
|
728
|
+
const [epoch, pendingDeposit, pendingRedeem, assetDecimals] = await Promise.all([
|
|
729
|
+
scm.read.epochId([this.id.raw, assetId.raw]),
|
|
730
|
+
scm.read.pendingDeposit([this.id.raw, assetId.raw]),
|
|
731
|
+
scm.read.pendingRedeem([this.id.raw, assetId.raw]),
|
|
732
|
+
this._root.getClient(this.pool.chainId).readContract({
|
|
733
|
+
address: hubRegistry,
|
|
734
|
+
// Use inline ABI because of function overload
|
|
735
|
+
abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
|
|
736
|
+
functionName: 'decimals',
|
|
737
|
+
args: [assetId.raw],
|
|
738
|
+
}),
|
|
739
|
+
]);
|
|
740
|
+
const depositEpoch = epoch[0];
|
|
741
|
+
const redeemEpoch = epoch[1];
|
|
742
|
+
const issueEpoch = epoch[2];
|
|
743
|
+
const revokeEpoch = epoch[3];
|
|
744
|
+
const [depositEpochAmounts, redeemEpochAmount] = await Promise.all([
|
|
745
|
+
Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.id.raw, assetId.raw, issueEpoch + i + 1]))),
|
|
746
|
+
Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.id.raw, assetId.raw, revokeEpoch + i + 1]))),
|
|
747
|
+
]);
|
|
748
|
+
const approvedDeposit = depositEpochAmounts.reduce((acc, amount) => acc + amount[1], 0n);
|
|
749
|
+
const approvedRedeem = redeemEpochAmount.reduce((acc, amount) => acc + amount[1], 0n);
|
|
750
|
+
return {
|
|
751
|
+
depositEpoch,
|
|
752
|
+
redeemEpoch,
|
|
753
|
+
issueEpoch,
|
|
754
|
+
revokeEpoch,
|
|
755
|
+
// TODO: Replace with assetDecimals()
|
|
756
|
+
pendingDeposit: new Balance(pendingDeposit, assetDecimals),
|
|
757
|
+
// TODO: Replace with assetDecimals()
|
|
758
|
+
pendingRedeem: new Balance(pendingRedeem, 18),
|
|
759
|
+
approvedDeposit: new Balance(approvedDeposit, assetDecimals),
|
|
760
|
+
approvedRedeem: new Balance(approvedRedeem, 18),
|
|
761
|
+
};
|
|
762
|
+
}).pipe(repeatOnEvents(this._root, {
|
|
763
|
+
address: shareClassManager,
|
|
764
|
+
abi: ABI.ShareClassManager,
|
|
765
|
+
eventName: [
|
|
766
|
+
'ApproveDeposits',
|
|
767
|
+
'ApproveRedeems',
|
|
768
|
+
'IssueShares',
|
|
769
|
+
'RevokeShares',
|
|
770
|
+
'RemoteIssueShares',
|
|
771
|
+
'RemoteRevokeShares',
|
|
772
|
+
'UpdateDepositRequest',
|
|
773
|
+
'UpdateRedeemRequest',
|
|
774
|
+
],
|
|
775
|
+
filter: (events) => {
|
|
776
|
+
return events.some((event) => {
|
|
777
|
+
return event.args.scId === this.id.raw;
|
|
778
|
+
});
|
|
779
|
+
},
|
|
780
|
+
}, this.pool.chainId)))));
|
|
781
|
+
}
|
|
782
|
+
/** @internal */
|
|
783
|
+
_updateContract(chainId, target, payload) {
|
|
784
|
+
const self = this;
|
|
785
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
786
|
+
const id = await self._root.id(chainId);
|
|
787
|
+
const [{ hub }, estimate] = await Promise.all([
|
|
788
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
789
|
+
self._root._estimate(self.pool.chainId, { centId: id }),
|
|
790
|
+
]);
|
|
791
|
+
yield* doTransaction('Update contract', publicClient, () => walletClient.writeContract({
|
|
792
|
+
address: hub,
|
|
793
|
+
abi: ABI.Hub,
|
|
794
|
+
functionName: 'updateContract',
|
|
795
|
+
args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(target), payload, 15000000n],
|
|
796
|
+
value: estimate,
|
|
797
|
+
}));
|
|
798
|
+
}, this.pool.chainId);
|
|
799
|
+
}
|
|
800
|
+
/** @internal */
|
|
801
|
+
_share(chainId) {
|
|
802
|
+
return this._query(null, () => this.pool.network(chainId).pipe(switchMap((network) => network._share(this.id))));
|
|
803
|
+
}
|
|
804
|
+
/** @internal */
|
|
805
|
+
_restrictionManager(chainId) {
|
|
806
|
+
return this._query(['restrictionManager', chainId], () => this._share(chainId).pipe(switchMap((share) => defer(async () => {
|
|
807
|
+
const address = await this._root.getClient(this.pool.chainId).readContract({
|
|
808
|
+
address: share,
|
|
809
|
+
abi: ABI.Currency,
|
|
810
|
+
functionName: 'hook',
|
|
811
|
+
});
|
|
812
|
+
return address.toLowerCase();
|
|
813
|
+
}))));
|
|
814
|
+
}
|
|
815
|
+
/** @internal */
|
|
816
|
+
_getFreeAccountId() {
|
|
817
|
+
return this._query(null, () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
|
|
818
|
+
const id = Number(randomUint(32));
|
|
819
|
+
if (triesLeft <= 0)
|
|
820
|
+
return EMPTY;
|
|
821
|
+
return defer(async () => {
|
|
822
|
+
const exists = await this._root.getClient(this.pool.chainId).readContract({
|
|
823
|
+
address: accounting,
|
|
824
|
+
abi: ABI.Accounting,
|
|
825
|
+
functionName: 'exists',
|
|
826
|
+
args: [this.pool.id.raw, id],
|
|
827
|
+
});
|
|
828
|
+
return { accounting, id: exists ? null : id, triesLeft: triesLeft - 1 };
|
|
829
|
+
});
|
|
830
|
+
}), filter(({ id }) => !!id), map(({ id }) => id)));
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
//# sourceMappingURL=ShareClass.js.map
|