@agoric/portfolio-api 0.1.1-dev-2637aca.0.2637aca → 0.1.1-dev-eb52bc3.0.eb52bc3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/portfolio-api",
3
- "version": "0.1.1-dev-2637aca.0.2637aca",
3
+ "version": "0.1.1-dev-eb52bc3.0.eb52bc3",
4
4
  "description": "API for Portfolio management",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,8 +47,8 @@
47
47
  "generate:ymax-machine": "npx tsx scripts/gen-ymax-machine.mts"
48
48
  },
49
49
  "dependencies": {
50
- "@agoric/internal": "0.3.3-dev-2637aca.0.2637aca",
51
- "@agoric/orchestration": "0.1.1-dev-2637aca.0.2637aca",
50
+ "@agoric/internal": "0.3.3-dev-eb52bc3.0.eb52bc3",
51
+ "@agoric/orchestration": "0.1.1-dev-eb52bc3.0.eb52bc3",
52
52
  "@endo/common": "^1.4.0",
53
53
  "@endo/errors": "^1.3.1",
54
54
  "@endo/patterns": "^1.9.1"
@@ -74,5 +74,5 @@
74
74
  "engines": {
75
75
  "node": "^22.11 || ^24.14"
76
76
  },
77
- "gitHead": "2637aca64dcb9aac114b6fe72410568ed1cd961b"
77
+ "gitHead": "eb52bc371f1d95f517989c49cf30633ba50d9d41"
78
78
  }
@@ -17,6 +17,10 @@
17
17
  * The generic machinery lives in `@agoric/orchestration`; this module defines
18
18
  * the {@link YmaxObservationMessageSchema} and converts between its messages
19
19
  * and the application-level {@link PlanObservations}.
20
+ *
21
+ * This module has no runtime dependency on Endo, so that it can be used
22
+ * outside of a locked-down (SES) environment, e.g. by the attestor. In
23
+ * particular, the values it returns are not hardened.
20
24
  */
21
25
  import type { TypedDataToStructType } from '@agoric/orchestration/src/utils/abitype.js';
22
26
  import { type EIP712MessageKit, type FullDomain, type OperationType, type StandaloneOperationData } from '@agoric/orchestration/src/utils/eip712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BAA4B,CACjC,CAAC;AAErD,MAAM,MAAM,yBAAyB,GACnC,UAAU,CAAC,4BAA4B,CAAC,CAAC;AAE3C,kEAAkE;AAClE,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,4BAA4B,EAC5B,uBAAuB,CACxB,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,gCAAgC,GAAG,qBAAqB,CAClE,OAAO,yBAAyB,GAAG,OAAO,mBAAmB,EAC7D,uBAAuB,EACvB,OAAO,CACR,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,mCAAmC,GAAG,uBAAuB,CACvE,4BAA4B,EAC5B,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACrC,aAAa,CAAC,mCAAmC,CAAC,CAAC;AAErD,0EAA0E;AAC1E,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,YAAY,EAAE,gBAAgB,CAAC;CAChC,CAAC;AASF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GAAI,4GAI3C,4BAA4B,KAAG,gCAShC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,GAAI,kDAK7C,2BAA2B,KAAG,4BA+BhC,CAAC"}
@@ -17,6 +17,10 @@
17
17
  * The generic machinery lives in `@agoric/orchestration`; this module defines
18
18
  * the {@link YmaxObservationMessageSchema} and converts between its messages
19
19
  * and the application-level {@link PlanObservations}.
20
+ *
21
+ * This module has no runtime dependency on Endo, so that it can be used
22
+ * outside of a locked-down (SES) environment, e.g. by the attestor. In
23
+ * particular, the values it returns are not hardened.
20
24
  */
21
25
 
22
26
 
@@ -32,10 +36,8 @@ import {
32
36
 
33
37
  } from '@agoric/orchestration/src/utils/eip712-messages.js';
34
38
  ;
35
- import { Fail, q } from '@endo/errors';
36
39
  ;
