@centrifuge/sdk 0.0.0-alpha.17 → 0.0.0-alpha.19
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 +7 -0
- package/dist/Centrifuge.d.ts +31 -8
- package/dist/Centrifuge.d.ts.map +1 -1
- package/dist/Centrifuge.js +170 -50
- package/dist/Centrifuge.js.map +1 -1
- package/dist/Centrifuge.test.js +88 -10
- 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 +1 -0
- package/dist/abi/Accounting.abi.js.map +1 -1
- 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/index.d.ts +27 -0
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +2 -0
- package/dist/abi/index.js.map +1 -1
- package/dist/entities/Investor.d.ts +1 -1
- package/dist/entities/Investor.d.ts.map +1 -1
- package/dist/entities/Investor.js.map +1 -1
- package/dist/entities/Pool.d.ts +23 -3
- package/dist/entities/Pool.d.ts.map +1 -1
- package/dist/entities/Pool.js +73 -3
- package/dist/entities/Pool.js.map +1 -1
- package/dist/entities/Pool.test.js +5 -3
- package/dist/entities/Pool.test.js.map +1 -1
- package/dist/entities/PoolNetwork.d.ts +31 -7
- package/dist/entities/PoolNetwork.d.ts.map +1 -1
- package/dist/entities/PoolNetwork.js +176 -39
- package/dist/entities/PoolNetwork.js.map +1 -1
- package/dist/entities/PoolNetwork.test.js +32 -35
- package/dist/entities/PoolNetwork.test.js.map +1 -1
- package/dist/entities/ShareClass.d.ts +48 -8
- package/dist/entities/ShareClass.d.ts.map +1 -1
- package/dist/entities/ShareClass.js +188 -16
- package/dist/entities/ShareClass.js.map +1 -1
- package/dist/entities/ShareClass.test.js +42 -2
- package/dist/entities/ShareClass.test.js.map +1 -1
- package/dist/entities/Vault.d.ts +2 -2
- package/dist/entities/Vault.d.ts.map +1 -1
- package/dist/entities/Vault.js +1 -1
- package/dist/entities/Vault.js.map +1 -1
- package/dist/tests/setup.js +2 -2
- package/dist/tests/setup.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/poolInput.d.ts +4 -3
- package/dist/types/poolInput.d.ts.map +1 -1
- package/dist/types/poolMetadata.d.ts +8 -0
- package/dist/types/poolMetadata.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/types.d.ts +7 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js +6 -0
- package/dist/utils/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
+
import { ABI } from '../abi/index.js';
|
|
2
3
|
import { NULL_ADDRESS } from '../constants.js';
|
|
3
4
|
import { context } from '../tests/setup.js';
|
|
4
|
-
import { PoolId, ShareClassId } from '../utils/types.js';
|
|
5
|
+
import { AssetId, PoolId, ShareClassId } from '../utils/types.js';
|
|
5
6
|
import { Pool } from './Pool.js';
|
|
6
7
|
import { PoolNetwork } from './PoolNetwork.js';
|
|
7
8
|
const poolId = PoolId.from(1, 1);
|
|
8
9
|
const scId = ShareClassId.from(poolId, 1);
|
|
10
|
+
const chainId = 11155111;
|
|
11
|
+
const poolManager = '0x423420Ae467df6e90291fd0252c0A8a637C1e03f';
|
|
9
12
|
describe('PoolNetwork', () => {
|
|
10
13
|
let poolNetwork;
|
|
11
14
|
beforeEach(() => {
|
|
@@ -26,39 +29,33 @@ describe('PoolNetwork', () => {
|
|
|
26
29
|
expect(vaults).to.have.length(1);
|
|
27
30
|
expect(vaults[0].address.toLowerCase()).not.to.equal(NULL_ADDRESS);
|
|
28
31
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
it('gets the details', async () => {
|
|
33
|
+
const details = await poolNetwork.details();
|
|
34
|
+
expect(details.isActive).to.equal(true);
|
|
35
|
+
expect(details.activeShareClasses).to.have.length(1);
|
|
36
|
+
expect(details.activeShareClasses[0].shareToken).not.to.equal(NULL_ADDRESS);
|
|
37
|
+
expect(details.activeShareClasses[0].id.equals(scId)).to.equal(true);
|
|
38
|
+
expect(details.activeShareClasses[0].vaults).to.have.length(1);
|
|
39
|
+
});
|
|
40
|
+
it('deploys share classes and vaults', async () => {
|
|
41
|
+
const { hub, freezeOnlyHook } = await context.centrifuge._protocolAddresses(chainId);
|
|
42
|
+
context.tenderlyFork.impersonateAddress = poolManager;
|
|
43
|
+
context.centrifuge.setSigner(context.tenderlyFork.signer);
|
|
44
|
+
await context.centrifuge._transact('Add share class', async ({ walletClient }) => {
|
|
45
|
+
return walletClient.writeContract({
|
|
46
|
+
address: hub,
|
|
47
|
+
abi: ABI.Hub,
|
|
48
|
+
functionName: 'addShareClass',
|
|
49
|
+
args: [poolId.raw, 'Test Share Class', 'TSC', '0x1'.padEnd(66, '0')],
|
|
50
|
+
});
|
|
51
|
+
}, chainId);
|
|
52
|
+
const result = await poolNetwork.deploy([{ id: ShareClassId.from(poolId, 2), hook: freezeOnlyHook }], [{ shareClassId: ShareClassId.from(poolId, 2), assetId: AssetId.from(1, 1), kind: 'syncDeposit' }]);
|
|
53
|
+
expect(result.type).to.equal('TransactionConfirmed');
|
|
54
|
+
const details = await poolNetwork.details();
|
|
55
|
+
expect(details.activeShareClasses).to.have.length(2);
|
|
56
|
+
expect(details.activeShareClasses[1].id.equals(ShareClassId.from(poolId, 2))).to.equal(true);
|
|
57
|
+
expect(details.activeShareClasses[1].shareToken).not.to.equal(NULL_ADDRESS);
|
|
58
|
+
expect(details.activeShareClasses[1].vaults).to.have.length(1);
|
|
59
|
+
});
|
|
48
60
|
});
|
|
49
|
-
// // Set the storage to a value that will make the tranche undeployable
|
|
50
|
-
// const poolLoc = mapLocation(6n, BigInt(poolId))
|
|
51
|
-
// const createdAtLoc = poolLoc + BigInt(0)
|
|
52
|
-
// const poolManager = await poolNetwork._poolManager()
|
|
53
|
-
// const client = context.centrifuge.getClient()!
|
|
54
|
-
// const data = await client.setStorageAt({
|
|
55
|
-
// address: poolManager,
|
|
56
|
-
// slot: toHex(createdAtLoc),
|
|
57
|
-
// })
|
|
58
|
-
// function mapLocation(slot: bigint, key: bigint) {
|
|
59
|
-
// return hexToBigInt(keccak256(encodePacked(['uint256', 'uint256'], [key, slot])))
|
|
60
|
-
// }
|
|
61
|
-
// function arrLocation(slot: bigint, index: bigint, elementSize: bigint) {
|
|
62
|
-
// return hexToBigInt(keccak256(toHex(slot))) + index * elementSize
|
|
63
|
-
// }
|
|
64
61
|
//# sourceMappingURL=PoolNetwork.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoolNetwork.test.js","sourceRoot":"","sources":["../../src/entities/PoolNetwork.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"PoolNetwork.test.js","sourceRoot":"","sources":["../../src/entities/PoolNetwork.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAEpD,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;QAC3C,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACpD,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7F,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAE,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;QAC5E,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AccountType } from '../types/holdings.js';
|
|
2
|
+
import { HexString } from '../types/index.js';
|
|
1
3
|
import { Balance, Price } from '../utils/BigInt.js';
|
|
2
4
|
import { AssetId, ShareClassId } from '../utils/types.js';
|
|
3
5
|
import { Entity } from './Entity.js';
|
|
@@ -18,14 +20,37 @@ export declare class ShareClass extends Entity {
|
|
|
18
20
|
name: string;
|
|
19
21
|
symbol: string;
|
|
20
22
|
totalIssuance: Balance;
|
|
21
|
-
|
|
23
|
+
pricePerShare: Price;
|
|
24
|
+
nav: Balance;
|
|
22
25
|
}>;
|
|
26
|
+
navPerNetwork(): import("../index.js").Query<{
|
|
27
|
+
chainId: number;
|
|
28
|
+
totalIssuance: Balance;
|
|
29
|
+
pricePerShare: Price;
|
|
30
|
+
nav: Balance;
|
|
31
|
+
}[]>;
|
|
23
32
|
/**
|
|
24
33
|
* Query the vaults of the share class.
|
|
25
34
|
* @param chainId The chain ID to query the vaults on.
|
|
26
35
|
* @returns The vaults of the share class on the given chain.
|
|
27
36
|
*/
|
|
28
37
|
vaults(chainId: number): import("../index.js").Query<import("./Vault.js").Vault[]>;
|
|
38
|
+
holdings(): import("../index.js").Query<{
|
|
39
|
+
assetId: AssetId;
|
|
40
|
+
assetDecimals: number;
|
|
41
|
+
valuation: `0x${string}`;
|
|
42
|
+
amount: Balance;
|
|
43
|
+
value: Balance;
|
|
44
|
+
isLiability: boolean;
|
|
45
|
+
accounts: {
|
|
46
|
+
0: number | null;
|
|
47
|
+
1: number | null;
|
|
48
|
+
2: number | null;
|
|
49
|
+
3: number | null;
|
|
50
|
+
4: number | null;
|
|
51
|
+
5: number | null;
|
|
52
|
+
};
|
|
53
|
+
}[]>;
|
|
29
54
|
/**
|
|
30
55
|
* Query a holding of the share class.
|
|
31
56
|
* @param assetId The asset ID
|
|
@@ -37,6 +62,7 @@ export declare class ShareClass extends Entity {
|
|
|
37
62
|
valuation: `0x${string}`;
|
|
38
63
|
amount: Balance;
|
|
39
64
|
value: Balance;
|
|
65
|
+
isLiability: boolean;
|
|
40
66
|
accounts: {
|
|
41
67
|
0: number | null;
|
|
42
68
|
1: number | null;
|
|
@@ -46,7 +72,7 @@ export declare class ShareClass extends Entity {
|
|
|
46
72
|
5: number | null;
|
|
47
73
|
};
|
|
48
74
|
}>;
|
|
49
|
-
investorOrder(assetId: AssetId, investor:
|
|
75
|
+
investorOrder(assetId: AssetId, investor: HexString): import("../index.js").Query<{
|
|
50
76
|
maxDepositClaims: number;
|
|
51
77
|
maxRedeemClaims: number;
|
|
52
78
|
}>;
|
|
@@ -55,27 +81,41 @@ export declare class ShareClass extends Entity {
|
|
|
55
81
|
* @param address Address to check
|
|
56
82
|
* @param chainId Chain ID of the network on which to check the member
|
|
57
83
|
*/
|
|
58
|
-
member(address:
|
|
84
|
+
member(address: HexString, chainId: number): import("../index.js").Query<{
|
|
59
85
|
isMember: boolean;
|
|
60
86
|
validUntil: Date;
|
|
61
87
|
} | {
|
|
62
88
|
isMember: boolean;
|
|
63
89
|
validUntil: Date;
|
|
64
90
|
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Create a holding for a registered asset in the share class.
|
|
93
|
+
* @param assetId - Asset ID of the asset to create a holding for
|
|
94
|
+
* @param valuation - Valuation of the asset
|
|
95
|
+
* @param isLiability - Whether the holding is a liability or not
|
|
96
|
+
* @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
|
|
97
|
+
* Other accounts are expected to be provided or to exist in the pool metadata.
|
|
98
|
+
*/
|
|
99
|
+
createHolding<Liability extends boolean>(assetId: AssetId, valuation: HexString, isLiability: Liability, accounts: Liability extends true ? {
|
|
100
|
+
[key in AccountType.Expense | AccountType.Liability]?: number;
|
|
101
|
+
} : {
|
|
102
|
+
[key in AccountType.Asset | AccountType.Equity | AccountType.Loss | AccountType.Gain]?: number;
|
|
103
|
+
}): import("../index.js").Transaction;
|
|
104
|
+
updateSharePrice(pricePerShare: Price): import("../index.js").Transaction;
|
|
65
105
|
setMaxAssetPriceAge(assetId: AssetId, maxPriceAge: number): import("../index.js").Transaction;
|
|
66
106
|
setMaxSharePriceAge(chainId: number, maxPriceAge: number): import("../index.js").Transaction;
|
|
67
107
|
notifyAssetPrice(assetId: AssetId): import("../index.js").Transaction;
|
|
68
108
|
notifySharePrice(chainId: number): import("../index.js").Transaction;
|
|
69
|
-
approveDeposits(assetId: AssetId, assetAmount: Balance,
|
|
70
|
-
approveRedeems(assetId: AssetId, shareAmount: Balance,
|
|
71
|
-
claimDeposit(assetId: AssetId, investor:
|
|
72
|
-
claimRedeem(assetId: AssetId, investor:
|
|
109
|
+
approveDeposits(assetId: AssetId, assetAmount: Balance, pricePerShare: Price): import("../index.js").Transaction;
|
|
110
|
+
approveRedeems(assetId: AssetId, shareAmount: Balance, pricePerShare: Price): import("../index.js").Transaction;
|
|
111
|
+
claimDeposit(assetId: AssetId, investor: HexString): import("../index.js").Transaction;
|
|
112
|
+
claimRedeem(assetId: AssetId, investor: HexString): import("../index.js").Transaction;
|
|
73
113
|
/**
|
|
74
114
|
* Update a member of the share class.
|
|
75
115
|
* @param address Address of the investor
|
|
76
116
|
* @param validUntil Time in seconds from Unix epoch until the investor is valid
|
|
77
117
|
* @param chainId Chain ID of the network on which to update the member
|
|
78
118
|
*/
|
|
79
|
-
updateMember(address:
|
|
119
|
+
updateMember(address: HexString, validUntil: number, chainId: number): import("../index.js").Transaction;
|
|
80
120
|
}
|
|
81
121
|
//# sourceMappingURL=ShareClass.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShareClass.d.ts","sourceRoot":"","sources":["../../src/entities/ShareClass.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ShareClass.d.ts","sourceRoot":"","sources":["../../src/entities/ShareClass.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAInD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGrC;;;GAGG;AACH,qBAAa,UAAW,SAAQ,MAAM;IAM3B,IAAI,EAAE,IAAI;IALnB,EAAE,EAAE,YAAY,CAAA;IAahB;;;OAGG;IACH,OAAO;;;;;;;;IAiBP,aAAa;;;;;;IAgCb;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM;IAItB,QAAQ;;;;;;;;;;;;;;;;I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,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAgPrE"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { catchError, combineLatest, defer, map, of, switchMap } from 'rxjs';
|
|
1
|
+
import { catchError, combineLatest, defer, EMPTY, expand, filter, map, of, switchMap } from 'rxjs';
|
|
2
2
|
import { encodeFunctionData, encodePacked, getContract, parseAbi } from 'viem';
|
|
3
3
|
import { ABI } from '../abi/index.js';
|
|
4
4
|
import { AccountType } from '../types/holdings.js';
|
|
5
|
-
import { Balance } from '../utils/BigInt.js';
|
|
6
|
-
import { addressToBytes32 } from '../utils/index.js';
|
|
5
|
+
import { Balance, Price } from '../utils/BigInt.js';
|
|
6
|
+
import { addressToBytes32, randomUint } from '../utils/index.js';
|
|
7
7
|
import { repeatOnEvents } from '../utils/rx.js';
|
|
8
8
|
import { doTransaction } from '../utils/transaction.js';
|
|
9
|
-
import { ShareClassId } from '../utils/types.js';
|
|
9
|
+
import { AssetId, ShareClassId } from '../utils/types.js';
|
|
10
10
|
import { Entity } from './Entity.js';
|
|
11
11
|
import { PoolNetwork } from './PoolNetwork.js';
|
|
12
12
|
/**
|
|
@@ -18,9 +18,10 @@ export class ShareClass extends Entity {
|
|
|
18
18
|
id;
|
|
19
19
|
/** @internal */
|
|
20
20
|
constructor(_root, pool, id) {
|
|
21
|
-
|
|
21
|
+
const _id = id instanceof ShareClassId ? id : new ShareClassId(id);
|
|
22
|
+
super(_root, ['shareclass', _id.toString()]);
|
|
22
23
|
this.pool = pool;
|
|
23
|
-
this.id =
|
|
24
|
+
this.id = _id;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Query the details of the share class.
|
|
@@ -33,10 +34,29 @@ export class ShareClass extends Entity {
|
|
|
33
34
|
name: metadata.name,
|
|
34
35
|
symbol: metadata.symbol,
|
|
35
36
|
totalIssuance: metrics.totalIssuance,
|
|
36
|
-
|
|
37
|
+
pricePerShare: metrics.pricePerShare,
|
|
38
|
+
nav: metrics.totalIssuance.mul(metrics.pricePerShare),
|
|
37
39
|
};
|
|
38
40
|
})));
|
|
39
41
|
}
|
|
42
|
+
navPerNetwork() {
|
|
43
|
+
return this._root._queryIndexer(`query ($scId: String!) {
|
|
44
|
+
tokenInstances(where: { tokenId: $scId }) {
|
|
45
|
+
items {
|
|
46
|
+
totalIssuance
|
|
47
|
+
tokenPrice
|
|
48
|
+
blockchain {
|
|
49
|
+
id
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
|
|
54
|
+
chainId: item.blockchain.id,
|
|
55
|
+
totalIssuance: new Balance(item.totalIssuance, 18), // TODO: Replace with pool currency decimals
|
|
56
|
+
pricePerShare: new Price(item.tokenPrice),
|
|
57
|
+
nav: new Balance(item.totalIssuance, 18).mul(new Price(item.tokenPrice)),
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
40
60
|
/**
|
|
41
61
|
* Query the vaults of the share class.
|
|
42
62
|
* @param chainId The chain ID to query the vaults on.
|
|
@@ -45,6 +65,22 @@ export class ShareClass extends Entity {
|
|
|
45
65
|
vaults(chainId) {
|
|
46
66
|
return this._query(null, () => new PoolNetwork(this._root, this.pool, chainId).vaults(this.id));
|
|
47
67
|
}
|
|
68
|
+
holdings() {
|
|
69
|
+
return this._query(null, () => this._root
|
|
70
|
+
._queryIndexer(`query ($scId: String!) {
|
|
71
|
+
holdings(where: { tokenId: $scId }) {
|
|
72
|
+
items {
|
|
73
|
+
assetRegistrationId
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}`, {
|
|
77
|
+
scId: this.id.raw,
|
|
78
|
+
})
|
|
79
|
+
.pipe(switchMap((res) => combineLatest(res.holdings.items.map((holding) => {
|
|
80
|
+
const assetId = new AssetId(holding.assetRegistrationId);
|
|
81
|
+
return this.holding(assetId);
|
|
82
|
+
})))));
|
|
83
|
+
}
|
|
48
84
|
/**
|
|
49
85
|
* Query a holding of the share class.
|
|
50
86
|
* @param assetId The asset ID
|
|
@@ -57,7 +93,7 @@ export class ShareClass extends Entity {
|
|
|
57
93
|
abi: ABI.Holdings,
|
|
58
94
|
client: this._root.getClient(this.pool.chainId),
|
|
59
95
|
});
|
|
60
|
-
const [valuation, amount, value, assetDecimals, ...accounts] = await Promise.all([
|
|
96
|
+
const [valuation, amount, value, assetDecimals, isLiability, ...accounts] = await Promise.all([
|
|
61
97
|
holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
62
98
|
holdings.read.amount([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
63
99
|
holdings.read.value([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
@@ -68,7 +104,7 @@ export class ShareClass extends Entity {
|
|
|
68
104
|
functionName: 'decimals',
|
|
69
105
|
args: [assetId.raw],
|
|
70
106
|
}),
|
|
71
|
-
|
|
107
|
+
holdings.read.isLiability([this.pool.id.raw, this.id.raw, assetId.raw]),
|
|
72
108
|
...[
|
|
73
109
|
AccountType.Asset,
|
|
74
110
|
AccountType.Equity,
|
|
@@ -84,7 +120,7 @@ export class ShareClass extends Entity {
|
|
|
84
120
|
valuation,
|
|
85
121
|
amount: new Balance(amount, assetDecimals),
|
|
86
122
|
value: new Balance(value, 18), // TODO: Replace with pool currency decimals
|
|
87
|
-
|
|
123
|
+
isLiability,
|
|
88
124
|
accounts: {
|
|
89
125
|
[AccountType.Asset]: accounts[0] || null,
|
|
90
126
|
[AccountType.Equity]: accounts[1] || null,
|
|
@@ -168,6 +204,125 @@ export class ShareClass extends Entity {
|
|
|
168
204
|
});
|
|
169
205
|
})))));
|
|
170
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Create a holding for a registered asset in the share class.
|
|
209
|
+
* @param assetId - Asset ID of the asset to create a holding for
|
|
210
|
+
* @param valuation - Valuation of the asset
|
|
211
|
+
* @param isLiability - Whether the holding is a liability or not
|
|
212
|
+
* @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
|
|
213
|
+
* Other accounts are expected to be provided or to exist in the pool metadata.
|
|
214
|
+
*/
|
|
215
|
+
createHolding(assetId, valuation, isLiability, accounts) {
|
|
216
|
+
const self = this;
|
|
217
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
218
|
+
const [{ hub }, metadata] = await Promise.all([
|
|
219
|
+
self._root._protocolAddresses(self.pool.chainId),
|
|
220
|
+
self.pool.metadata(),
|
|
221
|
+
]);
|
|
222
|
+
let tx;
|
|
223
|
+
if (isLiability) {
|
|
224
|
+
const expenseAccount = accounts[AccountType.Expense] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.expense;
|
|
225
|
+
const liabilityAccount = accounts[AccountType.Liability] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.liability;
|
|
226
|
+
if (liabilityAccount === undefined) {
|
|
227
|
+
throw new Error('Missing required accounts for liability creation');
|
|
228
|
+
}
|
|
229
|
+
if (expenseAccount) {
|
|
230
|
+
tx = walletClient.writeContract({
|
|
231
|
+
address: hub,
|
|
232
|
+
abi: ABI.Hub,
|
|
233
|
+
functionName: 'initializeLiability',
|
|
234
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, expenseAccount, liabilityAccount],
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const newExpenseAccount = await self._getFreeAccountId();
|
|
239
|
+
const createAccountData = encodeFunctionData({
|
|
240
|
+
abi: ABI.Hub,
|
|
241
|
+
functionName: 'createAccount',
|
|
242
|
+
args: [self.pool.id.raw, newExpenseAccount, true],
|
|
243
|
+
});
|
|
244
|
+
const initHoldingData = encodeFunctionData({
|
|
245
|
+
abi: ABI.Hub,
|
|
246
|
+
functionName: 'initializeLiability',
|
|
247
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, newExpenseAccount, liabilityAccount],
|
|
248
|
+
});
|
|
249
|
+
tx = walletClient.writeContract({
|
|
250
|
+
address: hub,
|
|
251
|
+
abi: ABI.Hub,
|
|
252
|
+
functionName: 'multicall',
|
|
253
|
+
args: [[createAccountData, initHoldingData]],
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const assetAccount = accounts[AccountType.Asset] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.asset;
|
|
259
|
+
const equityAccount = accounts[AccountType.Equity] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.equity;
|
|
260
|
+
const gainAccount = accounts[AccountType.Gain] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.gain;
|
|
261
|
+
const lossAccount = accounts[AccountType.Loss] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.loss;
|
|
262
|
+
if (equityAccount === undefined || gainAccount === undefined || lossAccount === undefined) {
|
|
263
|
+
throw new Error('Missing required accounts for holding creation');
|
|
264
|
+
}
|
|
265
|
+
if (assetAccount) {
|
|
266
|
+
tx = walletClient.writeContract({
|
|
267
|
+
address: hub,
|
|
268
|
+
abi: ABI.Hub,
|
|
269
|
+
functionName: 'initializeHolding',
|
|
270
|
+
args: [
|
|
271
|
+
self.pool.id.raw,
|
|
272
|
+
self.id.raw,
|
|
273
|
+
assetId.raw,
|
|
274
|
+
valuation,
|
|
275
|
+
assetAccount,
|
|
276
|
+
equityAccount,
|
|
277
|
+
gainAccount,
|
|
278
|
+
lossAccount,
|
|
279
|
+
],
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
const newAssetAccount = await self._getFreeAccountId();
|
|
284
|
+
const createAccountData = encodeFunctionData({
|
|
285
|
+
abi: ABI.Hub,
|
|
286
|
+
functionName: 'createAccount',
|
|
287
|
+
args: [self.pool.id.raw, newAssetAccount, false],
|
|
288
|
+
});
|
|
289
|
+
const initHoldingData = encodeFunctionData({
|
|
290
|
+
abi: ABI.Hub,
|
|
291
|
+
functionName: 'initializeHolding',
|
|
292
|
+
args: [
|
|
293
|
+
self.pool.id.raw,
|
|
294
|
+
self.id.raw,
|
|
295
|
+
assetId.raw,
|
|
296
|
+
valuation,
|
|
297
|
+
newAssetAccount,
|
|
298
|
+
equityAccount,
|
|
299
|
+
gainAccount,
|
|
300
|
+
lossAccount,
|
|
301
|
+
],
|
|
302
|
+
});
|
|
303
|
+
tx = walletClient.writeContract({
|
|
304
|
+
address: hub,
|
|
305
|
+
abi: ABI.Hub,
|
|
306
|
+
functionName: 'multicall',
|
|
307
|
+
args: [[createAccountData, initHoldingData]],
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
yield* doTransaction('Create holding', publicClient, () => tx);
|
|
312
|
+
}, this.pool.chainId);
|
|
313
|
+
}
|
|
314
|
+
updateSharePrice(pricePerShare) {
|
|
315
|
+
const self = this;
|
|
316
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
317
|
+
const { hub } = await self._root._protocolAddresses(self.pool.chainId);
|
|
318
|
+
yield* doTransaction('Update price', publicClient, () => walletClient.writeContract({
|
|
319
|
+
address: hub,
|
|
320
|
+
abi: ABI.Hub,
|
|
321
|
+
functionName: 'updateSharePrice',
|
|
322
|
+
args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
|
|
323
|
+
}));
|
|
324
|
+
}, this.pool.chainId);
|
|
325
|
+
}
|
|
171
326
|
setMaxAssetPriceAge(assetId, maxPriceAge) {
|
|
172
327
|
const self = this;
|
|
173
328
|
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
@@ -222,7 +377,7 @@ export class ShareClass extends Entity {
|
|
|
222
377
|
}));
|
|
223
378
|
}, this.pool.chainId);
|
|
224
379
|
}
|
|
225
|
-
approveDeposits(assetId, assetAmount,
|
|
380
|
+
approveDeposits(assetId, assetAmount, pricePerShare) {
|
|
226
381
|
const self = this;
|
|
227
382
|
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
228
383
|
const [{ hub }, epoch, estimate] = await Promise.all([
|
|
@@ -250,7 +405,7 @@ export class ShareClass extends Entity {
|
|
|
250
405
|
const issueData = encodeFunctionData({
|
|
251
406
|
abi: ABI.Hub,
|
|
252
407
|
functionName: 'issueShares',
|
|
253
|
-
args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.issueEpoch,
|
|
408
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.issueEpoch, pricePerShare.toBigInt()],
|
|
254
409
|
});
|
|
255
410
|
yield* doTransaction('Approve deposits', publicClient, () => walletClient.writeContract({
|
|
256
411
|
address: hub,
|
|
@@ -268,7 +423,7 @@ export class ShareClass extends Entity {
|
|
|
268
423
|
}));
|
|
269
424
|
}, this.pool.chainId);
|
|
270
425
|
}
|
|
271
|
-
approveRedeems(assetId, shareAmount,
|
|
426
|
+
approveRedeems(assetId, shareAmount, pricePerShare) {
|
|
272
427
|
const self = this;
|
|
273
428
|
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
274
429
|
const [{ hub }, epoch, estimate] = await Promise.all([
|
|
@@ -291,7 +446,7 @@ export class ShareClass extends Entity {
|
|
|
291
446
|
const issueData = encodeFunctionData({
|
|
292
447
|
abi: ABI.Hub,
|
|
293
448
|
functionName: 'revokeShares',
|
|
294
|
-
args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.revokeEpoch,
|
|
449
|
+
args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.revokeEpoch, pricePerShare.toBigInt()],
|
|
295
450
|
});
|
|
296
451
|
yield* doTransaction('Approve redeems', publicClient, () => walletClient.writeContract({
|
|
297
452
|
address: hub,
|
|
@@ -393,7 +548,7 @@ export class ShareClass extends Entity {
|
|
|
393
548
|
/** @internal */
|
|
394
549
|
_metrics() {
|
|
395
550
|
return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
|
|
396
|
-
const [totalIssuance,
|
|
551
|
+
const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
|
|
397
552
|
address: shareClassManager,
|
|
398
553
|
abi: ABI.ShareClassManager,
|
|
399
554
|
functionName: 'metrics',
|
|
@@ -401,7 +556,7 @@ export class ShareClass extends Entity {
|
|
|
401
556
|
});
|
|
402
557
|
return {
|
|
403
558
|
totalIssuance: new Balance(totalIssuance, 18),
|
|
404
|
-
|
|
559
|
+
pricePerShare: new Price(pricePerShare),
|
|
405
560
|
};
|
|
406
561
|
}).pipe(repeatOnEvents(this._root, {
|
|
407
562
|
address: shareClassManager,
|
|
@@ -503,5 +658,22 @@ export class ShareClass extends Entity {
|
|
|
503
658
|
return address.toLowerCase();
|
|
504
659
|
}))));
|
|
505
660
|
}
|
|
661
|
+
/** @internal */
|
|
662
|
+
_getFreeAccountId() {
|
|
663
|
+
return this._query(null, () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
|
|
664
|
+
const id = Number(randomUint(32));
|
|
665
|
+
if (triesLeft <= 0)
|
|
666
|
+
return EMPTY;
|
|
667
|
+
return defer(async () => {
|
|
668
|
+
const exists = await this._root.getClient(this.pool.chainId).readContract({
|
|
669
|
+
address: accounting,
|
|
670
|
+
abi: ABI.Accounting,
|
|
671
|
+
functionName: 'exists',
|
|
672
|
+
args: [this.pool.id.raw, id],
|
|
673
|
+
});
|
|
674
|
+
return { accounting, id: exists ? null : id, triesLeft: triesLeft - 1 };
|
|
675
|
+
});
|
|
676
|
+
}), filter(({ id }) => !!id), map(({ id }) => id)));
|
|
677
|
+
}
|
|
506
678
|
}
|
|
507
679
|
//# sourceMappingURL=ShareClass.js.map
|