@centrifuge/sdk 0.55.2 → 1.0.1
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 +2 -2
- package/dist/Centrifuge.d.ts +6910 -22
- package/dist/Centrifuge.d.ts.map +1 -1
- package/dist/Centrifuge.js +139 -160
- package/dist/Centrifuge.js.map +1 -1
- package/dist/Centrifuge.test.js +24 -26
- package/dist/Centrifuge.test.js.map +1 -1
- package/dist/abi/Accounting.abi.d.ts +1 -1
- package/dist/abi/Accounting.abi.d.ts.map +1 -1
- package/dist/abi/Accounting.abi.js +23 -24
- package/dist/abi/Accounting.abi.js.map +1 -1
- package/dist/abi/AsyncRequestManager.abi.d.ts +1 -1
- package/dist/abi/AsyncRequestManager.abi.js +18 -18
- package/dist/abi/AsyncRequestManager.abi.js.map +1 -1
- package/dist/abi/AsyncVault.abi.d.ts +1 -1
- package/dist/abi/AsyncVault.abi.d.ts.map +1 -1
- package/dist/abi/AsyncVault.abi.js +1 -2
- package/dist/abi/AsyncVault.abi.js.map +1 -1
- package/dist/abi/BalanceSheet.abi.d.ts +1 -1
- package/dist/abi/BalanceSheet.abi.d.ts.map +1 -1
- package/dist/abi/BalanceSheet.abi.js +21 -20
- package/dist/abi/BalanceSheet.abi.js.map +1 -1
- package/dist/abi/BatchRequestManager.abi.d.ts +3 -0
- package/dist/abi/BatchRequestManager.abi.d.ts.map +1 -0
- package/dist/abi/BatchRequestManager.abi.js +74 -0
- package/dist/abi/BatchRequestManager.abi.js.map +1 -0
- package/dist/abi/GasService.abi.d.ts +1 -1
- package/dist/abi/GasService.abi.d.ts.map +1 -1
- package/dist/abi/GasService.abi.js +10 -6
- package/dist/abi/GasService.abi.js.map +1 -1
- package/dist/abi/Gateway.abi.d.ts +1 -1
- package/dist/abi/Gateway.abi.d.ts.map +1 -1
- package/dist/abi/Gateway.abi.js +33 -27
- package/dist/abi/Gateway.abi.js.map +1 -1
- package/dist/abi/Holdings.abi.d.ts +1 -1
- package/dist/abi/Holdings.abi.d.ts.map +1 -1
- package/dist/abi/Holdings.abi.js +10 -5
- package/dist/abi/Holdings.abi.js.map +1 -1
- package/dist/abi/Hub.abi.d.ts +1 -1
- package/dist/abi/Hub.abi.d.ts.map +1 -1
- package/dist/abi/Hub.abi.js +40 -38
- package/dist/abi/Hub.abi.js.map +1 -1
- package/dist/abi/HubRegistry.abi.d.ts +1 -1
- package/dist/abi/HubRegistry.abi.d.ts.map +1 -1
- package/dist/abi/HubRegistry.abi.js +22 -19
- package/dist/abi/HubRegistry.abi.js.map +1 -1
- package/dist/abi/MerkleProofManager.abi.d.ts.map +1 -1
- package/dist/abi/MerkleProofManager.abi.js +2 -4
- package/dist/abi/MerkleProofManager.abi.js.map +1 -1
- package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -1
- package/dist/abi/MessageDispatcher.abi.js +44 -38
- package/dist/abi/MessageDispatcher.abi.js.map +1 -1
- package/dist/abi/MultiAdapter.abi.d.ts +1 -1
- package/dist/abi/MultiAdapter.abi.d.ts.map +1 -1
- package/dist/abi/MultiAdapter.abi.js +14 -28
- package/dist/abi/MultiAdapter.abi.js.map +1 -1
- package/dist/abi/NAVManager.abi.d.ts +3 -0
- package/dist/abi/NAVManager.abi.d.ts.map +1 -0
- package/dist/abi/NAVManager.abi.js +41 -0
- package/dist/abi/NAVManager.abi.js.map +1 -0
- package/dist/abi/OnOffRampManager.abi.d.ts +1 -1
- package/dist/abi/OnOffRampManager.abi.d.ts.map +1 -1
- package/dist/abi/OnOffRampManager.abi.js +18 -20
- package/dist/abi/OnOffRampManager.abi.js.map +1 -1
- package/dist/abi/PoolEscrow.abi.d.ts +1 -1
- package/dist/abi/PoolEscrow.abi.d.ts.map +1 -1
- package/dist/abi/PoolEscrow.abi.js +1 -2
- package/dist/abi/PoolEscrow.abi.js.map +1 -1
- package/dist/abi/QueueManager.abi.d.ts +3 -0
- package/dist/abi/QueueManager.abi.d.ts.map +1 -0
- package/dist/abi/QueueManager.abi.js +21 -0
- package/dist/abi/QueueManager.abi.js.map +1 -0
- package/dist/abi/ShareClassManager.abi.d.ts +1 -1
- package/dist/abi/ShareClassManager.abi.d.ts.map +1 -1
- package/dist/abi/ShareClassManager.abi.js +11 -62
- package/dist/abi/ShareClassManager.abi.js.map +1 -1
- package/dist/abi/Spoke.abi.d.ts +1 -1
- package/dist/abi/Spoke.abi.d.ts.map +1 -1
- package/dist/abi/Spoke.abi.js +25 -21
- package/dist/abi/Spoke.abi.js.map +1 -1
- package/dist/abi/SyncManager.abi.d.ts +3 -0
- package/dist/abi/SyncManager.abi.d.ts.map +1 -0
- package/dist/abi/{SyncRequestManager.abi.js → SyncManager.abi.js} +10 -26
- package/dist/abi/SyncManager.abi.js.map +1 -0
- package/dist/abi/Valuation.abi.d.ts +1 -1
- package/dist/abi/Valuation.abi.d.ts.map +1 -1
- package/dist/abi/Valuation.abi.js +4 -1
- package/dist/abi/Valuation.abi.js.map +1 -1
- package/dist/abi/VaultRegistry.abi.d.ts +3 -0
- package/dist/abi/VaultRegistry.abi.d.ts.map +1 -0
- package/dist/abi/VaultRegistry.abi.js +35 -0
- package/dist/abi/VaultRegistry.abi.js.map +1 -0
- package/dist/abi/VaultRouter.abi.d.ts +1 -1
- package/dist/abi/VaultRouter.abi.d.ts.map +1 -1
- package/dist/abi/VaultRouter.abi.js +3 -0
- package/dist/abi/VaultRouter.abi.js.map +1 -1
- package/dist/abi/index.d.ts +1805 -1802
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +9 -5
- package/dist/abi/index.js.map +1 -1
- package/dist/entities/BalanceSheet.d.ts +8 -8
- package/dist/entities/BalanceSheet.d.ts.map +1 -1
- package/dist/entities/BalanceSheet.js +23 -21
- package/dist/entities/BalanceSheet.js.map +1 -1
- package/dist/entities/BalanceSheet.test.js +9 -4
- package/dist/entities/BalanceSheet.test.js.map +1 -1
- package/dist/entities/Investor.d.ts +11 -9
- package/dist/entities/Investor.d.ts.map +1 -1
- package/dist/entities/Investor.js +28 -35
- package/dist/entities/Investor.js.map +1 -1
- package/dist/entities/Investor.test.js +1 -1
- package/dist/entities/Investor.test.js.map +1 -1
- package/dist/entities/MerkleProofManager.d.ts +1 -2
- package/dist/entities/MerkleProofManager.d.ts.map +1 -1
- package/dist/entities/MerkleProofManager.js +24 -25
- package/dist/entities/MerkleProofManager.js.map +1 -1
- package/dist/entities/MerkleProofManager.test.js +10 -10
- package/dist/entities/MerkleProofManager.test.js.map +1 -1
- package/dist/entities/OnOffRampManager.d.ts.map +1 -1
- package/dist/entities/OnOffRampManager.js +35 -39
- package/dist/entities/OnOffRampManager.js.map +1 -1
- package/dist/entities/OnOffRampManager.test.js +14 -10
- package/dist/entities/OnOffRampManager.test.js.map +1 -1
- package/dist/entities/Pool.d.ts +33 -11
- package/dist/entities/Pool.d.ts.map +1 -1
- package/dist/entities/Pool.js +132 -65
- package/dist/entities/Pool.js.map +1 -1
- package/dist/entities/Pool.test.js +35 -12
- package/dist/entities/Pool.test.js.map +1 -1
- package/dist/entities/PoolNetwork.d.ts +26 -5
- package/dist/entities/PoolNetwork.d.ts.map +1 -1
- package/dist/entities/PoolNetwork.js +154 -115
- package/dist/entities/PoolNetwork.js.map +1 -1
- package/dist/entities/PoolNetwork.test.js +40 -34
- package/dist/entities/PoolNetwork.test.js.map +1 -1
- package/dist/entities/Reports/PoolSharePricesReport.d.ts.map +1 -1
- package/dist/entities/Reports/PoolSharePricesReport.js +3 -2
- package/dist/entities/Reports/PoolSharePricesReport.js.map +1 -1
- package/dist/entities/Reports/PoolSharePricesReport.test.js +1 -1
- package/dist/entities/Reports/PoolSharePricesReport.test.js.map +1 -1
- package/dist/entities/ShareClass.d.ts +59 -49
- package/dist/entities/ShareClass.d.ts.map +1 -1
- package/dist/entities/ShareClass.js +384 -304
- package/dist/entities/ShareClass.js.map +1 -1
- package/dist/entities/ShareClass.test.js +36 -32
- package/dist/entities/ShareClass.test.js.map +1 -1
- package/dist/entities/Vault.d.ts +1 -1
- package/dist/entities/Vault.d.ts.map +1 -1
- package/dist/entities/Vault.js +68 -55
- package/dist/entities/Vault.js.map +1 -1
- package/dist/entities/Vault.test.js +10 -10
- package/dist/entities/Vault.test.js.map +1 -1
- package/dist/tests/mocks/mockPoolMetadata.js +2 -2
- package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
- package/dist/types/index.d.ts +17 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/transaction.d.ts +24 -32
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/types/transaction.js +26 -32
- package/dist/types/transaction.js.map +1 -1
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/permit.d.ts +1 -1
- package/dist/utils/permit.d.ts.map +1 -1
- package/dist/utils/permit.js +11 -7
- package/dist/utils/permit.js.map +1 -1
- package/dist/utils/rx.d.ts +2 -1
- package/dist/utils/rx.d.ts.map +1 -1
- package/dist/utils/rx.js +2 -2
- package/dist/utils/rx.js.map +1 -1
- package/dist/utils/transaction.d.ts +2 -1
- package/dist/utils/transaction.d.ts.map +1 -1
- package/dist/utils/transaction.js +4 -3
- package/dist/utils/transaction.js.map +1 -1
- package/dist/utils/types.d.ts +10 -5
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/abi/SyncRequestManager.abi.d.ts +0 -3
- package/dist/abi/SyncRequestManager.abi.d.ts.map +0 -1
- package/dist/abi/SyncRequestManager.abi.js.map +0 -1
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { catchError, combineLatest, defer, EMPTY, expand, filter, firstValueFrom, map, of, switchMap } from 'rxjs';
|
|
1
|
+
import { catchError, combineLatest, defer, EMPTY, expand, filter, firstValueFrom, map, of, switchMap, timer, } from 'rxjs';
|
|
2
2
|
import { encodeFunctionData, encodePacked, getContract } from 'viem';
|
|
3
3
|
import { ABI } from '../abi/index.js';
|
|
4
4
|
import { AccountType } from '../types/holdings.js';
|
|
5
5
|
import { MessageType } from '../types/transaction.js';
|
|
6
|
+
import { AddressMap } from '../utils/AddressMap.js';
|
|
6
7
|
import { Balance, Price } from '../utils/BigInt.js';
|
|
7
|
-
import { addressToBytes32, randomUint } from '../utils/index.js';
|
|
8
|
+
import { addressToBytes32, encode, randomUint } from '../utils/index.js';
|
|
8
9
|
import { repeatOnEvents } from '../utils/rx.js';
|
|
9
10
|
import { wrapTransaction } from '../utils/transaction.js';
|
|
10
11
|
import { AssetId, ShareClassId } from '../utils/types.js';
|
|
11
12
|
import { BalanceSheet } from './BalanceSheet.js';
|
|
12
13
|
import { Entity } from './Entity.js';
|
|
13
|
-
import { PoolNetwork } from './PoolNetwork.js';
|
|
14
|
+
import { PoolNetwork, VaultManagerTrustedCall } from './PoolNetwork.js';
|
|
14
15
|
import { Vault } from './Vault.js';
|
|
15
|
-
|
|
16
|
+
const GAS_LIMIT = 30000000n;
|
|
16
17
|
/**
|
|
17
18
|
* Query and interact with a share class, which allows querying total issuance, NAV per share,
|
|
18
19
|
* and allows interactions related to asynchronous deposits and redemptions.
|
|
@@ -64,11 +65,11 @@ export class ShareClass extends Entity {
|
|
|
64
65
|
};
|
|
65
66
|
})));
|
|
66
67
|
}
|
|
67
|
-
balanceSheet(
|
|
68
|
-
return this._query(['balanceSheet',
|
|
69
|
-
const network = networks.find((n) => n.
|
|
68
|
+
balanceSheet(centrifugeId) {
|
|
69
|
+
return this._query(['balanceSheet', centrifugeId], () => this.pool.activeNetworks().pipe(map((networks) => {
|
|
70
|
+
const network = networks.find((n) => n.centrifugeId === centrifugeId);
|
|
70
71
|
if (!network) {
|
|
71
|
-
throw new Error(`No active network found for
|
|
72
|
+
throw new Error(`No active network found for centrifuge ID ${centrifugeId}`);
|
|
72
73
|
}
|
|
73
74
|
return new BalanceSheet(this._root, network, this);
|
|
74
75
|
})));
|
|
@@ -78,15 +79,15 @@ export class ShareClass extends Entity {
|
|
|
78
79
|
if (networks.length === 0)
|
|
79
80
|
return of([]);
|
|
80
81
|
return combineLatest(networks.map((network) => combineLatest([
|
|
81
|
-
this._share(network.
|
|
82
|
-
this._restrictionManager(network.
|
|
83
|
-
this.valuation(network.
|
|
82
|
+
this._share(network.centrifugeId),
|
|
83
|
+
this._restrictionManager(network.centrifugeId).pipe(catchError(() => of(null))),
|
|
84
|
+
this.valuation(network.centrifugeId),
|
|
84
85
|
of(network),
|
|
85
86
|
])));
|
|
86
87
|
}), map((data) => data
|
|
87
88
|
.filter(([share, restrictionManager]) => share != null && restrictionManager != null)
|
|
88
89
|
.map(([share, restrictionManager, valuation, network]) => ({
|
|
89
|
-
|
|
90
|
+
centrifugeId: network.centrifugeId,
|
|
90
91
|
shareTokenAddress: share,
|
|
91
92
|
restrictionManagerAddress: restrictionManager,
|
|
92
93
|
valuation,
|
|
@@ -100,12 +101,12 @@ export class ShareClass extends Entity {
|
|
|
100
101
|
tokenPrice
|
|
101
102
|
address
|
|
102
103
|
blockchain {
|
|
103
|
-
|
|
104
|
+
centrifugeId
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
}`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
|
|
108
|
-
|
|
109
|
+
centrifugeId: Number(item.blockchain.centrifugeId),
|
|
109
110
|
totalIssuance: new Balance(item.totalIssuance, poolCurrency.decimals),
|
|
110
111
|
pricePerShare: new Price(item.tokenPrice),
|
|
111
112
|
nav: new Balance(item.totalIssuance, poolCurrency.decimals).mul(new Price(item.tokenPrice)),
|
|
@@ -114,31 +115,30 @@ export class ShareClass extends Entity {
|
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
117
|
* Query the vaults of the share class.
|
|
117
|
-
* @param
|
|
118
|
+
* @param centrifugeId The optional centrifuge ID to query the vaults on.
|
|
118
119
|
* @param includeUnlinked Whether to include unlinked vaults.
|
|
119
120
|
* @returns Vaults of the share class.
|
|
120
121
|
*/
|
|
121
|
-
vaults(
|
|
122
|
-
return this._query(['vaults',
|
|
123
|
-
|
|
124
|
-
if (
|
|
122
|
+
vaults(centrifugeId, includeUnlinked = false) {
|
|
123
|
+
return this._query(['vaults', centrifugeId, includeUnlinked.toString()], () => this._allVaults().pipe(map((allVaults) => {
|
|
124
|
+
return allVaults.filter((vault) => {
|
|
125
|
+
if (centrifugeId !== undefined && vault.centrifugeId !== centrifugeId)
|
|
125
126
|
return false;
|
|
126
127
|
if (!includeUnlinked && vault.status === 'Unlinked')
|
|
127
128
|
return false;
|
|
128
129
|
return true;
|
|
129
130
|
});
|
|
130
|
-
|
|
131
|
-
})));
|
|
131
|
+
}), map((vaults) => vaults.map((vault) => new Vault(this._root, new PoolNetwork(this._root, this.pool, vault.centrifugeId), this, vault.assetAddress, vault.address, vault.assetId)))));
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* Query all the balances of the share class (from BalanceSheet and Holdings).
|
|
135
135
|
*/
|
|
136
|
-
balances(
|
|
137
|
-
return this._query(['balances',
|
|
136
|
+
balances(centrifugeId) {
|
|
137
|
+
return this._query(['balances', centrifugeId], () => combineLatest([this._balances(), this.pool.currency()]).pipe(switchMap(([res, poolCurrency]) => {
|
|
138
138
|
if (res.length === 0) {
|
|
139
139
|
return of([]);
|
|
140
140
|
}
|
|
141
|
-
const items = res.filter((item) => Number(item.
|
|
141
|
+
const items = res.filter((item) => Number(item.centrifugeId) === centrifugeId || !centrifugeId);
|
|
142
142
|
if (items.length === 0)
|
|
143
143
|
return of([]);
|
|
144
144
|
return combineLatest([
|
|
@@ -146,11 +146,11 @@ export class ShareClass extends Entity {
|
|
|
146
146
|
if (!holding.holding)
|
|
147
147
|
return of(null);
|
|
148
148
|
const assetId = new AssetId(holding.assetId);
|
|
149
|
-
return this._holding(assetId);
|
|
149
|
+
return this._holding(assetId).pipe(catchError(() => of(null)));
|
|
150
150
|
})),
|
|
151
151
|
combineLatest(items.map((holding) => {
|
|
152
152
|
const assetId = new AssetId(holding.assetId);
|
|
153
|
-
return this._balance(Number(holding.
|
|
153
|
+
return this._balance(Number(holding.centrifugeId), {
|
|
154
154
|
address: holding.asset.address,
|
|
155
155
|
assetTokenId: BigInt(holding.asset.assetTokenId),
|
|
156
156
|
id: assetId,
|
|
@@ -174,7 +174,7 @@ export class ShareClass extends Entity {
|
|
|
174
174
|
tokenId: BigInt(data.asset.assetTokenId),
|
|
175
175
|
name: data.asset.name,
|
|
176
176
|
symbol: data.asset.symbol,
|
|
177
|
-
|
|
177
|
+
centrifugeId: Number(data.centrifugeId),
|
|
178
178
|
},
|
|
179
179
|
holding: holding && {
|
|
180
180
|
valuation: holding.valuation,
|
|
@@ -201,20 +201,20 @@ export class ShareClass extends Entity {
|
|
|
201
201
|
this.balances(),
|
|
202
202
|
]).pipe(map(([epochs, outInv, outRed, balancesData]) => {
|
|
203
203
|
const invByKey = new Map();
|
|
204
|
-
outInv.forEach((o) => invByKey.set(`${o.assetId.toString()}-${o.
|
|
204
|
+
outInv.forEach((o) => invByKey.set(`${o.assetId.toString()}-${o.centrifugeId}`, o.amount));
|
|
205
205
|
const redByKey = new Map();
|
|
206
|
-
outRed.forEach((o) => redByKey.set(`${o.assetId.toString()}-${o.
|
|
206
|
+
outRed.forEach((o) => redByKey.set(`${o.assetId.toString()}-${o.centrifugeId}`, o.amount));
|
|
207
207
|
const priceByAsset = new Map();
|
|
208
208
|
balancesData.forEach((b) => priceByAsset.set(b.assetId.toString(), b.price));
|
|
209
209
|
return epochs.map((epoch, i) => {
|
|
210
210
|
const vault = vaults[i];
|
|
211
|
-
const key = `${vault.assetId.toString()}-${vault.
|
|
211
|
+
const key = `${vault.assetId.toString()}-${vault.centrifugeId}`;
|
|
212
212
|
const queuedInvest = invByKey.get(key) ?? new Balance(0n, 18);
|
|
213
213
|
const queuedRedeem = redByKey.get(key) ?? new Balance(0n, 18);
|
|
214
214
|
const assetPrice = priceByAsset.get(vault.assetId.toString()) ?? Price.fromFloat(1);
|
|
215
215
|
return {
|
|
216
216
|
assetId: vault.assetId,
|
|
217
|
-
|
|
217
|
+
centrifugeId: vault.centrifugeId,
|
|
218
218
|
queuedInvest,
|
|
219
219
|
queuedRedeem,
|
|
220
220
|
assetPrice,
|
|
@@ -227,12 +227,16 @@ export class ShareClass extends Entity {
|
|
|
227
227
|
/**
|
|
228
228
|
* Check if an address is a member of the share class.
|
|
229
229
|
* @param address Address to check
|
|
230
|
-
* @param
|
|
230
|
+
* @param centrifugeId Centrifuge ID of the network on which to check the member
|
|
231
231
|
*/
|
|
232
|
-
member(address,
|
|
232
|
+
member(address, centrifugeId) {
|
|
233
233
|
const addr = address.toLowerCase();
|
|
234
|
-
return this._query(['member', addr,
|
|
235
|
-
|
|
234
|
+
return this._query(['member', addr, centrifugeId], () => combineLatest([
|
|
235
|
+
this._share(centrifugeId),
|
|
236
|
+
this._restrictionManager(centrifugeId),
|
|
237
|
+
this._root.getClient(centrifugeId),
|
|
238
|
+
]).pipe(switchMap(([share, restrictionManager, client]) => defer(async () => {
|
|
239
|
+
const res = await client.readContract({
|
|
236
240
|
address: restrictionManager,
|
|
237
241
|
abi: ABI.RestrictionManager,
|
|
238
242
|
functionName: 'isMember',
|
|
@@ -246,7 +250,7 @@ export class ShareClass extends Entity {
|
|
|
246
250
|
address: restrictionManager,
|
|
247
251
|
eventName: 'UpdateMember',
|
|
248
252
|
filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
|
|
249
|
-
},
|
|
253
|
+
}, centrifugeId), catchError((e) => {
|
|
250
254
|
console.warn('Error checking member status', e);
|
|
251
255
|
// Freeze-only hook doesn't have isMember function
|
|
252
256
|
return of({
|
|
@@ -267,7 +271,7 @@ export class ShareClass extends Entity {
|
|
|
267
271
|
const self = this;
|
|
268
272
|
return this._transact(async function* (ctx) {
|
|
269
273
|
const [{ hub }, metadata] = await Promise.all([
|
|
270
|
-
self._root._protocolAddresses(self.pool.
|
|
274
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
271
275
|
self.pool.metadata(),
|
|
272
276
|
]);
|
|
273
277
|
let data;
|
|
@@ -351,13 +355,13 @@ export class ShareClass extends Entity {
|
|
|
351
355
|
contract: hub,
|
|
352
356
|
data,
|
|
353
357
|
});
|
|
354
|
-
}, this.pool.
|
|
358
|
+
}, this.pool.centrifugeId);
|
|
355
359
|
}
|
|
356
|
-
updateSharePrice(pricePerShare) {
|
|
360
|
+
updateSharePrice(pricePerShare, updatedAt = new Date()) {
|
|
357
361
|
const self = this;
|
|
358
362
|
return this._transact(async function* (ctx) {
|
|
359
363
|
const [{ hub }, activeNetworks] = await Promise.all([
|
|
360
|
-
self._root._protocolAddresses(self.pool.
|
|
364
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
361
365
|
self.pool.activeNetworks(),
|
|
362
366
|
]);
|
|
363
367
|
const batch = [];
|
|
@@ -370,17 +374,22 @@ export class ShareClass extends Entity {
|
|
|
370
374
|
batch.push(encodeFunctionData({
|
|
371
375
|
abi: ABI.Hub,
|
|
372
376
|
functionName: 'updateSharePrice',
|
|
373
|
-
args: [
|
|
377
|
+
args: [
|
|
378
|
+
self.pool.id.raw,
|
|
379
|
+
self.id.raw,
|
|
380
|
+
pricePerShare.toBigInt(),
|
|
381
|
+
BigInt(Math.floor(updatedAt.getTime() / 1000)),
|
|
382
|
+
],
|
|
374
383
|
}));
|
|
375
384
|
await Promise.all(activeNetworks.map(async (activeNetwork) => {
|
|
376
385
|
const networkDetails = await activeNetwork.details();
|
|
377
|
-
const id =
|
|
386
|
+
const id = activeNetwork.centrifugeId;
|
|
378
387
|
const isShareClassInNetwork = networkDetails.activeShareClasses.find((shareClass) => shareClass.id.equals(self.id));
|
|
379
388
|
if (isShareClassInNetwork) {
|
|
380
389
|
batch.push(encodeFunctionData({
|
|
381
390
|
abi: ABI.Hub,
|
|
382
391
|
functionName: 'notifySharePrice',
|
|
383
|
-
args: [self.pool.id.raw, self.id.raw, id],
|
|
392
|
+
args: [self.pool.id.raw, self.id.raw, id, ctx.signingAddress],
|
|
384
393
|
}));
|
|
385
394
|
addMessage(id, MessageType.NotifyPricePoolPerShare);
|
|
386
395
|
}
|
|
@@ -390,81 +399,75 @@ export class ShareClass extends Entity {
|
|
|
390
399
|
data: batch,
|
|
391
400
|
messages,
|
|
392
401
|
});
|
|
393
|
-
}, this.pool.
|
|
402
|
+
}, this.pool.centrifugeId);
|
|
394
403
|
}
|
|
395
404
|
setMaxAssetPriceAge(assetId, maxPriceAge) {
|
|
396
405
|
const self = this;
|
|
397
406
|
return this._transact(async function* (ctx) {
|
|
398
|
-
const { hub } = await self._root._protocolAddresses(self.pool.
|
|
407
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
399
408
|
yield* wrapTransaction('Set max asset price age', ctx, {
|
|
400
409
|
contract: hub,
|
|
401
410
|
data: encodeFunctionData({
|
|
402
411
|
abi: ABI.Hub,
|
|
403
412
|
functionName: 'setMaxAssetPriceAge',
|
|
404
|
-
args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
|
|
413
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge), ctx.signingAddress],
|
|
405
414
|
}),
|
|
406
415
|
messages: {
|
|
407
|
-
[assetId.centrifugeId]: [MessageType.
|
|
416
|
+
[assetId.centrifugeId]: [MessageType.SetMaxAssetPriceAge],
|
|
408
417
|
},
|
|
409
418
|
});
|
|
410
|
-
}, this.pool.
|
|
419
|
+
}, this.pool.centrifugeId);
|
|
411
420
|
}
|
|
412
|
-
setMaxSharePriceAge(
|
|
421
|
+
setMaxSharePriceAge(centrifugeId, maxPriceAge) {
|
|
413
422
|
const self = this;
|
|
414
423
|
return this._transact(async function* (ctx) {
|
|
415
|
-
const
|
|
416
|
-
self._root._protocolAddresses(self.pool.chainId),
|
|
417
|
-
self._root.id(chainId),
|
|
418
|
-
]);
|
|
424
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
419
425
|
yield* wrapTransaction('Set max share price age', ctx, {
|
|
420
426
|
contract: hub,
|
|
421
427
|
data: encodeFunctionData({
|
|
422
428
|
abi: ABI.Hub,
|
|
423
429
|
functionName: 'setMaxSharePriceAge',
|
|
424
|
-
args: [
|
|
430
|
+
args: [self.pool.id.raw, self.id.raw, centrifugeId, BigInt(maxPriceAge), ctx.signingAddress],
|
|
425
431
|
}),
|
|
426
432
|
messages: {
|
|
427
|
-
[
|
|
433
|
+
[centrifugeId]: [MessageType.SetMaxSharePriceAge],
|
|
428
434
|
},
|
|
429
435
|
});
|
|
430
|
-
}, this.pool.
|
|
436
|
+
}, this.pool.centrifugeId);
|
|
431
437
|
}
|
|
432
438
|
notifyAssetPrice(assetId) {
|
|
433
439
|
const self = this;
|
|
434
440
|
return this._transact(async function* (ctx) {
|
|
435
|
-
const { hub } = await self._root._protocolAddresses(self.pool.
|
|
441
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
436
442
|
yield* wrapTransaction('Notify asset price', ctx, {
|
|
437
443
|
contract: hub,
|
|
438
444
|
data: encodeFunctionData({
|
|
439
445
|
abi: ABI.Hub,
|
|
440
446
|
functionName: 'notifyAssetPrice',
|
|
441
|
-
args: [self.pool.id.raw, self.id.raw, assetId.raw],
|
|
447
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, ctx.signingAddress],
|
|
442
448
|
}),
|
|
443
449
|
messages: {
|
|
444
450
|
[assetId.centrifugeId]: [MessageType.NotifyPricePoolPerAsset],
|
|
445
451
|
},
|
|
446
452
|
});
|
|
447
|
-
}, this.pool.
|
|
453
|
+
}, this.pool.centrifugeId);
|
|
448
454
|
}
|
|
449
|
-
notifySharePrice(
|
|
455
|
+
notifySharePrice(centrifugeId) {
|
|
450
456
|
const self = this;
|
|
451
457
|
return this._transact(async function* (ctx) {
|
|
452
|
-
const
|
|
453
|
-
self._root._protocolAddresses(self.pool.chainId),
|
|
454
|
-
self._root.id(chainId),
|
|
455
|
-
]);
|
|
458
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
456
459
|
yield* wrapTransaction('Notify share price', ctx, {
|
|
457
460
|
contract: hub,
|
|
458
461
|
data: encodeFunctionData({
|
|
459
462
|
abi: ABI.Hub,
|
|
460
463
|
functionName: 'notifySharePrice',
|
|
461
|
-
args: [self.pool.id.raw, self.id.raw,
|
|
464
|
+
args: [self.pool.id.raw, self.id.raw, centrifugeId, ctx.signingAddress],
|
|
462
465
|
}),
|
|
463
466
|
messages: {
|
|
464
|
-
[
|
|
467
|
+
[centrifugeId]: [MessageType.NotifyPricePoolPerShare],
|
|
465
468
|
},
|
|
466
469
|
});
|
|
467
|
-
}, this.pool.
|
|
470
|
+
}, this.pool.centrifugeId);
|
|
468
471
|
}
|
|
469
472
|
/**
|
|
470
473
|
* Approve deposits and issue shares for the given assets.
|
|
@@ -474,20 +477,18 @@ export class ShareClass extends Entity {
|
|
|
474
477
|
approveDepositsAndIssueShares(assets) {
|
|
475
478
|
const self = this;
|
|
476
479
|
return this._transact(async function* (ctx) {
|
|
477
|
-
const [{
|
|
478
|
-
self._root._protocolAddresses(self.pool.
|
|
479
|
-
self._root.id(self.pool.chainId),
|
|
480
|
+
const [{ batchRequestManager }, pendingAmounts, orders] = await Promise.all([
|
|
481
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
480
482
|
self.pendingAmounts(),
|
|
481
483
|
firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
|
|
482
484
|
if (orders.outstandingInvests.length === 0)
|
|
483
485
|
return of([]);
|
|
484
486
|
return combineLatest(orders.outstandingInvests.map((order) => self._investorOrder(order.assetId, order.investor)));
|
|
485
487
|
}))),
|
|
486
|
-
self._root._maxBatchGasLimit(self.pool.chainId),
|
|
487
488
|
]);
|
|
488
|
-
const assetsWithApprove = assets.filter((a) => a
|
|
489
|
-
const assetsWithIssue = assets.filter((a) => a
|
|
490
|
-
const gasLimitPerAsset = assetsWithIssue ?
|
|
489
|
+
const assetsWithApprove = assets.filter((a) => 'approveAssetAmount' in a).length;
|
|
490
|
+
const assetsWithIssue = assets.filter((a) => 'issuePricePerShare' in a).length;
|
|
491
|
+
const gasLimitPerAsset = assetsWithIssue ? GAS_LIMIT / BigInt(assetsWithIssue) : 0n;
|
|
491
492
|
const estimatePerMessage = 700000n;
|
|
492
493
|
const estimatePerMessageIfLocal = 360000n;
|
|
493
494
|
const ordersByAssetId = {};
|
|
@@ -511,14 +512,14 @@ export class ShareClass extends Entity {
|
|
|
511
512
|
messages[centId].push(message);
|
|
512
513
|
}
|
|
513
514
|
for (const asset of assets) {
|
|
514
|
-
const gasPerMessage = asset.assetId.centrifugeId ===
|
|
515
|
+
const gasPerMessage = asset.assetId.centrifugeId === self.pool.centrifugeId ? estimatePerMessageIfLocal : estimatePerMessage;
|
|
515
516
|
let gasLeft = gasLimitPerAsset;
|
|
516
517
|
const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
|
|
517
518
|
if (!pending) {
|
|
518
519
|
throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
|
|
519
520
|
}
|
|
520
521
|
let nowDepositEpoch = pending?.depositEpoch;
|
|
521
|
-
if (asset
|
|
522
|
+
if ('approveAssetAmount' in asset) {
|
|
522
523
|
if (asset.approveAssetAmount.gt(pending.pendingDeposit)) {
|
|
523
524
|
throw new Error(`Approve amount exceeds pending amount for asset "${asset.assetId.toString()}"`);
|
|
524
525
|
}
|
|
@@ -526,7 +527,7 @@ export class ShareClass extends Entity {
|
|
|
526
527
|
throw new Error(`Approve amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
527
528
|
}
|
|
528
529
|
batch.push(encodeFunctionData({
|
|
529
|
-
abi: ABI.
|
|
530
|
+
abi: ABI.BatchRequestManager,
|
|
530
531
|
functionName: 'approveDeposits',
|
|
531
532
|
args: [
|
|
532
533
|
self.pool.id.raw,
|
|
@@ -534,6 +535,8 @@ export class ShareClass extends Entity {
|
|
|
534
535
|
asset.assetId.raw,
|
|
535
536
|
nowDepositEpoch,
|
|
536
537
|
asset.approveAssetAmount.toBigInt(),
|
|
538
|
+
asset.approvePricePerAsset.toBigInt(),
|
|
539
|
+
ctx.signingAddress,
|
|
537
540
|
],
|
|
538
541
|
}));
|
|
539
542
|
addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
|
|
@@ -541,7 +544,7 @@ export class ShareClass extends Entity {
|
|
|
541
544
|
nowDepositEpoch++;
|
|
542
545
|
}
|
|
543
546
|
const nowIssueEpoch = pending.issueEpoch;
|
|
544
|
-
if (asset
|
|
547
|
+
if ('issuePricePerShare' in asset) {
|
|
545
548
|
if (nowIssueEpoch >= nowDepositEpoch)
|
|
546
549
|
throw new Error('Nothing to issue');
|
|
547
550
|
let i;
|
|
@@ -555,9 +558,17 @@ export class ShareClass extends Entity {
|
|
|
555
558
|
throw new Error(`Issue price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
556
559
|
}
|
|
557
560
|
batch.push(encodeFunctionData({
|
|
558
|
-
abi: ABI.
|
|
561
|
+
abi: ABI.BatchRequestManager,
|
|
559
562
|
functionName: 'issueShares',
|
|
560
|
-
args: [
|
|
563
|
+
args: [
|
|
564
|
+
self.pool.id.raw,
|
|
565
|
+
self.id.raw,
|
|
566
|
+
asset.assetId.raw,
|
|
567
|
+
nowIssueEpoch + i,
|
|
568
|
+
price.toBigInt(),
|
|
569
|
+
0n,
|
|
570
|
+
ctx.signingAddress,
|
|
571
|
+
],
|
|
561
572
|
}));
|
|
562
573
|
addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
|
|
563
574
|
gasLeft -= gasPerMessage;
|
|
@@ -569,7 +580,7 @@ export class ShareClass extends Entity {
|
|
|
569
580
|
assetOrders?.slice(0, claims).forEach((order) => {
|
|
570
581
|
if (order.pendingDeposit > 0n) {
|
|
571
582
|
batch.push(encodeFunctionData({
|
|
572
|
-
abi: ABI.
|
|
583
|
+
abi: ABI.BatchRequestManager,
|
|
573
584
|
functionName: 'notifyDeposit',
|
|
574
585
|
args: [
|
|
575
586
|
self.pool.id.raw,
|
|
@@ -577,6 +588,7 @@ export class ShareClass extends Entity {
|
|
|
577
588
|
asset.assetId.raw,
|
|
578
589
|
addressToBytes32(order.investor),
|
|
579
590
|
order.maxDepositClaims + i, // +i to ensure the additional epochs that are being issued are included
|
|
591
|
+
ctx.signingAddress,
|
|
580
592
|
],
|
|
581
593
|
}));
|
|
582
594
|
addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
|
|
@@ -596,11 +608,11 @@ export class ShareClass extends Entity {
|
|
|
596
608
|
title = 'Approve';
|
|
597
609
|
}
|
|
598
610
|
yield* wrapTransaction(title, ctx, {
|
|
599
|
-
contract:
|
|
611
|
+
contract: batchRequestManager,
|
|
600
612
|
data: batch,
|
|
601
613
|
messages,
|
|
602
614
|
});
|
|
603
|
-
}, this.pool.
|
|
615
|
+
}, this.pool.centrifugeId);
|
|
604
616
|
}
|
|
605
617
|
/**
|
|
606
618
|
* Approve redeems and revoke shares for the given assets.
|
|
@@ -610,20 +622,18 @@ export class ShareClass extends Entity {
|
|
|
610
622
|
approveRedeemsAndRevokeShares(assets) {
|
|
611
623
|
const self = this;
|
|
612
624
|
return this._transact(async function* (ctx) {
|
|
613
|
-
const [{
|
|
614
|
-
self._root._protocolAddresses(self.pool.
|
|
615
|
-
self._root.id(self.pool.chainId),
|
|
625
|
+
const [{ batchRequestManager }, pendingAmounts, orders] = await Promise.all([
|
|
626
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
616
627
|
self.pendingAmounts(),
|
|
617
628
|
firstValueFrom(self._investorOrders().pipe(switchMap((orders) => {
|
|
618
629
|
if (orders.outstandingRedeems.length === 0)
|
|
619
630
|
return of([]);
|
|
620
631
|
return combineLatest(orders.outstandingRedeems.map((order) => self._investorOrder(order.assetId, order.investor)));
|
|
621
632
|
}))),
|
|
622
|
-
self._root._maxBatchGasLimit(self.pool.chainId),
|
|
623
633
|
]);
|
|
624
|
-
const assetsWithApprove = assets.filter((a) => a
|
|
625
|
-
const assetsWithRevoke = assets.filter((a) => a
|
|
626
|
-
const gasLimitPerAsset = assetsWithRevoke ?
|
|
634
|
+
const assetsWithApprove = assets.filter((a) => 'approveShareAmount' in a).length;
|
|
635
|
+
const assetsWithRevoke = assets.filter((a) => 'revokePricePerShare' in a).length;
|
|
636
|
+
const gasLimitPerAsset = assetsWithRevoke ? GAS_LIMIT / BigInt(assetsWithRevoke) : 0n;
|
|
627
637
|
const estimatePerMessage = 700000n;
|
|
628
638
|
const estimatePerMessageIfLocal = 360000n;
|
|
629
639
|
const ordersByAssetId = {};
|
|
@@ -647,14 +657,14 @@ export class ShareClass extends Entity {
|
|
|
647
657
|
messages[centId].push(message);
|
|
648
658
|
}
|
|
649
659
|
for (const asset of assets) {
|
|
650
|
-
const gasPerMessage = asset.assetId.centrifugeId ===
|
|
660
|
+
const gasPerMessage = asset.assetId.centrifugeId === self.pool.centrifugeId ? estimatePerMessageIfLocal : estimatePerMessage;
|
|
651
661
|
let gasLeft = gasLimitPerAsset;
|
|
652
662
|
const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
|
|
653
663
|
if (!pending) {
|
|
654
664
|
throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
|
|
655
665
|
}
|
|
656
666
|
let nowRedeemEpoch = pending.redeemEpoch;
|
|
657
|
-
if (asset
|
|
667
|
+
if ('approveShareAmount' in asset) {
|
|
658
668
|
if (asset.approveShareAmount.gt(pending.pendingRedeem)) {
|
|
659
669
|
throw new Error(`Share amount exceeds pending redeem for asset "${asset.assetId.toString()}"`);
|
|
660
670
|
}
|
|
@@ -662,7 +672,7 @@ export class ShareClass extends Entity {
|
|
|
662
672
|
throw new Error(`Share amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
663
673
|
}
|
|
664
674
|
batch.push(encodeFunctionData({
|
|
665
|
-
abi: ABI.
|
|
675
|
+
abi: ABI.BatchRequestManager,
|
|
666
676
|
functionName: 'approveRedeems',
|
|
667
677
|
args: [
|
|
668
678
|
self.pool.id.raw,
|
|
@@ -670,12 +680,13 @@ export class ShareClass extends Entity {
|
|
|
670
680
|
asset.assetId.raw,
|
|
671
681
|
nowRedeemEpoch,
|
|
672
682
|
asset.approveShareAmount.toBigInt(),
|
|
683
|
+
asset.approvePricePerAsset.toBigInt(),
|
|
673
684
|
],
|
|
674
685
|
}));
|
|
675
686
|
nowRedeemEpoch++;
|
|
676
687
|
}
|
|
677
688
|
const nowRevokeEpoch = pending.revokeEpoch;
|
|
678
|
-
if (asset
|
|
689
|
+
if ('revokePricePerShare' in asset) {
|
|
679
690
|
if (nowRevokeEpoch >= nowRedeemEpoch)
|
|
680
691
|
throw new Error('Nothing to revoke');
|
|
681
692
|
let i;
|
|
@@ -689,9 +700,17 @@ export class ShareClass extends Entity {
|
|
|
689
700
|
throw new Error(`Revoke price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
|
|
690
701
|
}
|
|
691
702
|
batch.push(encodeFunctionData({
|
|
692
|
-
abi: ABI.
|
|
703
|
+
abi: ABI.BatchRequestManager,
|
|
693
704
|
functionName: 'revokeShares',
|
|
694
|
-
args: [
|
|
705
|
+
args: [
|
|
706
|
+
self.pool.id.raw,
|
|
707
|
+
self.id.raw,
|
|
708
|
+
asset.assetId.raw,
|
|
709
|
+
nowRevokeEpoch + i,
|
|
710
|
+
price.toBigInt(),
|
|
711
|
+
0n,
|
|
712
|
+
ctx.signingAddress,
|
|
713
|
+
],
|
|
695
714
|
}));
|
|
696
715
|
addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
|
|
697
716
|
gasLeft -= gasPerMessage;
|
|
@@ -703,7 +722,7 @@ export class ShareClass extends Entity {
|
|
|
703
722
|
assetOrders?.slice(0, claims).forEach((order) => {
|
|
704
723
|
if (order.pendingRedeem > 0n) {
|
|
705
724
|
batch.push(encodeFunctionData({
|
|
706
|
-
abi: ABI.
|
|
725
|
+
abi: ABI.BatchRequestManager,
|
|
707
726
|
functionName: 'notifyRedeem',
|
|
708
727
|
args: [
|
|
709
728
|
self.pool.id.raw,
|
|
@@ -711,6 +730,7 @@ export class ShareClass extends Entity {
|
|
|
711
730
|
asset.assetId.raw,
|
|
712
731
|
addressToBytes32(order.investor),
|
|
713
732
|
order.maxRedeemClaims + 1, // +1 to ensure the order that's being issued is included
|
|
733
|
+
ctx.signingAddress,
|
|
714
734
|
],
|
|
715
735
|
}));
|
|
716
736
|
addMessage(asset.assetId.centrifugeId, MessageType.RequestCallback);
|
|
@@ -730,11 +750,11 @@ export class ShareClass extends Entity {
|
|
|
730
750
|
title = 'Approve';
|
|
731
751
|
}
|
|
732
752
|
yield* wrapTransaction(title, ctx, {
|
|
733
|
-
contract:
|
|
753
|
+
contract: batchRequestManager,
|
|
734
754
|
data: batch,
|
|
735
755
|
messages,
|
|
736
756
|
});
|
|
737
|
-
}, this.pool.
|
|
757
|
+
}, this.pool.centrifugeId);
|
|
738
758
|
}
|
|
739
759
|
/**
|
|
740
760
|
* Claim a deposit on the Hub side for the given asset and investor after the shares have been issued.
|
|
@@ -743,14 +763,14 @@ export class ShareClass extends Entity {
|
|
|
743
763
|
claimDeposit(assetId, investor) {
|
|
744
764
|
const self = this;
|
|
745
765
|
return this._transact(async function* (ctx) {
|
|
746
|
-
const [{
|
|
747
|
-
self._root._protocolAddresses(self.pool.
|
|
766
|
+
const [{ batchRequestManager }, investorOrder] = await Promise.all([
|
|
767
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
748
768
|
self._investorOrder(assetId, investor),
|
|
749
769
|
]);
|
|
750
770
|
yield* wrapTransaction('Claim deposit', ctx, {
|
|
751
|
-
contract:
|
|
771
|
+
contract: batchRequestManager,
|
|
752
772
|
data: encodeFunctionData({
|
|
753
|
-
abi: ABI.
|
|
773
|
+
abi: ABI.BatchRequestManager,
|
|
754
774
|
functionName: 'notifyDeposit',
|
|
755
775
|
args: [
|
|
756
776
|
self.pool.id.raw,
|
|
@@ -758,11 +778,12 @@ export class ShareClass extends Entity {
|
|
|
758
778
|
assetId.raw,
|
|
759
779
|
addressToBytes32(investor),
|
|
760
780
|
investorOrder.maxDepositClaims,
|
|
781
|
+
ctx.signingAddress,
|
|
761
782
|
],
|
|
762
783
|
}),
|
|
763
784
|
messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
|
|
764
785
|
});
|
|
765
|
-
}, this.pool.
|
|
786
|
+
}, this.pool.centrifugeId);
|
|
766
787
|
}
|
|
767
788
|
/**
|
|
768
789
|
* Claim a redemption on the Hub side for the given asset and investor after the shares have been revoked.
|
|
@@ -771,44 +792,48 @@ export class ShareClass extends Entity {
|
|
|
771
792
|
claimRedeem(assetId, investor) {
|
|
772
793
|
const self = this;
|
|
773
794
|
return this._transact(async function* (ctx) {
|
|
774
|
-
const [{
|
|
775
|
-
self._root._protocolAddresses(self.pool.
|
|
795
|
+
const [{ batchRequestManager }, investorOrder] = await Promise.all([
|
|
796
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
776
797
|
self._investorOrder(assetId, investor),
|
|
777
798
|
]);
|
|
778
799
|
yield* wrapTransaction('Claim redeem', ctx, {
|
|
779
|
-
contract:
|
|
800
|
+
contract: batchRequestManager,
|
|
780
801
|
data: encodeFunctionData({
|
|
781
|
-
abi: ABI.
|
|
802
|
+
abi: ABI.BatchRequestManager,
|
|
782
803
|
functionName: 'notifyRedeem',
|
|
783
|
-
args: [
|
|
804
|
+
args: [
|
|
805
|
+
self.pool.id.raw,
|
|
806
|
+
self.id.raw,
|
|
807
|
+
assetId.raw,
|
|
808
|
+
addressToBytes32(investor),
|
|
809
|
+
investorOrder.maxRedeemClaims,
|
|
810
|
+
ctx.signingAddress,
|
|
811
|
+
],
|
|
784
812
|
}),
|
|
785
813
|
messages: { [assetId.centrifugeId]: [MessageType.RequestCallback] },
|
|
786
814
|
});
|
|
787
|
-
}, this.pool.
|
|
815
|
+
}, this.pool.centrifugeId);
|
|
788
816
|
}
|
|
789
817
|
/**
|
|
790
818
|
* Update a member of the share class.
|
|
791
819
|
* @param address Address of the investor
|
|
792
820
|
* @param validUntil Time in seconds from Unix epoch until the investor is valid
|
|
793
|
-
* @param
|
|
821
|
+
* @param centrifugeId Centrifuge ID of the network on which to update the member
|
|
794
822
|
*/
|
|
795
|
-
updateMember(address, validUntil,
|
|
796
|
-
return this.updateMembers([{ address, validUntil,
|
|
823
|
+
updateMember(address, validUntil, centrifugeId) {
|
|
824
|
+
return this.updateMembers([{ address, validUntil, centrifugeId }]);
|
|
797
825
|
}
|
|
798
826
|
/**
|
|
799
827
|
* Batch update a list of members of the share class.
|
|
800
|
-
* @param members Array of members to update, each with address, validUntil and
|
|
828
|
+
* @param members Array of members to update, each with address, validUntil and centrifugeId
|
|
801
829
|
* @param members.address Address of the investor
|
|
802
830
|
* @param members.validUntil Time in seconds from Unix epoch until the investor is valid
|
|
803
|
-
* @param members.
|
|
831
|
+
* @param members.centrifugeId Centrifuge ID of the network on which to update the member
|
|
804
832
|
*/
|
|
805
833
|
updateMembers(members) {
|
|
806
834
|
const self = this;
|
|
807
835
|
return this._transact(async function* (ctx) {
|
|
808
|
-
const
|
|
809
|
-
self._root._protocolAddresses(self.pool.chainId),
|
|
810
|
-
...members.map((m) => self._root.id(m.chainId)),
|
|
811
|
-
]);
|
|
836
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
812
837
|
const batch = [];
|
|
813
838
|
const messages = {};
|
|
814
839
|
function addMessage(centId, message) {
|
|
@@ -816,23 +841,20 @@ export class ShareClass extends Entity {
|
|
|
816
841
|
messages[centId] = [];
|
|
817
842
|
messages[centId].push(message);
|
|
818
843
|
}
|
|
819
|
-
members.forEach((member
|
|
820
|
-
const id = ids[index];
|
|
821
|
-
if (!id) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
844
|
+
members.forEach((member) => {
|
|
824
845
|
batch.push(encodeFunctionData({
|
|
825
846
|
abi: ABI.Hub,
|
|
826
847
|
functionName: 'updateRestriction',
|
|
827
848
|
args: [
|
|
828
849
|
self.pool.id.raw,
|
|
829
850
|
self.id.raw,
|
|
830
|
-
|
|
851
|
+
member.centrifugeId,
|
|
831
852
|
encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(member.address), BigInt(member.validUntil)]),
|
|
832
853
|
0n,
|
|
854
|
+
ctx.signingAddress,
|
|
833
855
|
],
|
|
834
856
|
}));
|
|
835
|
-
addMessage(
|
|
857
|
+
addMessage(member.centrifugeId, MessageType.UpdateRestriction);
|
|
836
858
|
});
|
|
837
859
|
if (batch.length === 0) {
|
|
838
860
|
throw new Error('No data to update members');
|
|
@@ -842,7 +864,7 @@ export class ShareClass extends Entity {
|
|
|
842
864
|
data: batch,
|
|
843
865
|
messages,
|
|
844
866
|
});
|
|
845
|
-
}, this.pool.
|
|
867
|
+
}, this.pool.centrifugeId);
|
|
846
868
|
}
|
|
847
869
|
/**
|
|
848
870
|
* Retrieve all holders of the share class.
|
|
@@ -873,11 +895,10 @@ export class ShareClass extends Entity {
|
|
|
873
895
|
orderBy,
|
|
874
896
|
orderDirection,
|
|
875
897
|
], () => combineLatest([
|
|
876
|
-
this._root._deployments(),
|
|
877
898
|
this.pool.currency(),
|
|
878
899
|
this._investorOrders(),
|
|
879
900
|
this._tokenInstancePositions({ limit, offset, orderBy, orderDirection, filter }),
|
|
880
|
-
]).pipe(switchMap(([
|
|
901
|
+
]).pipe(switchMap(([poolCurrency, { outstandingInvests, outstandingRedeems }, { items: tokenInstancePositions, assets, pageInfo, totalCount },]) => {
|
|
881
902
|
// Handle empty positions case or else combineLatest([]) can hang indefinitely
|
|
882
903
|
if (tokenInstancePositions.length === 0) {
|
|
883
904
|
return of({
|
|
@@ -891,11 +912,10 @@ export class ShareClass extends Entity {
|
|
|
891
912
|
centrifugeId: position.centrifugeId,
|
|
892
913
|
tokenId: this.id.raw,
|
|
893
914
|
}).pipe(catchError(() => of(null))));
|
|
894
|
-
const chainsById = new Map(deployments.blockchains.items.map((chain) => [chain.centrifugeId, chain.id]));
|
|
895
915
|
return combineLatest(whitelistedQueries).pipe(map((whitelistResults) => {
|
|
896
916
|
const investors = tokenInstancePositions.map((position, i) => {
|
|
897
917
|
const whitelistData = whitelistResults[i];
|
|
898
|
-
const
|
|
918
|
+
const centrifugeId = Number(position.centrifugeId);
|
|
899
919
|
const outstandingInvest = outstandingInvests.find((order) => order.investor === position.accountAddress);
|
|
900
920
|
const outstandingRedeem = outstandingRedeems.find((order) => order.investor === position.accountAddress);
|
|
901
921
|
const assetId = outstandingInvest?.assetId.toString();
|
|
@@ -906,7 +926,7 @@ export class ShareClass extends Entity {
|
|
|
906
926
|
return {
|
|
907
927
|
address: position.accountAddress,
|
|
908
928
|
amount: new Balance(outstandingInvest?.pendingAmount ?? 0n, assetDecimals),
|
|
909
|
-
|
|
929
|
+
centrifugeId,
|
|
910
930
|
createdAt: whitelistData?.createdAt ?? '',
|
|
911
931
|
holdings: new Balance(position.balance, poolCurrency.decimals),
|
|
912
932
|
isFrozen: whitelistData?.isFrozen ?? position.isFrozen,
|
|
@@ -947,12 +967,7 @@ export class ShareClass extends Entity {
|
|
|
947
967
|
whitelistedHolders(options) {
|
|
948
968
|
const limit = options?.limit ?? 20;
|
|
949
969
|
const offset = options?.offset ?? 0;
|
|
950
|
-
return this._query(['whitelistedHolders', this.id.raw, limit, offset], () => combineLatest([
|
|
951
|
-
this._root._deployments(),
|
|
952
|
-
this.pool.currency(),
|
|
953
|
-
this._investorOrders(),
|
|
954
|
-
this._whitelistedInvestors({ limit, offset }),
|
|
955
|
-
]).pipe(switchMap(([deployments, poolCurrency, { outstandingInvests, outstandingRedeems }, { items: whitelistedInvestors, assets, pageInfo, totalCount },]) => {
|
|
970
|
+
return this._query(['whitelistedHolders', this.id.raw, limit, offset], () => combineLatest([this.pool.currency(), this._investorOrders(), this._whitelistedInvestors({ limit, offset })]).pipe(switchMap(([poolCurrency, { outstandingInvests, outstandingRedeems }, { items: whitelistedInvestors, assets, pageInfo, totalCount },]) => {
|
|
956
971
|
if (whitelistedInvestors.length === 0) {
|
|
957
972
|
return of({
|
|
958
973
|
investors: [],
|
|
@@ -965,11 +980,9 @@ export class ShareClass extends Entity {
|
|
|
965
980
|
centrifugeId: investor.centrifugeId,
|
|
966
981
|
tokenId: this.id.raw,
|
|
967
982
|
}).pipe(catchError(() => of(null))));
|
|
968
|
-
const chainsById = new Map(deployments.blockchains.items.map((chain) => [chain.centrifugeId, chain.id]));
|
|
969
983
|
return combineLatest(positionQueries).pipe(map((positionResults) => {
|
|
970
984
|
const investors = whitelistedInvestors.map((investor, i) => {
|
|
971
985
|
const positionData = positionResults[i];
|
|
972
|
-
const chainId = Number(chainsById.get(investor.centrifugeId));
|
|
973
986
|
const outstandingInvest = outstandingInvests.find((order) => order.investor === investor.address);
|
|
974
987
|
const outstandingRedeem = outstandingRedeems.find((order) => order.investor === investor.address);
|
|
975
988
|
const assetId = outstandingInvest?.assetId.toString();
|
|
@@ -979,7 +992,7 @@ export class ShareClass extends Entity {
|
|
|
979
992
|
return {
|
|
980
993
|
address: investor.address,
|
|
981
994
|
amount: new Balance(outstandingInvest?.pendingAmount ?? 0n, assetDecimals),
|
|
982
|
-
|
|
995
|
+
centrifugeId: Number(investor.centrifugeId),
|
|
983
996
|
createdAt: investor.createdAt,
|
|
984
997
|
holdings: new Balance(positionBalance, poolCurrency.decimals),
|
|
985
998
|
isFrozen: investor.isFrozen ?? positionData?.isFrozen,
|
|
@@ -1040,13 +1053,15 @@ export class ShareClass extends Entity {
|
|
|
1040
1053
|
}
|
|
1041
1054
|
/**
|
|
1042
1055
|
* Freeze a member of the share class.
|
|
1056
|
+
* @param address Address to freeze
|
|
1057
|
+
* @param centrifugeId Centrifuge ID of the network on which to freeze the member
|
|
1043
1058
|
*/
|
|
1044
|
-
freezeMember(address,
|
|
1059
|
+
freezeMember(address, centrifugeId) {
|
|
1045
1060
|
const self = this;
|
|
1046
1061
|
return this._transact(async function* (ctx) {
|
|
1047
1062
|
const [share, restrictionManager] = await Promise.all([
|
|
1048
|
-
firstValueFrom(self._share(
|
|
1049
|
-
firstValueFrom(self._restrictionManager(
|
|
1063
|
+
firstValueFrom(self._share(centrifugeId)),
|
|
1064
|
+
firstValueFrom(self._restrictionManager(centrifugeId)),
|
|
1050
1065
|
]);
|
|
1051
1066
|
yield* wrapTransaction('Freeze member', ctx, {
|
|
1052
1067
|
contract: restrictionManager,
|
|
@@ -1056,17 +1071,19 @@ export class ShareClass extends Entity {
|
|
|
1056
1071
|
args: [share, address],
|
|
1057
1072
|
}),
|
|
1058
1073
|
});
|
|
1059
|
-
},
|
|
1074
|
+
}, centrifugeId);
|
|
1060
1075
|
}
|
|
1061
1076
|
/**
|
|
1062
1077
|
* Unfreeze a member of the share class
|
|
1078
|
+
* @param address Address to unfreeze
|
|
1079
|
+
* @param centrifugeId Centrifuge ID of the network on which to unfreeze the member
|
|
1063
1080
|
*/
|
|
1064
|
-
unfreezeMember(address,
|
|
1081
|
+
unfreezeMember(address, centrifugeId) {
|
|
1065
1082
|
const self = this;
|
|
1066
1083
|
return this._transact(async function* (ctx) {
|
|
1067
1084
|
const [share, restrictionManager] = await Promise.all([
|
|
1068
|
-
firstValueFrom(self._share(
|
|
1069
|
-
firstValueFrom(self._restrictionManager(
|
|
1085
|
+
firstValueFrom(self._share(centrifugeId)),
|
|
1086
|
+
firstValueFrom(self._restrictionManager(centrifugeId)),
|
|
1070
1087
|
]);
|
|
1071
1088
|
yield* wrapTransaction('Unfreeze member', ctx, {
|
|
1072
1089
|
contract: restrictionManager,
|
|
@@ -1076,14 +1093,14 @@ export class ShareClass extends Entity {
|
|
|
1076
1093
|
args: [share, address],
|
|
1077
1094
|
}),
|
|
1078
1095
|
});
|
|
1079
|
-
},
|
|
1096
|
+
}, centrifugeId);
|
|
1080
1097
|
}
|
|
1081
1098
|
/**
|
|
1082
1099
|
* Get the pending and claimable investment/redeem amounts for all investors
|
|
1083
1100
|
* in a given share class (per vault/chain)
|
|
1084
1101
|
*/
|
|
1085
|
-
investmentsByVault(
|
|
1086
|
-
return this._query(['investmentsByVault',
|
|
1102
|
+
investmentsByVault(centrifugeId) {
|
|
1103
|
+
return this._query(['investmentsByVault', centrifugeId], () => combineLatest([this._investorOrders(), this.vaults(centrifugeId), this.pendingAmounts()]).pipe(switchMap(([orders, vaults, pendingAmounts]) => {
|
|
1087
1104
|
if (!vaults.length)
|
|
1088
1105
|
return of([]);
|
|
1089
1106
|
const allInvestors = new Set();
|
|
@@ -1101,25 +1118,25 @@ export class ShareClass extends Entity {
|
|
|
1101
1118
|
.forEach((o) => vaultInvestors.add(o.investor));
|
|
1102
1119
|
if (vaultInvestors.size === 0)
|
|
1103
1120
|
return of([]);
|
|
1104
|
-
const pendingMatch = pendingAmounts.find((p) => p.assetId.equals(vault.assetId) && p.
|
|
1121
|
+
const pendingMatch = pendingAmounts.find((p) => p.assetId.equals(vault.assetId) && p.centrifugeId === vault.centrifugeId);
|
|
1105
1122
|
const allPendingIssuances = pendingMatch?.pendingIssuances ?? [];
|
|
1106
1123
|
const allPendingRevocations = pendingMatch?.pendingRevocations ?? [];
|
|
1107
1124
|
return combineLatest(Array.from(vaultInvestors).map((investor) => vault.investment(investor).pipe(map((investment) => {
|
|
1108
1125
|
const pendingIssuances = allPendingIssuances.map((epoch) => ({
|
|
1109
1126
|
...epoch,
|
|
1110
1127
|
assetId: vault.assetId,
|
|
1111
|
-
|
|
1128
|
+
centrifugeId: vault.centrifugeId,
|
|
1112
1129
|
}));
|
|
1113
1130
|
const pendingRevocations = allPendingRevocations.map((epoch) => ({
|
|
1114
1131
|
...epoch,
|
|
1115
1132
|
assetId: vault.assetId,
|
|
1116
|
-
|
|
1133
|
+
centrifugeId: vault.centrifugeId,
|
|
1117
1134
|
}));
|
|
1118
1135
|
return {
|
|
1119
1136
|
investor,
|
|
1120
1137
|
investment,
|
|
1121
1138
|
assetId: vault.assetId,
|
|
1122
|
-
|
|
1139
|
+
centrifugeId: vault.centrifugeId,
|
|
1123
1140
|
pendingIssuances,
|
|
1124
1141
|
pendingRevocations,
|
|
1125
1142
|
pendingMatch,
|
|
@@ -1128,7 +1145,7 @@ export class ShareClass extends Entity {
|
|
|
1128
1145
|
investor,
|
|
1129
1146
|
investment: null,
|
|
1130
1147
|
assetId: vault.assetId,
|
|
1131
|
-
|
|
1148
|
+
centrifugeId: vault.centrifugeId,
|
|
1132
1149
|
pendingIssuances: [],
|
|
1133
1150
|
pendingRevocations: [],
|
|
1134
1151
|
pendingMatch: null,
|
|
@@ -1169,7 +1186,7 @@ export class ShareClass extends Entity {
|
|
|
1169
1186
|
expandedRecords.push({
|
|
1170
1187
|
investor: inv.investor,
|
|
1171
1188
|
assetId: inv.assetId,
|
|
1172
|
-
|
|
1189
|
+
centrifugeId: inv.centrifugeId,
|
|
1173
1190
|
epoch: inv.pendingMatch.depositEpoch,
|
|
1174
1191
|
epochType: 'deposit',
|
|
1175
1192
|
investorAmount,
|
|
@@ -1188,7 +1205,7 @@ export class ShareClass extends Entity {
|
|
|
1188
1205
|
expandedRecords.push({
|
|
1189
1206
|
investor: inv.investor,
|
|
1190
1207
|
assetId: inv.assetId,
|
|
1191
|
-
|
|
1208
|
+
centrifugeId: inv.centrifugeId,
|
|
1192
1209
|
epoch: issuance.epoch,
|
|
1193
1210
|
epochType: 'issue',
|
|
1194
1211
|
investorAmount,
|
|
@@ -1207,7 +1224,7 @@ export class ShareClass extends Entity {
|
|
|
1207
1224
|
expandedRecords.push({
|
|
1208
1225
|
investor: inv.investor,
|
|
1209
1226
|
assetId: inv.assetId,
|
|
1210
|
-
|
|
1227
|
+
centrifugeId: inv.centrifugeId,
|
|
1211
1228
|
epoch: inv.pendingMatch.redeemEpoch,
|
|
1212
1229
|
epochType: 'redeem',
|
|
1213
1230
|
investorAmount,
|
|
@@ -1226,7 +1243,7 @@ export class ShareClass extends Entity {
|
|
|
1226
1243
|
expandedRecords.push({
|
|
1227
1244
|
investor: inv.investor,
|
|
1228
1245
|
assetId: inv.assetId,
|
|
1229
|
-
|
|
1246
|
+
centrifugeId: inv.centrifugeId,
|
|
1230
1247
|
epoch: revocation.epoch,
|
|
1231
1248
|
epochType: 'revoke',
|
|
1232
1249
|
investorAmount,
|
|
@@ -1265,15 +1282,10 @@ export class ShareClass extends Entity {
|
|
|
1265
1282
|
decimals
|
|
1266
1283
|
symbol
|
|
1267
1284
|
name
|
|
1268
|
-
|
|
1269
|
-
chainId
|
|
1270
|
-
}
|
|
1285
|
+
centrifugeId
|
|
1271
1286
|
}
|
|
1272
1287
|
token {
|
|
1273
1288
|
decimals
|
|
1274
|
-
blockchain {
|
|
1275
|
-
chainId
|
|
1276
|
-
}
|
|
1277
1289
|
}
|
|
1278
1290
|
}
|
|
1279
1291
|
}
|
|
@@ -1305,14 +1317,10 @@ export class ShareClass extends Entity {
|
|
|
1305
1317
|
decimals
|
|
1306
1318
|
symbol
|
|
1307
1319
|
name
|
|
1308
|
-
|
|
1309
|
-
chainId
|
|
1310
|
-
}
|
|
1320
|
+
centrifugeId
|
|
1311
1321
|
}
|
|
1312
1322
|
token {
|
|
1313
1323
|
decimals
|
|
1314
|
-
blockchain {
|
|
1315
|
-
chainId
|
|
1316
1324
|
}
|
|
1317
1325
|
}
|
|
1318
1326
|
}
|
|
@@ -1340,7 +1348,7 @@ export class ShareClass extends Entity {
|
|
|
1340
1348
|
name: epochData.asset.name,
|
|
1341
1349
|
decimals: epochData.asset.decimals,
|
|
1342
1350
|
},
|
|
1343
|
-
|
|
1351
|
+
centrifugeId: epochData.asset.centrifugeId,
|
|
1344
1352
|
token: {
|
|
1345
1353
|
decimals: epochData.token.decimals,
|
|
1346
1354
|
},
|
|
@@ -1365,7 +1373,7 @@ export class ShareClass extends Entity {
|
|
|
1365
1373
|
name: order.asset.name,
|
|
1366
1374
|
decimals: order.asset.decimals,
|
|
1367
1375
|
},
|
|
1368
|
-
|
|
1376
|
+
centrifugeId: order.asset.centrifugeId,
|
|
1369
1377
|
token: {
|
|
1370
1378
|
decimals: order.token.decimals,
|
|
1371
1379
|
},
|
|
@@ -1398,15 +1406,10 @@ export class ShareClass extends Entity {
|
|
|
1398
1406
|
decimals
|
|
1399
1407
|
symbol
|
|
1400
1408
|
name
|
|
1401
|
-
|
|
1402
|
-
chainId
|
|
1403
|
-
}
|
|
1409
|
+
centrifugeId
|
|
1404
1410
|
}
|
|
1405
1411
|
token {
|
|
1406
1412
|
decimals
|
|
1407
|
-
blockchain {
|
|
1408
|
-
chainId
|
|
1409
|
-
}
|
|
1410
1413
|
}
|
|
1411
1414
|
}
|
|
1412
1415
|
}
|
|
@@ -1438,15 +1441,10 @@ export class ShareClass extends Entity {
|
|
|
1438
1441
|
decimals
|
|
1439
1442
|
symbol
|
|
1440
1443
|
name
|
|
1441
|
-
|
|
1442
|
-
chainId
|
|
1443
|
-
}
|
|
1444
|
+
centrifugeId
|
|
1444
1445
|
}
|
|
1445
1446
|
token {
|
|
1446
1447
|
decimals
|
|
1447
|
-
blockchain {
|
|
1448
|
-
chainId
|
|
1449
|
-
}
|
|
1450
1448
|
}
|
|
1451
1449
|
}
|
|
1452
1450
|
}
|
|
@@ -1473,7 +1471,7 @@ export class ShareClass extends Entity {
|
|
|
1473
1471
|
name: epochData.asset.name,
|
|
1474
1472
|
decimals: epochData.asset.decimals,
|
|
1475
1473
|
},
|
|
1476
|
-
|
|
1474
|
+
centrifugeId: epochData.asset.centrifugeId,
|
|
1477
1475
|
token: {
|
|
1478
1476
|
decimals: epochData.token.decimals,
|
|
1479
1477
|
},
|
|
@@ -1498,7 +1496,7 @@ export class ShareClass extends Entity {
|
|
|
1498
1496
|
name: order.asset.name,
|
|
1499
1497
|
decimals: order.asset.decimals,
|
|
1500
1498
|
},
|
|
1501
|
-
|
|
1499
|
+
centrifugeId: order.asset.centrifugeId,
|
|
1502
1500
|
token: {
|
|
1503
1501
|
decimals: order.token.decimals,
|
|
1504
1502
|
},
|
|
@@ -1511,13 +1509,13 @@ export class ShareClass extends Entity {
|
|
|
1511
1509
|
}
|
|
1512
1510
|
/**
|
|
1513
1511
|
* Get the valuation contract address for this share class on a specific chain.
|
|
1514
|
-
* @param
|
|
1512
|
+
* @param centrifugeId
|
|
1515
1513
|
*/
|
|
1516
|
-
valuation(
|
|
1517
|
-
return this._query(['valuation',
|
|
1518
|
-
const valuation = await
|
|
1514
|
+
valuation(centrifugeId) {
|
|
1515
|
+
return this._query(['valuation', centrifugeId], () => combineLatest([this._root._protocolAddresses(centrifugeId), this._root.getClient(centrifugeId)]).pipe(switchMap(([{ syncManager }, client]) => defer(async () => {
|
|
1516
|
+
const valuation = await client.readContract({
|
|
1519
1517
|
address: syncManager,
|
|
1520
|
-
abi: ABI.
|
|
1518
|
+
abi: ABI.SyncManager,
|
|
1521
1519
|
functionName: 'valuation',
|
|
1522
1520
|
args: [this.pool.id.raw, this.id.raw],
|
|
1523
1521
|
});
|
|
@@ -1526,20 +1524,19 @@ export class ShareClass extends Entity {
|
|
|
1526
1524
|
address: syncManager,
|
|
1527
1525
|
eventName: ['SetValuation'],
|
|
1528
1526
|
filter: (events) => events.some((event) => event.args.poolId === this.pool.id.raw && event.args.scId === this.id.raw),
|
|
1529
|
-
},
|
|
1527
|
+
}, centrifugeId)))));
|
|
1530
1528
|
}
|
|
1531
1529
|
/**
|
|
1532
1530
|
* Set the default valuation contract for this share class on a specific chain.
|
|
1533
|
-
* @param
|
|
1531
|
+
* @param centrifugeId - The centrifuge ID where the valuation should be updated
|
|
1534
1532
|
* @param valuation - The address of the valuation contract
|
|
1535
1533
|
*/
|
|
1536
|
-
updateValuation(
|
|
1534
|
+
updateValuation(centrifugeId, valuation) {
|
|
1537
1535
|
const self = this;
|
|
1538
1536
|
return this._transact(async function* (ctx) {
|
|
1539
|
-
const [
|
|
1540
|
-
self._root.
|
|
1541
|
-
self._root._protocolAddresses(
|
|
1542
|
-
self._root._protocolAddresses(chainId),
|
|
1537
|
+
const [{ hub }, spokeAddresses] = await Promise.all([
|
|
1538
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
1539
|
+
self._root._protocolAddresses(centrifugeId),
|
|
1543
1540
|
]);
|
|
1544
1541
|
yield* wrapTransaction('Update valuation', ctx, {
|
|
1545
1542
|
contract: hub,
|
|
@@ -1549,55 +1546,52 @@ export class ShareClass extends Entity {
|
|
|
1549
1546
|
args: [
|
|
1550
1547
|
self.pool.id.raw,
|
|
1551
1548
|
self.id.raw,
|
|
1552
|
-
|
|
1549
|
+
centrifugeId,
|
|
1553
1550
|
addressToBytes32(spokeAddresses.syncManager),
|
|
1554
|
-
|
|
1551
|
+
encode([VaultManagerTrustedCall.Valuation, addressToBytes32(valuation)]),
|
|
1555
1552
|
0n,
|
|
1553
|
+
ctx.signingAddress,
|
|
1556
1554
|
],
|
|
1557
1555
|
}),
|
|
1558
|
-
messages: { [
|
|
1556
|
+
messages: { [centrifugeId]: [MessageType.TrustedContractUpdate] },
|
|
1559
1557
|
});
|
|
1560
|
-
}, this.pool.
|
|
1558
|
+
}, this.pool.centrifugeId);
|
|
1561
1559
|
}
|
|
1562
1560
|
/**
|
|
1563
1561
|
* Update the hook for this share class on a specific chain.
|
|
1564
|
-
* @param
|
|
1562
|
+
* @param centrifugeId - The centrifuge ID where the hook should be updated
|
|
1565
1563
|
* @param hook - The address of the new hook contract
|
|
1566
1564
|
*/
|
|
1567
|
-
updateHook(
|
|
1565
|
+
updateHook(centrifugeId, hook) {
|
|
1568
1566
|
const self = this;
|
|
1569
1567
|
return this._transact(async function* (ctx) {
|
|
1570
|
-
const
|
|
1571
|
-
self._root.id(chainId),
|
|
1572
|
-
self._root._protocolAddresses(self.pool.chainId),
|
|
1573
|
-
]);
|
|
1568
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
1574
1569
|
yield* wrapTransaction('Update hook', ctx, {
|
|
1575
1570
|
contract: hub,
|
|
1576
1571
|
data: encodeFunctionData({
|
|
1577
1572
|
abi: ABI.Hub,
|
|
1578
1573
|
functionName: 'updateShareHook',
|
|
1579
|
-
args: [self.pool.id.raw, self.id.raw,
|
|
1574
|
+
args: [self.pool.id.raw, self.id.raw, centrifugeId, addressToBytes32(hook), ctx.signingAddress],
|
|
1580
1575
|
}),
|
|
1581
|
-
messages: { [
|
|
1576
|
+
messages: { [centrifugeId]: [MessageType.UpdateShareHook] },
|
|
1582
1577
|
});
|
|
1583
|
-
}, this.pool.
|
|
1578
|
+
}, this.pool.centrifugeId);
|
|
1584
1579
|
}
|
|
1585
1580
|
/**
|
|
1586
1581
|
* Update both (or one of) the hook and valuation for this share class on a specific chain in a single transaction.
|
|
1587
|
-
* @param
|
|
1582
|
+
* @param centrifugeId - The centrifuge ID where the updates should be applied
|
|
1588
1583
|
* @param hook - The address of the new hook contract (optional)
|
|
1589
1584
|
* @param valuation - The address of the new valuation contract (optional)
|
|
1590
1585
|
*/
|
|
1591
|
-
updateHookAndValuation(
|
|
1586
|
+
updateHookAndValuation(centrifugeId, hook, valuation) {
|
|
1592
1587
|
if (!hook && !valuation) {
|
|
1593
1588
|
throw new Error('At least one of hook or valuation must be provided');
|
|
1594
1589
|
}
|
|
1595
1590
|
const self = this;
|
|
1596
1591
|
return this._transact(async function* (ctx) {
|
|
1597
|
-
const [
|
|
1598
|
-
self._root.
|
|
1599
|
-
self._root._protocolAddresses(
|
|
1600
|
-
self._root._protocolAddresses(chainId),
|
|
1592
|
+
const [{ hub }, spokeAddresses] = await Promise.all([
|
|
1593
|
+
self._root._protocolAddresses(self.pool.centrifugeId),
|
|
1594
|
+
self._root._protocolAddresses(centrifugeId),
|
|
1601
1595
|
]);
|
|
1602
1596
|
const calls = [];
|
|
1603
1597
|
const messages = [];
|
|
@@ -1605,7 +1599,7 @@ export class ShareClass extends Entity {
|
|
|
1605
1599
|
calls.push(encodeFunctionData({
|
|
1606
1600
|
abi: ABI.Hub,
|
|
1607
1601
|
functionName: 'updateShareHook',
|
|
1608
|
-
args: [self.pool.id.raw, self.id.raw,
|
|
1602
|
+
args: [self.pool.id.raw, self.id.raw, centrifugeId, addressToBytes32(hook), ctx.signingAddress],
|
|
1609
1603
|
}));
|
|
1610
1604
|
messages.push(MessageType.UpdateShareHook);
|
|
1611
1605
|
}
|
|
@@ -1616,21 +1610,22 @@ export class ShareClass extends Entity {
|
|
|
1616
1610
|
args: [
|
|
1617
1611
|
self.pool.id.raw,
|
|
1618
1612
|
self.id.raw,
|
|
1619
|
-
|
|
1613
|
+
centrifugeId,
|
|
1620
1614
|
addressToBytes32(spokeAddresses.syncManager),
|
|
1621
1615
|
encodePacked(['uint8', 'bytes32'], [/* UpdateContractType.Valuation */ 1, addressToBytes32(valuation)]),
|
|
1622
1616
|
0n,
|
|
1617
|
+
ctx.signingAddress,
|
|
1623
1618
|
],
|
|
1624
1619
|
}));
|
|
1625
|
-
messages.push(MessageType.
|
|
1620
|
+
messages.push(MessageType.TrustedContractUpdate);
|
|
1626
1621
|
}
|
|
1627
1622
|
const title = hook && valuation ? 'Update hook and valuation' : hook ? 'Update hook' : 'Update valuation';
|
|
1628
1623
|
yield* wrapTransaction(title, ctx, {
|
|
1629
1624
|
contract: hub,
|
|
1630
1625
|
data: calls,
|
|
1631
|
-
messages: { [
|
|
1626
|
+
messages: { [centrifugeId]: messages },
|
|
1632
1627
|
});
|
|
1633
|
-
}, this.pool.
|
|
1628
|
+
}, this.pool.centrifugeId);
|
|
1634
1629
|
}
|
|
1635
1630
|
/** @internal */
|
|
1636
1631
|
_balances() {
|
|
@@ -1643,6 +1638,7 @@ export class ShareClass extends Entity {
|
|
|
1643
1638
|
assetAmount
|
|
1644
1639
|
assetPrice
|
|
1645
1640
|
assetId
|
|
1641
|
+
centrifugeId
|
|
1646
1642
|
asset {
|
|
1647
1643
|
decimals
|
|
1648
1644
|
assetTokenId
|
|
@@ -1651,6 +1647,7 @@ export class ShareClass extends Entity {
|
|
|
1651
1647
|
symbol
|
|
1652
1648
|
blockchain {
|
|
1653
1649
|
id
|
|
1650
|
+
centrifugeId
|
|
1654
1651
|
}
|
|
1655
1652
|
}
|
|
1656
1653
|
}
|
|
@@ -1662,14 +1659,15 @@ export class ShareClass extends Entity {
|
|
|
1662
1659
|
/** @internal */
|
|
1663
1660
|
_holding(assetId) {
|
|
1664
1661
|
return this._query(['holding', assetId.toString()], () => combineLatest([
|
|
1665
|
-
this._root._protocolAddresses(this.pool.
|
|
1662
|
+
this._root._protocolAddresses(this.pool.centrifugeId),
|
|
1666
1663
|
this.pool.currency(),
|
|
1667
|
-
this._root._assetDecimals(assetId, this.pool.
|
|
1664
|
+
this._root._assetDecimals(assetId, this.pool.centrifugeId),
|
|
1668
1665
|
]).pipe(switchMap(([{ holdings: holdingsAddr }, poolCurrency, assetDecimals]) => defer(async () => {
|
|
1666
|
+
const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
|
|
1669
1667
|
const holdings = getContract({
|
|
1670
1668
|
address: holdingsAddr,
|
|
1671
1669
|
abi: ABI.Holdings,
|
|
1672
|
-
client
|
|
1670
|
+
client,
|
|
1673
1671
|
});
|
|
1674
1672
|
const [valuation, amount, value, isLiability, ...accounts] = await Promise.all([
|
|
1675
1673
|
holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
@@ -1709,12 +1707,15 @@ export class ShareClass extends Entity {
|
|
|
1709
1707
|
return event.args.scId === this.id && event.args.assetId === assetId.raw;
|
|
1710
1708
|
});
|
|
1711
1709
|
},
|
|
1712
|
-
}, this.pool.
|
|
1710
|
+
}, this.pool.centrifugeId)))));
|
|
1713
1711
|
}
|
|
1714
1712
|
/** @internal */
|
|
1715
|
-
_balance(
|
|
1716
|
-
return this._query(['balance', asset.id.toString()], () => combineLatest([
|
|
1717
|
-
|
|
1713
|
+
_balance(centrifugeId, asset) {
|
|
1714
|
+
return this._query(['balance', asset.id.toString()], () => combineLatest([
|
|
1715
|
+
this._root._protocolAddresses(centrifugeId),
|
|
1716
|
+
this.pool.currency(),
|
|
1717
|
+
this._root.getClient(centrifugeId),
|
|
1718
|
+
]).pipe(switchMap(([addresses, poolCurrency, client]) => defer(async () => {
|
|
1718
1719
|
const [amountBn, priceBn] = await Promise.all([
|
|
1719
1720
|
client.readContract({
|
|
1720
1721
|
address: addresses.balanceSheet,
|
|
@@ -1747,55 +1748,106 @@ export class ShareClass extends Entity {
|
|
|
1747
1748
|
// NoteDeposit, Deposit, Withdraw events
|
|
1748
1749
|
event.args.asset?.toLowerCase() === asset.address?.toLowerCase()));
|
|
1749
1750
|
},
|
|
1750
|
-
},
|
|
1751
|
+
}, centrifugeId)))));
|
|
1751
1752
|
}
|
|
1752
1753
|
/** @internal */
|
|
1753
1754
|
_investorOrders() {
|
|
1754
1755
|
return this._root._queryIndexer(`query ($scId: String!) {
|
|
1755
|
-
|
|
1756
|
+
investOrders(where: {tokenId: $scId}) {
|
|
1756
1757
|
items {
|
|
1757
|
-
|
|
1758
|
+
account
|
|
1758
1759
|
assetId
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1760
|
+
tokenId
|
|
1761
|
+
approvedAssetsAmount
|
|
1762
|
+
approvedAt
|
|
1763
|
+
claimedSharesAmount
|
|
1764
|
+
claimedAt
|
|
1765
|
+
issuedSharesAmount
|
|
1766
|
+
issuedAt
|
|
1767
|
+
pendingAssetsAmount
|
|
1768
|
+
postedAt
|
|
1769
|
+
queuedAssetsAmount
|
|
1762
1770
|
}
|
|
1763
1771
|
}
|
|
1764
|
-
|
|
1772
|
+
redeemOrders(where: {tokenId: $scId}) {
|
|
1765
1773
|
items {
|
|
1774
|
+
account
|
|
1766
1775
|
assetId
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1776
|
+
tokenId
|
|
1777
|
+
approvedSharesAmount
|
|
1778
|
+
approvedAt
|
|
1779
|
+
claimedAssetsAmount
|
|
1780
|
+
claimedAt
|
|
1781
|
+
pendingSharesAmount
|
|
1782
|
+
postedAt
|
|
1783
|
+
revokedSharesAmount
|
|
1784
|
+
revokedAssetsAmount
|
|
1785
|
+
revokedPoolAmount
|
|
1786
|
+
revokedAt
|
|
1787
|
+
queuedSharesAmount
|
|
1771
1788
|
}
|
|
1772
1789
|
}
|
|
1773
1790
|
}`, { scId: this.id.raw }, (data) => ({
|
|
1774
|
-
|
|
1791
|
+
investOrders: data.investOrders.items.map((item) => ({
|
|
1775
1792
|
...item,
|
|
1776
1793
|
assetId: new AssetId(item.assetId),
|
|
1794
|
+
account: item.account.toLowerCase(),
|
|
1795
|
+
investor: item.account.toLowerCase(),
|
|
1796
|
+
tokenId: item.tokenId.toLowerCase(),
|
|
1797
|
+
})),
|
|
1798
|
+
outstandingInvests: data.investOrders.items.map((item) => ({
|
|
1799
|
+
assetId: new AssetId(item.assetId),
|
|
1800
|
+
account: item.account.toLowerCase(),
|
|
1801
|
+
investor: item.account.toLowerCase(),
|
|
1802
|
+
tokenId: item.tokenId.toLowerCase(),
|
|
1803
|
+
pendingAmount: item.pendingAssetsAmount,
|
|
1804
|
+
queuedAmount: item.queuedAssetsAmount,
|
|
1777
1805
|
})),
|
|
1778
|
-
|
|
1806
|
+
redeemOrders: data.redeemOrders.items.map((item) => ({
|
|
1779
1807
|
...item,
|
|
1780
1808
|
assetId: new AssetId(item.assetId),
|
|
1809
|
+
account: item.account.toLowerCase(),
|
|
1810
|
+
investor: item.account.toLowerCase(),
|
|
1811
|
+
tokenId: item.tokenId.toLowerCase(),
|
|
1812
|
+
})),
|
|
1813
|
+
outstandingRedeems: data.redeemOrders.items.map((item) => ({
|
|
1814
|
+
assetId: new AssetId(item.assetId),
|
|
1815
|
+
account: item.account.toLowerCase(),
|
|
1816
|
+
investor: item.account.toLowerCase(),
|
|
1817
|
+
tokenId: item.tokenId.toLowerCase(),
|
|
1818
|
+
pendingAmount: item.pendingSharesAmount,
|
|
1819
|
+
queuedAmount: item.queuedSharesAmount,
|
|
1781
1820
|
})),
|
|
1782
1821
|
}));
|
|
1783
1822
|
}
|
|
1784
1823
|
/** @internal */
|
|
1785
1824
|
_investorOrder(assetId, investor) {
|
|
1786
|
-
return this._query(['investorOrder', assetId.toString(), investor.toLowerCase()], () =>
|
|
1825
|
+
return this._query(['investorOrder', assetId.toString(), investor.toLowerCase()], () => combineLatest([
|
|
1826
|
+
this._root._protocolAddresses(this.pool.centrifugeId),
|
|
1827
|
+
this._root.getClient(this.pool.centrifugeId),
|
|
1828
|
+
]).pipe(switchMap(([{ batchRequestManager }, client]) => defer(async () => {
|
|
1787
1829
|
const contract = getContract({
|
|
1788
|
-
address:
|
|
1789
|
-
abi: ABI.
|
|
1790
|
-
client
|
|
1830
|
+
address: batchRequestManager,
|
|
1831
|
+
abi: ABI.BatchRequestManager,
|
|
1832
|
+
client,
|
|
1791
1833
|
});
|
|
1792
1834
|
const [maxDepositClaims, maxRedeemClaims, [pendingDeposit], [pendingRedeem], [, queuedInvest], [, queuedRedeem],] = await Promise.all([
|
|
1793
|
-
contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
1794
|
-
contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
1795
|
-
contract.read.depositRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
|
|
1796
|
-
contract.read.redeemRequest([this.id.raw, assetId.raw, addressToBytes32(investor)]),
|
|
1797
|
-
contract.read.queuedDepositRequest([
|
|
1798
|
-
|
|
1835
|
+
contract.read.maxDepositClaims([this.pool.id.raw, this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
1836
|
+
contract.read.maxRedeemClaims([this.pool.id.raw, this.id.raw, addressToBytes32(investor), assetId.raw]),
|
|
1837
|
+
contract.read.depositRequest([this.pool.id.raw, this.id.raw, assetId.raw, addressToBytes32(investor)]),
|
|
1838
|
+
contract.read.redeemRequest([this.pool.id.raw, this.id.raw, assetId.raw, addressToBytes32(investor)]),
|
|
1839
|
+
contract.read.queuedDepositRequest([
|
|
1840
|
+
this.pool.id.raw,
|
|
1841
|
+
this.id.raw,
|
|
1842
|
+
assetId.raw,
|
|
1843
|
+
addressToBytes32(investor),
|
|
1844
|
+
]),
|
|
1845
|
+
contract.read.queuedRedeemRequest([
|
|
1846
|
+
this.pool.id.raw,
|
|
1847
|
+
this.id.raw,
|
|
1848
|
+
assetId.raw,
|
|
1849
|
+
addressToBytes32(investor),
|
|
1850
|
+
]),
|
|
1799
1851
|
]);
|
|
1800
1852
|
return {
|
|
1801
1853
|
assetId,
|
|
@@ -1808,7 +1860,7 @@ export class ShareClass extends Entity {
|
|
|
1808
1860
|
queuedRedeem,
|
|
1809
1861
|
};
|
|
1810
1862
|
}).pipe(repeatOnEvents(this._root, {
|
|
1811
|
-
address:
|
|
1863
|
+
address: batchRequestManager,
|
|
1812
1864
|
eventName: [
|
|
1813
1865
|
'UpdateDepositRequest',
|
|
1814
1866
|
'UpdateRedeemRequest',
|
|
@@ -1821,7 +1873,7 @@ export class ShareClass extends Entity {
|
|
|
1821
1873
|
return events.some((event) => event.args.scId === this.id.raw &&
|
|
1822
1874
|
(event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
|
|
1823
1875
|
},
|
|
1824
|
-
}, this.pool.
|
|
1876
|
+
}, this.pool.centrifugeId)))));
|
|
1825
1877
|
}
|
|
1826
1878
|
/** @internal */
|
|
1827
1879
|
_allVaults() {
|
|
@@ -1836,24 +1888,25 @@ export class ShareClass extends Entity {
|
|
|
1836
1888
|
assetAddress
|
|
1837
1889
|
status
|
|
1838
1890
|
blockchain {
|
|
1839
|
-
|
|
1891
|
+
centrifugeId
|
|
1840
1892
|
}
|
|
1841
1893
|
}
|
|
1842
1894
|
}
|
|
1843
1895
|
}`, { scId: this.id.raw }, (data) => data.vaults.items.map(({ blockchain, asset, ...rest }) => ({
|
|
1844
1896
|
...rest,
|
|
1845
|
-
|
|
1897
|
+
centrifugeId: Number(blockchain.centrifugeId),
|
|
1846
1898
|
assetId: new AssetId(asset.id),
|
|
1847
1899
|
})));
|
|
1848
1900
|
}
|
|
1849
1901
|
/** @internal */
|
|
1850
1902
|
_metadata() {
|
|
1851
|
-
return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.
|
|
1852
|
-
const
|
|
1903
|
+
return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
|
|
1904
|
+
const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
|
|
1905
|
+
const [name, symbol] = await client.readContract({
|
|
1853
1906
|
address: shareClassManager,
|
|
1854
1907
|
abi: ABI.ShareClassManager,
|
|
1855
1908
|
functionName: 'metadata',
|
|
1856
|
-
args: [this.id.raw],
|
|
1909
|
+
args: [this.pool.id.raw, this.id.raw],
|
|
1857
1910
|
});
|
|
1858
1911
|
return {
|
|
1859
1912
|
name,
|
|
@@ -1867,17 +1920,23 @@ export class ShareClass extends Entity {
|
|
|
1867
1920
|
return event.args.scId === this.id;
|
|
1868
1921
|
});
|
|
1869
1922
|
},
|
|
1870
|
-
}, this.pool.
|
|
1923
|
+
}, this.pool.centrifugeId)))));
|
|
1871
1924
|
}
|
|
1872
1925
|
/** @internal */
|
|
1873
1926
|
_metrics() {
|
|
1874
|
-
return this._query(['metrics'], () =>
|
|
1875
|
-
|
|
1927
|
+
return this._query(['metrics'], () => combineLatest([
|
|
1928
|
+
this._root._protocolAddresses(this.pool.centrifugeId),
|
|
1929
|
+
this._root.getClient(this.pool.centrifugeId),
|
|
1930
|
+
]).pipe(switchMap(([{ shareClassManager }, client]) => defer(async () => {
|
|
1931
|
+
const contract = getContract({
|
|
1876
1932
|
address: shareClassManager,
|
|
1877
1933
|
abi: ABI.ShareClassManager,
|
|
1878
|
-
|
|
1879
|
-
args: [this.id.raw],
|
|
1934
|
+
client,
|
|
1880
1935
|
});
|
|
1936
|
+
const [totalIssuance, [pricePerShare]] = await Promise.all([
|
|
1937
|
+
contract.read.totalIssuance([this.pool.id.raw, this.id.raw]),
|
|
1938
|
+
contract.read.pricePoolPerShare([this.pool.id.raw, this.id.raw]),
|
|
1939
|
+
]);
|
|
1881
1940
|
return {
|
|
1882
1941
|
totalIssuance: new Balance(totalIssuance, 18),
|
|
1883
1942
|
pricePerShare: new Price(pricePerShare),
|
|
@@ -1896,7 +1955,7 @@ export class ShareClass extends Entity {
|
|
|
1896
1955
|
return event.args.scId === this.id.raw;
|
|
1897
1956
|
});
|
|
1898
1957
|
},
|
|
1899
|
-
}, this.pool.
|
|
1958
|
+
}, this.pool.centrifugeId)))));
|
|
1900
1959
|
}
|
|
1901
1960
|
/** @internal */
|
|
1902
1961
|
_epochInvestOrders() {
|
|
@@ -1953,29 +2012,30 @@ export class ShareClass extends Entity {
|
|
|
1953
2012
|
/** @internal */
|
|
1954
2013
|
_epoch(assetId) {
|
|
1955
2014
|
return this._query(['epoch', assetId.toString()], () => combineLatest([
|
|
1956
|
-
this._root._protocolAddresses(this.pool.
|
|
2015
|
+
this._root._protocolAddresses(this.pool.centrifugeId),
|
|
1957
2016
|
this.pool.currency(),
|
|
1958
|
-
this._root._assetDecimals(assetId, this.pool.
|
|
2017
|
+
this._root._assetDecimals(assetId, this.pool.centrifugeId),
|
|
1959
2018
|
this._epochInvestOrders(),
|
|
1960
2019
|
this._epochRedeemOrders(),
|
|
1961
|
-
|
|
2020
|
+
this._root.getClient(this.pool.centrifugeId),
|
|
2021
|
+
]).pipe(switchMap(([{ batchRequestManager }, poolCurrency, assetDecimals, epochInvestOrders, epochRedeemOrders, client]) => defer(async () => {
|
|
1962
2022
|
const scm = getContract({
|
|
1963
|
-
address:
|
|
1964
|
-
abi: ABI.
|
|
1965
|
-
client
|
|
2023
|
+
address: batchRequestManager,
|
|
2024
|
+
abi: ABI.BatchRequestManager,
|
|
2025
|
+
client,
|
|
1966
2026
|
});
|
|
1967
2027
|
const [epoch, pendingDeposit, pendingRedeem] = await Promise.all([
|
|
1968
|
-
scm.read.epochId([this.id.raw, assetId.raw]),
|
|
1969
|
-
scm.read.pendingDeposit([this.id.raw, assetId.raw]),
|
|
1970
|
-
scm.read.pendingRedeem([this.id.raw, assetId.raw]),
|
|
2028
|
+
scm.read.epochId([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
2029
|
+
scm.read.pendingDeposit([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
2030
|
+
scm.read.pendingRedeem([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
1971
2031
|
]);
|
|
1972
2032
|
const depositEpoch = epoch[0] + 1;
|
|
1973
2033
|
const redeemEpoch = epoch[1] + 1;
|
|
1974
2034
|
const issueEpoch = epoch[2] + 1;
|
|
1975
2035
|
const revokeEpoch = epoch[3] + 1;
|
|
1976
2036
|
const [depositEpochAmounts, redeemEpochAmount] = await Promise.all([
|
|
1977
|
-
Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.id.raw, assetId.raw, issueEpoch + i]))),
|
|
1978
|
-
Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.id.raw, assetId.raw, revokeEpoch + i]))),
|
|
2037
|
+
Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.pool.id.raw, this.id.raw, assetId.raw, issueEpoch + i]))),
|
|
2038
|
+
Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.pool.id.raw, this.id.raw, assetId.raw, revokeEpoch + i]))),
|
|
1979
2039
|
]);
|
|
1980
2040
|
const approvedDeposit = depositEpochAmounts.reduce((acc, amount) => acc + amount[1], 0n);
|
|
1981
2041
|
const approvedRedeem = redeemEpochAmount.reduce((acc, amount) => acc + amount[1], 0n);
|
|
@@ -2000,7 +2060,7 @@ export class ShareClass extends Entity {
|
|
|
2000
2060
|
})),
|
|
2001
2061
|
};
|
|
2002
2062
|
}).pipe(repeatOnEvents(this._root, {
|
|
2003
|
-
address:
|
|
2063
|
+
address: batchRequestManager,
|
|
2004
2064
|
eventName: [
|
|
2005
2065
|
'ApproveDeposits',
|
|
2006
2066
|
'ApproveRedeems',
|
|
@@ -2016,30 +2076,35 @@ export class ShareClass extends Entity {
|
|
|
2016
2076
|
return event.args.scId === this.id.raw;
|
|
2017
2077
|
});
|
|
2018
2078
|
},
|
|
2019
|
-
}, this.pool.
|
|
2079
|
+
}, this.pool.centrifugeId)))));
|
|
2020
2080
|
}
|
|
2021
2081
|
/** @internal */
|
|
2022
|
-
_updateContract(
|
|
2082
|
+
_updateContract(centrifugeId, target, payload) {
|
|
2023
2083
|
const self = this;
|
|
2024
2084
|
return this._transact(async function* (ctx) {
|
|
2025
|
-
const
|
|
2026
|
-
self._root.id(chainId),
|
|
2027
|
-
self._root._protocolAddresses(self.pool.chainId),
|
|
2028
|
-
]);
|
|
2085
|
+
const { hub } = await self._root._protocolAddresses(self.pool.centrifugeId);
|
|
2029
2086
|
yield* wrapTransaction('Update contract', ctx, {
|
|
2030
2087
|
contract: hub,
|
|
2031
2088
|
data: encodeFunctionData({
|
|
2032
2089
|
abi: ABI.Hub,
|
|
2033
2090
|
functionName: 'updateContract',
|
|
2034
|
-
args: [
|
|
2091
|
+
args: [
|
|
2092
|
+
self.pool.id.raw,
|
|
2093
|
+
self.id.raw,
|
|
2094
|
+
centrifugeId,
|
|
2095
|
+
addressToBytes32(target),
|
|
2096
|
+
payload,
|
|
2097
|
+
0n,
|
|
2098
|
+
ctx.signingAddress,
|
|
2099
|
+
],
|
|
2035
2100
|
}),
|
|
2036
|
-
messages: { [
|
|
2101
|
+
messages: { [centrifugeId]: [MessageType.TrustedContractUpdate] },
|
|
2037
2102
|
});
|
|
2038
|
-
}, this.pool.
|
|
2103
|
+
}, this.pool.centrifugeId);
|
|
2039
2104
|
}
|
|
2040
2105
|
/** @internal */
|
|
2041
2106
|
_epochOutstandingInvests() {
|
|
2042
|
-
return this._query(['epochOutstandingInvests'], () =>
|
|
2107
|
+
return this._query(['epochOutstandingInvests'], () => this._root._queryIndexer(`query ($scId: String!) {
|
|
2043
2108
|
epochOutstandingInvests(where: { tokenId: $scId }, limit: 1000) {
|
|
2044
2109
|
items {
|
|
2045
2110
|
assetId
|
|
@@ -2048,17 +2113,16 @@ export class ShareClass extends Entity {
|
|
|
2048
2113
|
}
|
|
2049
2114
|
}
|
|
2050
2115
|
}`, { scId: this.id.raw }, (data) => {
|
|
2051
|
-
const chainsById = new Map(deployments.blockchains.items.map((c) => [c.centrifugeId, c.id]));
|
|
2052
2116
|
return data.epochOutstandingInvests.items.map((item) => ({
|
|
2053
2117
|
assetId: new AssetId(item.assetId),
|
|
2054
|
-
|
|
2118
|
+
centrifugeId: item.asset.centrifugeId,
|
|
2055
2119
|
amount: new Balance(item.pendingAssetsAmount || 0, item.asset.decimals),
|
|
2056
2120
|
}));
|
|
2057
|
-
}))
|
|
2121
|
+
}));
|
|
2058
2122
|
}
|
|
2059
2123
|
/** @internal */
|
|
2060
2124
|
_epochOutstandingRedeems() {
|
|
2061
|
-
return this._query(['epochOutstandingRedeems'], () =>
|
|
2125
|
+
return this._query(['epochOutstandingRedeems'], () => this._root._queryIndexer(`query ($scId: String!) {
|
|
2062
2126
|
epochOutstandingRedeems(where: { tokenId: $scId }, limit: 1000) {
|
|
2063
2127
|
items {
|
|
2064
2128
|
assetId
|
|
@@ -2067,22 +2131,21 @@ export class ShareClass extends Entity {
|
|
|
2067
2131
|
}
|
|
2068
2132
|
}
|
|
2069
2133
|
}`, { scId: this.id.raw }, (data) => {
|
|
2070
|
-
const chainsById = new Map(deployments.blockchains.items.map((c) => [c.centrifugeId, c.id]));
|
|
2071
2134
|
return data.epochOutstandingRedeems.items.map((item) => ({
|
|
2072
2135
|
assetId: new AssetId(item.assetId),
|
|
2073
|
-
|
|
2136
|
+
centrifugeId: item.asset.centrifugeId,
|
|
2074
2137
|
amount: new Balance(item.pendingSharesAmount || 0, 18),
|
|
2075
2138
|
}));
|
|
2076
|
-
}))
|
|
2139
|
+
}));
|
|
2077
2140
|
}
|
|
2078
2141
|
/** @internal */
|
|
2079
|
-
_share(
|
|
2080
|
-
return this._query(['share',
|
|
2142
|
+
_share(centrifugeId) {
|
|
2143
|
+
return this._query(['share', centrifugeId], () => this.pool.network(centrifugeId).pipe(switchMap((network) => network._share(this.id))));
|
|
2081
2144
|
}
|
|
2082
2145
|
/** @internal */
|
|
2083
|
-
_restrictionManager(
|
|
2084
|
-
return this._query(['restrictionManager',
|
|
2085
|
-
const address = await
|
|
2146
|
+
_restrictionManager(centrifugeId) {
|
|
2147
|
+
return this._query(['restrictionManager', centrifugeId], () => combineLatest([this._share(centrifugeId), this._root.getClient(centrifugeId)]).pipe(switchMap(([share, client]) => defer(async () => {
|
|
2148
|
+
const address = await client.readContract({
|
|
2086
2149
|
address: share,
|
|
2087
2150
|
abi: ABI.Currency,
|
|
2088
2151
|
functionName: 'hook',
|
|
@@ -2092,12 +2155,13 @@ export class ShareClass extends Entity {
|
|
|
2092
2155
|
}
|
|
2093
2156
|
/** @internal */
|
|
2094
2157
|
_getFreeAccountId() {
|
|
2095
|
-
return this._query(['getFreeAccountId'], () => this._root._protocolAddresses(this.pool.
|
|
2096
|
-
const id =
|
|
2158
|
+
return this._query(['getFreeAccountId'], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
|
|
2159
|
+
const id = randomUint(256);
|
|
2097
2160
|
if (triesLeft <= 0)
|
|
2098
2161
|
return EMPTY;
|
|
2099
2162
|
return defer(async () => {
|
|
2100
|
-
const
|
|
2163
|
+
const client = await firstValueFrom(this._root.getClient(this.pool.centrifugeId));
|
|
2164
|
+
const exists = await client.readContract({
|
|
2101
2165
|
address: accounting,
|
|
2102
2166
|
abi: ABI.Accounting,
|
|
2103
2167
|
functionName: 'exists',
|
|
@@ -2126,7 +2190,7 @@ export class ShareClass extends Entity {
|
|
|
2126
2190
|
centrifugeIds?.join(','),
|
|
2127
2191
|
orderBy,
|
|
2128
2192
|
orderDirection,
|
|
2129
|
-
], () => this._root._protocolAddresses(this.pool.
|
|
2193
|
+
], () => this._root._protocolAddresses(this.pool.centrifugeId).pipe(switchMap((protocolAddresses) => {
|
|
2130
2194
|
// Build where clause dynamically based on which filters are provided
|
|
2131
2195
|
const whereConditions = ['tokenId: $scId', 'accountAddress_not_in: $excludedAddresses'];
|
|
2132
2196
|
if (balance_gt !== undefined)
|
|
@@ -2315,5 +2379,21 @@ export class ShareClass extends Entity {
|
|
|
2315
2379
|
};
|
|
2316
2380
|
})));
|
|
2317
2381
|
}
|
|
2382
|
+
/** @internal */
|
|
2383
|
+
_getQuote(valuationAddress, assetId, baseAmount) {
|
|
2384
|
+
return this._query(['getQuote', valuationAddress, baseAmount.toString(), assetId.toString()], () => timer(0, 120_000).pipe(switchMap(() => this._root.getClient(this.pool.centrifugeId)), switchMap((client) => combineLatest([
|
|
2385
|
+
this.pool.currency(),
|
|
2386
|
+
defer(() => {
|
|
2387
|
+
return client.readContract({
|
|
2388
|
+
address: valuationAddress,
|
|
2389
|
+
abi: ABI.Valuation,
|
|
2390
|
+
functionName: 'getQuote',
|
|
2391
|
+
args: [this.pool.id.raw, this.id.raw, assetId.raw, baseAmount.toBigInt()],
|
|
2392
|
+
});
|
|
2393
|
+
}),
|
|
2394
|
+
])), map(([poolCurrency, quote]) => {
|
|
2395
|
+
return new Balance(quote, poolCurrency.decimals);
|
|
2396
|
+
})));
|
|
2397
|
+
}
|
|
2318
2398
|
}
|
|
2319
2399
|
//# sourceMappingURL=ShareClass.js.map
|