37
- import { isInstrumentId } from './places.js';
38
- import { isPortfolioBalancePlaceRef } from './type-guards.js';
40
+ import { isInstrumentId, isPortfolioBalancePlaceRef } from './places.js';
39
41
  ;
40
42
 
41
43
 
@@ -133,8 +135,9 @@ export const ymaxObservationMessageKit
133
135
 
134
136
 
135
137
  const toSafeNumber = (value , what ) => {
136
- value <= BigInt(Number.MAX_SAFE_INTEGER) ||
137
- Fail`${q(what)} out of range: ${value}`;
138
+ if (!(value <= BigInt(Number.MAX_SAFE_INTEGER))) {
139
+ throw RangeError(`${JSON.stringify(what)} out of range: ${value}`);
140
+ }
138
141
  return Number(value);
139
142
  };
140
143
 
@@ -148,18 +151,16 @@ export const portfolioObservationsToEIP712 = ({
148
151
  portfolioId,
149
152
  syncState: { policyVersion, rebalanceCount },
150
153
  observations: { balances, instrumentTvls },
151
- } ) =>
152
- harden({
153
- portfolio: portfolioId,
154
- syncState: { policyVersion, rebalanceCount },
155
- holdings: Object.entries(balances).flatMap(([place, balanceUsdc]) =>
156
- balanceUsdc === undefined ? [] : [{ place, balanceUsdc }],
157
- ),
158
- instruments: Object.entries(instrumentTvls).flatMap(
159
- ([instrumentId, tvl]) =>
160
- tvl === undefined ? [] : [{ instrumentId, tvlUsd: tvl.tvlUsd }],
161
- ),
162
- });
154
+ } ) => ({
155
+ portfolio: portfolioId,
156
+ syncState: { policyVersion, rebalanceCount },
157
+ holdings: Object.entries(balances).flatMap(([place, balanceUsdc]) =>
158
+ balanceUsdc === undefined ? [] : [{ place, balanceUsdc }],
159
+ ),
160
+ instruments: Object.entries(instrumentTvls).flatMap(([instrumentId, tvl]) =>
161
+ tvl === undefined ? [] : [{ instrumentId, tvlUsd: tvl.tvlUsd }],
162
+ ),
163
+ });
163
164
 
164
165
  /**
165
166
  * Convert the data of a signed `PortfolioObservations` message to its
@@ -180,27 +181,32 @@ export const portfolioObservationsFromEIP712 = ({
180
181
  } ) => {
181
182
  const balances = {};
182
183
  for (const { place, balanceUsdc } of holdings) {
183
- isPortfolioBalancePlaceRef(place) ||
184
- Fail`invalid holding place ${q(place)}`;
185
- !Object.hasOwn(balances, place) ||
186
- Fail`duplicate holding place ${q(place)}`;
184
+ if (!isPortfolioBalancePlaceRef(place)) {
185
+ throw TypeError(`invalid holding place ${JSON.stringify(place)}`);
186
+ }
187
+ if (Object.hasOwn(balances, place)) {
188
+ throw TypeError(`duplicate holding place ${JSON.stringify(place)}`);
189
+ }
187
190
  balances[place] = balanceUsdc;
188
191
  }
189
192
 
190
193
  const instrumentTvls = {};
191
194
  for (const { instrumentId, tvlUsd } of instruments) {
192
- isInstrumentId(instrumentId) || Fail`invalid instrument ${q(instrumentId)}`;
193
- !Object.hasOwn(instrumentTvls, instrumentId) ||
194
- Fail`duplicate instrument ${q(instrumentId)}`;
195
+ if (!isInstrumentId(instrumentId)) {
196
+ throw TypeError(`invalid instrument ${JSON.stringify(instrumentId)}`);
197
+ }
198
+ if (Object.hasOwn(instrumentTvls, instrumentId)) {
199
+ throw TypeError(`duplicate instrument ${JSON.stringify(instrumentId)}`);
200
+ }
195
201
  instrumentTvls[instrumentId ] = { tvlUsd };
196
202
  }
197
203
 
198
- return harden({
204
+ return {
199
205
  portfolioId: toSafeNumber(portfolio, 'portfolio'),
200
206
  syncState: {
201
207
  policyVersion: toSafeNumber(syncState.policyVersion, 'policyVersion'),
202
208
  rebalanceCount: toSafeNumber(syncState.rebalanceCount, 'rebalanceCount'),
203
209
  },
204
210
  observations: { balances, instrumentTvls },
205
- });
211
+ };
206
212
  };
package/src/places.d.ts CHANGED
@@ -1,7 +1,14 @@
1
+ /**
2
+ * @file Places (instruments, chain accounts) of portfolios.
3
+ *
4
+ * This module has no runtime dependencies (in particular not on Endo), so that
5
+ * it can be used outside of a locked-down (SES) environment, e.g. by
6
+ * {@link ./observation-messages.ts}.
7
+ */
1
8
  import type { TypeTag } from '@agoric/internal/src/tagged.js';
