@@ -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+ */
196207export 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
225232export 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
311325export function validatePublicKey ( value : string ) {
0 commit comments