Skip to content

Commit 3963a18

Browse files
feat(cli): single asset vault support
Synced from glamsystems/glam 11ba91cd3a2ce9108e8deda6356f1e220e6bc7f9
1 parent 14b8ade commit 3963a18

File tree

3 files changed

+75
-16
lines changed

3 files changed

+75
-16
lines changed

src/utils.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,40 @@ export async function confirmOperation(message: string) {
193193
}
194194
}
195195

196+
/**
197+
{
198+
"state": {
199+
"accountType": "vault",
200+
"name": "Example vault",
201+
"baseAssetMint": "So11111111111111111111111111111111111111112",
202+
"enabled": true, // optional
203+
"assets": [ "So11111111111111111111111111111111111111112" ] // optional
204+
}
205+
}
206+
*/
196207
export function parseStateJson(json: any): InitStateParams {
197208
if (!json.state) {
198209
throw new Error("Invalid JSON file: must contain 'state' property");
199210
}
200211
const { state } = json;
201-
const requiredFields =
202-
state.accountType === "vault"
203-
? ["accountType", "name", "baseAssetMint"]
204-
: ["accountType"];
205-
requiredFields.forEach((field) => {
212+
["accountType", "name", "baseAssetMint"].forEach((field) => {
206213
if (state?.[field] === undefined) {
207-
throw new Error(`Missing required state field: ${field}`);
214+
throw new Error(
215+
`Account type ${state.accountType} missing required state field: ${field}`,
216+
);
208217
}
209218
});
210219

211-
const params = {
220+
return {
212221
accountType: StateAccountType.from(state.accountType),
213222
name: stringToChars(state.name),
223+
baseAssetMint: new PublicKey(state.baseAssetMint),
214224
enabled: state.enabled !== false,
215225
assets: state.assets?.map((asset: string) => new PublicKey(asset)) || null,
216-
baseAssetMint: new PublicKey(state.baseAssetMint),
217226
portfolioManagerName: state.portfolioManagerName
218227
? stringToChars(state.portfolioManagerName)
219228
: null,
220229
};
221-
222-
return params;
223230
}
224231

225232
export function parseMintJson(
@@ -239,19 +246,27 @@ export function parseMintJson(
239246

240247
const { mint } = json;
241248

242-
const requiredFields = ["name", "symbol", "uri", "baseAssetMint"];
249+
const requiredFields = ["name", "symbol", "uri"];
243250
requiredFields.forEach((field) => {
244251
if (mint?.[field] === undefined) {
245-
throw new Error(`Missing required mint field: ${field}`);
252+
throw new Error(
253+
`Account type ${accountType} missing required mint field: ${field}`,
254+
);
246255
}
247256
});
257+
const baseAssetMint = json?.state?.baseAssetMint;
258+
if (!baseAssetMint) {
259+
throw new Error(
260+
"Invalid JSON file: must contain 'baseAssetMint' property for tokenized vault",
261+
);
262+
}
248263

249-
const params = {
264+
return {
250265
accountType,
251266
name: stringToChars(mint.name),
252267
symbol: mint.symbol,
253268
uri: mint.uri,
254-
baseAssetMint: new PublicKey(mint.baseAssetMint),
269+
baseAssetMint: new PublicKey(baseAssetMint),
255270
maxCap: mint.maxCap ? new BN(mint.maxCap) : null,
256271
minSubscription: mint.minSubscription ? new BN(mint.minSubscription) : null,
257272
minRedemption: mint.minRedemption ? new BN(mint.minRedemption) : null,
@@ -305,7 +320,6 @@ export function parseMintJson(
305320
}
306321
: null,
307322
};
308-
return params;
309323
}
310324

311325
export function validatePublicKey(value: string) {

templates/single-asset.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"state": {
3+
"accountType": "singleAssetVault",
4+
"name": "Single Asset Vault",
5+
"baseAssetMint": "So11111111111111111111111111111111111111112"
6+
},
7+
"mint": {
8+
"name": "Single Asset Vault",
9+
"symbol": "SAV",
10+
"uri": "https://glam.systems",
11+
"lockupPeriod": 0,
12+
"feeStructure": {
13+
"vault": {
14+
"subscriptionFeeBps": 0,
15+
"redemptionFeeBps": 0
16+
},
17+
"manager": {
18+
"subscriptionFeeBps": 0,
19+
"redemptionFeeBps": 0
20+
},
21+
"management": {
22+
"feeBps": 0
23+
},
24+
"performance": {
25+
"feeBps": 0,
26+
"hurdleRateBps": 0,
27+
"hurdleType": "hard"
28+
}
29+
},
30+
"notifyAndSettle": {
31+
"model": "continuous",
32+
"permissionlessFulfillment": false,
33+
"subscribeNoticePeriodType": "soft",
34+
"subscribeNoticePeriod": 0,
35+
"subscribeSettlementPeriod": 0,
36+
"subscribeCancellationWindow": 0,
37+
"redeemNoticePeriodType": "soft",
38+
"redeemNoticePeriod": 0,
39+
"redeemSettlementPeriod": 604800,
40+
"redeemCancellationWindow": 0,
41+
"timeUnit": "second"
42+
}
43+
}
44+
}

templates/tokenized.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"state": {
33
"accountType": "tokenizedVault",
4+
"name": "GLAM SOL",
5+
"baseAssetMint": "So11111111111111111111111111111111111111112",
46
"enabled": true
57
},
68
"mint": {
79
"name": "GLAM SOL",
810
"symbol": "gmSOL",
911
"uri": "https://glam.systems",
10-
"baseAssetMint": "So11111111111111111111111111111111111111112",
1112
"maxCap": 1000000000000,
1213
"minSubscription": 100000000,
1314
"minRedemption": 100000000,

0 commit comments

Comments
 (0)