2
9
  import type { SupportedChain, YieldProtocol } from './constants.js';
3
10
  import type { InstrumentId } from './instruments.js';
4
- import type { AssetPlaceRef } from './types.js';
11
+ import type { AssetPlaceRef, DepositFromChainRef, InterChainAccountRef, LocalChainAccountRef, PortfolioBalancePlaceRef, WithdrawToChainRef } from './types.js';
5
12
  export type TokenUsage = 'swapFrom' | 'swapTo';
6
13
  export type TokenIdKey = TypeTag<string, 'TokenIdKey'>;
7
14
  export declare const makeTokenIdKey: (tokenId: string) => TokenIdKey;
@@ -420,5 +427,45 @@ export type ChainTokenMetadata = Record<string, ChainTokenMetadataEntry>;
420
427
  * (i.e., does it start with an ASCII letter)?
421
428
  */
422
429
  export declare const isInstrumentId: (ref: string) => ref is InstrumentId;
430
+ /**
431
+ * Without regard to supported chains, is the input plausibly an
432
+ * InterChainAccountRef (i.e., does it start with `@`)?
433
+ */
434
+ export declare const isInterChainAccountRef: (ref: string) => ref is InterChainAccountRef;
435
+ /**
436
+ * Without regard to supported chains or instruments, is the input plausibly a
437
+ * PortfolioBalancePlaceRef (i.e., an InterChainAccountRef or InstrumentId)?
438
+ */
439
+ export declare const isPortfolioBalancePlaceRef: (ref: string) => ref is PortfolioBalancePlaceRef;
440
+ /**
441
+ * Without regard to supported chains, is the input plausibly a
442
+ * DepositFromChainRef (i.e., does it start with `+`)?
443
+ */
444
+ export declare const isDepositFromChainRef: (ref: string) => ref is DepositFromChainRef;
445
+ /**
446
+ * Without regard to supported chains, is the input plausibly a
447
+ * LocalChainAccountRef (i.e., does it start with `+`)?
448
+ */
449
+ export declare const isLocalChainAccountRef: (ref: string) => ref is LocalChainAccountRef;
450
+ /**
451
+ * Without regard to supported chains, is the input plausibly a
452
+ * WithdrawToChainRef (i.e., does it start with `-`)?
453
+ */
454
+ export declare const isWithdrawToChainRef: (ref: string) => ref is WithdrawToChainRef;
455
+ /**
456
+ * Is the input an ERC-4626 InstrumentId
457
+ * (i.e., does it start with 'ERC4626_')?
458
+ */
459
+ export declare const isERC4626InstrumentId: (ref: string) => ref is ERC4626InstrumentId;
460
+ /**
461
+ * Is the input an ERC-4626 and a morpho InstrumentId
462
+ * (i.e., does it start with 'ERC4626_morpho')?
463
+ */
464
+ export declare const isERC4626MorphoInstrumentId: (ref: string) => ref is ERC4626InstrumentId;
465
+ /**
466
+ * Is the input an Beefy InstrumentId
467
+ * (i.e., does it start with 'Beefy_')?
468
+ */
469
+ export declare const isBeefyInstrumentId: (ref: string) => ref is BeefyInstrumentId;
423
470
  export declare const chainOf: (id: AssetPlaceRef) => SupportedChain;
424
471
  //# sourceMappingURL=places.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"places.d.ts","sourceRoot":"","sources":["places.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAEvD,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,UAC2B,CAAC;AAG7E;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAC/B,CAAC;AAcF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GACzD;IACE,QAAQ,EAAE,aAAa,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC;CAC3B,CAAC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rC,CAAC;AAGtB;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,MAAM,KACV,GAAG,IAAI,mBAAiD,CAAC;AAG5D;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GACtC,KAAK,MAAM,KACV,GAAG,IAAI,mBAAuD,CAAC;AAGlE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,KAAG,GAAG,IAAI,iBAC/B,CAAC;AAI3B,eAAO,MAAM,OAAO,GAAI,IAAI,aAAa,KAAG,cAa3C,CAAC"}
package/src/places.js CHANGED
@@ -1,9 +1,35 @@
1
- import { Fail } from '@endo/errors';
1
+ /**
2
+ * @file Places (instruments, chain accounts) of portfolios.
3
+ *
4
+ * This module has no runtime dependencies (in particular not on Endo), so that
5
+ * it can be used outside of a locked-down (SES) environment, e.g. by
6
+ * {@link ./observation-messages.ts}.
7
+ */
2
8
 
3
- ;
4
- ;
5
- ;
6
- ;
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ const isPrimitive = (value ) =>
22
+ !value || (typeof value !== 'object' && typeof value !== 'function');
23
+
24
+ const deepFreeze = (value ) => {
25
+ if (isPrimitive(value)) return value;
26
+ const obj = value ;
27
+ Object.freeze(obj);
28
+ for (const key of Reflect.ownKeys(obj)) {
29
+ deepFreeze(obj[key]);
30
+ }
31
+ return value;
32
+ };
7
33
 
8
34
  ;
9
35
 
@@ -11,7 +37,7 @@ import { Fail } from '@endo/errors';
11
37
 
12
38
  export const makeTokenIdKey = (tokenId ) =>
13
39
  (tokenId.startsWith('0x') ? tokenId.toLowerCase() : tokenId) ;
14
- harden(makeTokenIdKey);
40
+ deepFreeze(makeTokenIdKey);
15
41
 
16
42
  /**
17
43
  * cf. https://github.com/Agoric/ymax-web/blob/main/yds/src/data/tokens.ts:
@@ -27,18 +53,6 @@ harden(makeTokenIdKey);
27
53
 
28
54
 
29
55
 
30
- const isPrimitive = (value ) => Object(value) !== value;
31
-
32
- const deepFreeze = (value ) => {
33
- if (isPrimitive(value)) return value;
34
- const obj = value ;
35
- Object.freeze(obj);
36
- for (const key of Reflect.ownKeys(obj)) {
37
- deepFreeze(obj[key]);
38
- }
39
- return value;
40
- };
41
-
42
56
  ;
43
57
 
44
58
 
@@ -257,6 +271,77 @@ export const isInstrumentId = (ref ) =>
257
271
  !!ref.match(/^[a-z]/i);
258
272
  deepFreeze(isInstrumentId);
259
273
 
274
+ /**
275
+ * Without regard to supported chains, is the input plausibly an
276
+ * InterChainAccountRef (i.e., does it start with `@`)?
277
+ */
278
+ export const isInterChainAccountRef = (
279
+ ref ,
280
+ ) => ref.startsWith('@');
281
+ deepFreeze(isInterChainAccountRef);
282
+
283
+ /**
284
+ * Without regard to supported chains or instruments, is the input plausibly a
285
+ * PortfolioBalancePlaceRef (i.e., an InterChainAccountRef or InstrumentId)?
286
+ */
287
+ export const isPortfolioBalancePlaceRef = (
288
+ ref ,
289
+ ) =>
290
+ isInterChainAccountRef(ref) || isInstrumentId(ref);
291
+ deepFreeze(isPortfolioBalancePlaceRef);
292
+
293
+ /**
294
+ * Without regard to supported chains, is the input plausibly a
295
+ * DepositFromChainRef (i.e., does it start with `+`)?
296
+ */
297
+ export const isDepositFromChainRef = (
298
+ ref ,
299
+ ) => ref.startsWith('+');
300
+ deepFreeze(isDepositFromChainRef);
301
+
302
+ /**
303
+ * Without regard to supported chains, is the input plausibly a
304
+ * LocalChainAccountRef (i.e., does it start with `+`)?
305
+ */
306
+ export const isLocalChainAccountRef = (
307
+ ref ,
308
+ ) => ref.startsWith('+');
309
+ deepFreeze(isLocalChainAccountRef);
310
+
311
+ /**
312
+ * Without regard to supported chains, is the input plausibly a
313
+ * WithdrawToChainRef (i.e., does it start with `-`)?
314
+ */
315
+ export const isWithdrawToChainRef = (ref ) =>
316
+ ref.startsWith('-');
317
+ deepFreeze(isWithdrawToChainRef);
318
+
319
+ /**
320
+ * Is the input an ERC-4626 InstrumentId
321
+ * (i.e., does it start with 'ERC4626_')?
322
+ */
323
+ export const isERC4626InstrumentId = (
324
+ ref ,
325
+ ) => ref.startsWith('ERC4626_');
326
+ deepFreeze(isERC4626InstrumentId);
327
+
328
+ /**
329
+ * Is the input an ERC-4626 and a morpho InstrumentId
330
+ * (i.e., does it start with 'ERC4626_morpho')?
331
+ */
332
+ export const isERC4626MorphoInstrumentId = (
333
+ ref ,
334
+ ) => ref.startsWith('ERC4626_morpho');
335
+ deepFreeze(isERC4626MorphoInstrumentId);
336
+
337
+ /**
338
+ * Is the input an Beefy InstrumentId
339
+ * (i.e., does it start with 'Beefy_')?
340
+ */
341
+ export const isBeefyInstrumentId = (ref ) =>
342
+ ref.startsWith('Beefy_');
343
+ deepFreeze(isBeefyInstrumentId);
344
+
260
345
  // XXX Possible to consolidate with {@link getChainNameOfPlaceRef}?
261
346
  export const chainOf = (id ) => {
262
347
  if (id.startsWith('<')) return 'agoric';
@@ -270,6 +355,6 @@ export const chainOf = (id ) => {
270
355
  const m = /^(?:[A-Za-z0-9]+_)+([A-Za-z0-9]+)$/.exec(id);
271
356
  if (m) return m[1] ;
272
357
 
273
- throw Fail`Cannot determine chain for ${id}`;
358
+ throw Error(`Cannot determine chain for ${id}`);
274
359
  };
275
360
  deepFreeze(chainOf);
@@ -1,51 +1,11 @@
1
1
  import type { TypedPattern } from '@agoric/internal';
2
- import { type BeefyInstrumentId, type ChainTokenMetadata, type ERC4626InstrumentId, type TokenMetadata } from './places.js';
3
- import type { DepositFromChainRef, LocalChainAccountRef, PortfolioAgentKey, InterChainAccountRef, PortfolioBalancePlaceRef, PortfolioDelegatedClaimRewardsParams, PortfolioDelegatedRebalanceParams, PortfolioSyncState, WithdrawToChainRef } from './types.js';
4
- export { isInstrumentId, makeTokenIdKey } from './places.js';
2
+ import type { ChainTokenMetadata, TokenMetadata } from './places.js';
3
+ import type { PortfolioAgentKey, PortfolioDelegatedClaimRewardsParams, PortfolioDelegatedRebalanceParams, PortfolioSyncState } from './types.js';
4
+ export { isBeefyInstrumentId, isDepositFromChainRef, isERC4626InstrumentId, isERC4626MorphoInstrumentId, isInstrumentId, isInterChainAccountRef, isLocalChainAccountRef, isPortfolioBalancePlaceRef, isWithdrawToChainRef, makeTokenIdKey, } from './places.js';
5
5
  export type { ChainTokenMetadata, ChainTokenMetadataEntry, TokenIdKey, TokenMetadata, } from './places.js';
6
6
  export declare const TokenUsageShape: import("@endo/patterns").MatcherOf<"or", ["swapFrom", "swapTo"]>;
7
7
  export declare const TokenMetadataShape: TypedPattern<TokenMetadata>;
8
8
  export declare const ChainTokenMetadataShape: TypedPattern<ChainTokenMetadata>;
9
- /**
10
- * Without regard to supported chains, is the input plausibly a
11
- * DepositFromChainRef (i.e., does it start with `+`)?
12
- */
13
- export declare const isDepositFromChainRef: (ref: string) => ref is DepositFromChainRef;
14
- /**
15
- * Without regard to supported chains, is the input plausibly a
16
- * LocalChainAccountRef (i.e., does it start with `+`)?
17
- */
18
- export declare const isLocalChainAccountRef: (ref: string) => ref is LocalChainAccountRef;
19
- /**
20
- * Without regard to supported chains, is the input plausibly an
21
- * InterChainAccountRef (i.e., does it start with `@`)?
22
- */
23
- export declare const isInterChainAccountRef: (ref: string) => ref is InterChainAccountRef;
24
- /**
25
- * Without regard to supported chains or instruments, is the input plausibly a
26
- * PortfolioBalancePlaceRef (i.e., an InterChainAccountRef or InstrumentId)?
27
- */
28
- export declare const isPortfolioBalancePlaceRef: (ref: string) => ref is PortfolioBalancePlaceRef;
29
- /**
30
- * Without regard to supported chains, is the input plausibly a
31
- * WithdrawToChainRef (i.e., does it start with `-`)?
32
- */
33
- export declare const isWithdrawToChainRef: (ref: string) => ref is WithdrawToChainRef;
34
- /**
35
- * Is the input an ERC-4626 InstrumentId
36
- * (i.e., does it start with 'ERC4626_')?
37
- */
38
- export declare const isERC4626InstrumentId: (ref: string) => ref is ERC4626InstrumentId;
39
- /**
40
- * Is the input an ERC-4626 and a morpho InstrumentId
41
- * (i.e., does it start with 'ERC4626_morpho')?
42
- */
43
- export declare const isERC4626MorphoInstrumentId: (ref: string) => ref is ERC4626InstrumentId;
44
- /**
45
- * Is the input an Beefy InstrumentId
46
- * (i.e., does it start with 'Beefy_')?
47
- */
48
- export declare const isBeefyInstrumentId: (ref: string) => ref is BeefyInstrumentId;
49
9
  export declare const PortfolioAgentKeyShape: TypedPattern<PortfolioAgentKey>;
50
10
  /** The shape for the optional `agentMemo` field for flows started by an agent */
51
11
  export declare const PortfolioFlowAgentMemoShape: TypedPattern<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,oCAAoC,EACpC,iCAAiC,EACjC,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,EACV,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,eAAe,kEAA6B,CAAC;AAG1D,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,aAAa,CAW1D,CAAC;AAGF,eAAO,MAAM,uBAAuB,EAAE,YAAY,CAAC,kBAAkB,CAWlE,CAAC;AAGJ;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,MAAM,KACV,GAAG,IAAI,mBAA0C,CAAC;AAGrD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,KAAK,MAAM,KACV,GAAG,IAAI,oBAA2C,CAAC;AAGtD;;;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,2BAA2B,EAC3B,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,EACV,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,eAAe,kEAA6B,CAAC;AAG1D,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,aAAa,CAW1D,CAAC;AAGF,eAAO,MAAM,uBAAuB,EAAE,YAAY,CAAC,kBAAkB,CAWlE,CAAC;AAGJ,eAAO,MAAM,sBAAsB,EAAE,YAAY,CAAC,iBAAiB,CACvD,CAAC;AAEb,iFAAiF;AACjF,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAAC,MAAM,CAE3D,CAAC;AAEH,eAAO,MAAM,uBAAuB,EAAE,YAAY,CAAC,kBAAkB,CAIjE,CAAC;AAEL,eAAO,MAAM,sCAAsC,EAAE,YAAY,CAAC,iCAAiC,CAKhG,CAAC;AAEJ,eAAO,MAAM,yCAAyC,EAAE,YAAY,CAAC,oCAAoC,CAKtG,CAAC"}
@@ -1,25 +1,25 @@
1
1
 
2
2
  import { M } from '@endo/patterns';
3
- import {
4
- isInstrumentId,
5
-
6
-
7
-
8
-
9
- } from './places.js';
3
+ ;
10
4
  ;
11
-
12
-
13
5
 
14
-
15
-
16
6
 
17
7
 
18
8
 
19
-
20
9
 
21
10
 
22
- export { isInstrumentId, makeTokenIdKey } from './places.js';
11
+ export {
12
+ isBeefyInstrumentId,
13
+ isDepositFromChainRef,
14
+ isERC4626InstrumentId,
15
+ isERC4626MorphoInstrumentId,
16
+ isInstrumentId,
17
+ isInterChainAccountRef,
18
+ isLocalChainAccountRef,
19
+ isPortfolioBalancePlaceRef,
20
+ isWithdrawToChainRef,
21
+ makeTokenIdKey,
22
+ } from './places.js';
23
23
  ;
24
24
 
25
25
 
@@ -58,77 +58,6 @@ export const ChainTokenMetadataShape =
58
58
  );
59
59
  harden(ChainTokenMetadataShape);
60
60
 
61
- /**
62
- * Without regard to supported chains, is the input plausibly a
63
- * DepositFromChainRef (i.e., does it start with `+`)?
64
- */
65
- export const isDepositFromChainRef = (
66
- ref ,
67
- ) => ref.startsWith('+');
68
- harden(isDepositFromChainRef);
69
-
70
- /**
71
- * Without regard to supported chains, is the input plausibly a
72
- * LocalChainAccountRef (i.e., does it start with `+`)?
73
- */
74
- export const isLocalChainAccountRef = (
75
- ref ,
76
- ) => ref.startsWith('+');
77
- harden(isLocalChainAccountRef);
78
-
79
- /**
80
- * Without regard to supported chains, is the input plausibly an
81
- * InterChainAccountRef (i.e., does it start with `@`)?
82
- */
83
- export const isInterChainAccountRef = (
84
- ref ,
85
- ) => ref.startsWith('@');
86
- harden(isInterChainAccountRef);
87
-
88
- /**
89
- * Without regard to supported chains or instruments, is the input plausibly a
90
- * PortfolioBalancePlaceRef (i.e., an InterChainAccountRef or InstrumentId)?
91
- */
92
- export const isPortfolioBalancePlaceRef = (
93
- ref ,
94
- ) =>
95
- isInterChainAccountRef(ref) || isInstrumentId(ref);
96
- harden(isPortfolioBalancePlaceRef);
97
-
98
- /**
99
- * Without regard to supported chains, is the input plausibly a
100
- * WithdrawToChainRef (i.e., does it start with `-`)?
101
- */
102
- export const isWithdrawToChainRef = (ref ) =>
103
- ref.startsWith('-');
104
- harden(isWithdrawToChainRef);
105
-
106
- /**
107
- * Is the input an ERC-4626 InstrumentId
108
- * (i.e., does it start with 'ERC4626_')?
109
- */
110
- export const isERC4626InstrumentId = (
111
- ref ,
112
- ) => ref.startsWith('ERC4626_');
113
- harden(isERC4626InstrumentId);
114
-
115
- /**
116
- * Is the input an ERC-4626 and a morpho InstrumentId
117
- * (i.e., does it start with 'ERC4626_morpho')?
118
- */
119
- export const isERC4626MorphoInstrumentId = (
120
- ref ,
121
- ) => ref.startsWith('ERC4626_morpho');
122
- harden(isERC4626MorphoInstrumentId);
123
-
124
- /**
125
- * Is the input an Beefy InstrumentId
126
- * (i.e., does it start with 'Beefy_')?
127
- */
128
- export const isBeefyInstrumentId = (ref ) =>
129
- ref.startsWith('Beefy_');
130
- harden(isBeefyInstrumentId);
131
-
132
61
  export const PortfolioAgentKeyShape =
133
62
  M.string();
134
63