@agoric/portfolio-api 0.1.1-dev-d756c83.0.d756c83 → 0.1.1-dev-e9efaa1.0.e9efaa1

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-d756c83.0.d756c83",
3
+ "version": "0.1.1-dev-e9efaa1.0.e9efaa1",
4
4
  "description": "API for Portfolio management",
5
5
  "type": "module",
6
6
  "files": [
@@ -11,8 +11,8 @@
11
11
  "bin": "./src/cli/bin.js",
12
12
  "scripts": {
13
13
  "build": "exit 0",
14
- "prepack": "yarn run -T tsc --build tsconfig.build.json",
15
- "postpack": "git clean -f '*.d.*ts*' '*.tsbuildinfo'",
14
+ "prepack": "yarn run -T prepack-package",
15
+ "postpack": "yarn run -T postpack-package",
16
16
  "test": "ava",
17
17
  "test:c8": "c8 --all $C8_OPTIONS ava",
18
18
  "test:xs": "exit 0",
@@ -27,8 +27,8 @@
27
27
  "generate:ymax-machine": "npx tsx scripts/gen-ymax-machine.mts"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/internal": "0.3.3-dev-d756c83.0.d756c83",
31
- "@agoric/orchestration": "0.1.1-dev-d756c83.0.d756c83",
30
+ "@agoric/internal": "0.3.3-dev-e9efaa1.0.e9efaa1",
31
+ "@agoric/orchestration": "0.1.1-dev-e9efaa1.0.e9efaa1",
32
32
  "@endo/common": "^1.2.13",
33
33
  "@endo/errors": "^1.2.13",
34
34
  "@endo/patterns": "^1.7.0"
@@ -69,5 +69,5 @@
69
69
  "engines": {
70
70
  "node": "^20.9 || ^22.11"
71
71
  },
72
- "gitHead": "d756c838c7eb3e3cec4a8bdf5c24b97f942b754e"
72
+ "gitHead": "e9efaa12254f2c9a6faffc40ade2f1d9a70b87ae"
73
73
  }
@@ -11,8 +11,8 @@
11
11
  */
12
12
  import type { Address, TypedDataDomain, TypedDataToPrimitiveTypes } from 'abitype';
13
13
  import type { TypedDataDefinition } from 'viem';
14
- import type { TypedDataParameter } from '@agoric/orchestration/src/utils/abitype.ts';
15
- import { type Witness, type getPermitWitnessTransferFromData, type getPermitBatchWitnessTransferFromData } from '@agoric/orchestration/src/utils/permit2.ts';
14
+ import type { TypedDataParameter } from '@agoric/orchestration/src/utils/abitype.js';
15
+ import { type Witness, type getPermitWitnessTransferFromData, type getPermitBatchWitnessTransferFromData } from '@agoric/orchestration/src/utils/permit2.js';
16
16
  declare const YMAX_DOMAIN_NAME = "Ymax";
17
17
  declare const YMAX_DOMAIN_VERSION = "1";
18
18
  declare const StandaloneDomainTypeParams: [{
@@ -10,21 +10,21 @@
10
10
  * name but with some effort this could be parametrizable
11
11
  */
12
12
 
13
- import type {
14
- Address,
15
- TypedData,
16
- TypedDataDomain,
17
- TypedDataToPrimitiveTypes,
18
- } from 'abitype';
19
- import type { TypedDataDefinition } from 'viem';
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
20
  import { Fail, q } from '@endo/errors';
21
- import type { TypedDataParameter } from '@agoric/orchestration/src/utils/abitype.ts';
21
+ ;
22
22
  import {
23
- type Witness,
24
- type getPermitWitnessTransferFromData,
25
- type getPermitBatchWitnessTransferFromData,
23
+
24
+
25
+
26
26
  makeWitness,
27
- } from '@agoric/orchestration/src/utils/permit2.ts';
27
+ } from '@agoric/orchestration/src/utils/permit2.js';
28
28
 
29
29
  const YMAX_DOMAIN_NAME = 'Ymax';
30
30
  const YMAX_DOMAIN_VERSION = '1';
@@ -36,25 +36,25 @@ const StandaloneDomainTypeParams = [
36
36
  { name: 'version', type: 'string' },
37
37
  { name: 'chainId', type: 'uint256' },
38
38
  { name: 'verifyingContract', type: 'address' },
39
- ] as const satisfies TypedDataParameter[];
39
+ ] ;
40
40
 
41
41
  const YmaxStandaloneDomainBase = {
42
42
  name: YMAX_DOMAIN_NAME,
43
43
  version: YMAX_DOMAIN_VERSION,
44
- } as const satisfies TypedDataDomain;
45
- export type YmaxStandaloneDomain = typeof YmaxStandaloneDomainBase & {
46
- chainId: bigint;
47
- verifyingContract: Address;
48
- };
44
+ } ;
45
+ ;
46
+
47
+
48
+
49
49
 
50
50
  // A param to designate the portfolio in operations by its `portfolioId`
51
51
  const PortfolioIdParam = {
52
52
  name: 'portfolio',
53
53
  type: 'uint256',
54
- } as const satisfies TypedDataParameter;
54
+ } ;
55
55
 
56
56
  // XXX: Remove
57
- const SharedPortfolioTypeParams = [] as const satisfies TypedDataParameter[];
57
+ const SharedPortfolioTypeParams = [] ;
58
58
 
59
59
  /**
60
60
  * Fields included in Permit data that we don't want duplicated in witness data,
@@ -63,7 +63,7 @@ const SharedPortfolioTypeParams = [] as const satisfies TypedDataParameter[];
63
63
  const PortfolioStandaloneTypeParams = [
64
64
  { name: 'nonce', type: 'uint256' },
65
65
  { name: 'deadline', type: 'uint256' },
66
- ] as const satisfies TypedDataParameter[];
66
+ ] ;
67
67
 
68
68
  /**
69
69
  * The set of portfolio operations supported by EVM Wallets, and their associated params
@@ -72,16 +72,16 @@ const OperationTypes = {
72
72
  OpenPortfolio: [{ name: 'allocations', type: 'Allocation[]' }],
73
73
  Rebalance: [{ name: 'allocations', type: 'Allocation[]' }, PortfolioIdParam],
74
74
  Deposit: [PortfolioIdParam],
75
- } as const satisfies TypedData;
76
- type OperationTypes = typeof OperationTypes;
77
- export type OperationTypeNames = keyof OperationTypes;
75
+ } ;
76
+ ;
77
+ ;
78
78
 
79
79
  const OperationSubTypes = {
80
80
  Allocation: [
81
81
  { name: 'instrument', type: 'string' },
82
82
  { name: 'portion', type: 'uint256' },
83
83
  ],
84
- } as const satisfies TypedData;
84
+ } ;
85
85
 
86
86
  /**
87
87
  * Target allocation for portfolio positions.
@@ -92,86 +92,86 @@ const OperationSubTypes = {
92
92
  * - [{instrument: 'A', portion: 60}, {instrument: 'B', portion: 40}] => 60:40 ratio
93
93
  * - [{instrument: 'A', portion: 6}, {instrument: 'B', portion: 4}] => 6:4 ratio (same as 60:40)
94
94
  */
95
- export type TargetAllocation = TypedDataToPrimitiveTypes<
96
- typeof OperationSubTypes
97
- >['Allocation'];
95
+ ;
96
+
97
+
98
98
 
99
99
  /**
100
100
  * In the wrapped case, the domain is fixed by permit2, so we can't choose name/version there.
101
101
  * so we put the ymax-specifc domain name and version in the type name.
102
102
  */
103
- const getYmaxWitnessTypeName = <T extends OperationTypeNames>(operation: T) =>
104
- `${YMAX_DOMAIN_NAME}V${YMAX_DOMAIN_VERSION}${operation}` as const;
105
- type YmaxWitnessTypeName<T extends OperationTypeNames> = ReturnType<
106
- typeof getYmaxWitnessTypeName<T>
107
- >;
108
- const getYmaxWitnessFieldName = <T extends OperationTypeNames>(operation: T) =>
109
- `${YMAX_WITNESS_FIELD_NAME_PREFIX}${operation}` as const;
110
- type YmaxWitnessFieldName<T extends OperationTypeNames> = ReturnType<
111
- typeof getYmaxWitnessFieldName<T>
112
- >;
103
+ const getYmaxWitnessTypeName = (operation ) =>
104
+ `${YMAX_DOMAIN_NAME}V${YMAX_DOMAIN_VERSION}${operation}` ;
105
+ ;
106
+
107
+
108
+ const getYmaxWitnessFieldName = (operation ) =>
109
+ `${YMAX_WITNESS_FIELD_NAME_PREFIX}${operation}` ;
110
+ ;
111
+
112
+
113
113
 
114
114
  /**
115
115
  * showing a field named "witness" in the wallet signing UI is... boring
116
116
  * so let's put something more relevant like the @{link OperationTypes}: Deposit etc.
117
117
  */
118
- const getYmaxWitnessTypeParam = <T extends OperationTypeNames>(
119
- operation: T,
120
- ): YmaxWitnessTypeParam<T> => ({
118
+ const getYmaxWitnessTypeParam = (
119
+ operation ,
120
+ ) => ({
121
121
  name: getYmaxWitnessFieldName(operation),
122
122
  type: getYmaxWitnessTypeName(operation),
123
123
  });
124
- export type YmaxWitnessTypeParam<
125
- T extends OperationTypeNames = OperationTypeNames,
126
- > = TypedDataParameter<YmaxWitnessFieldName<T>, YmaxWitnessTypeName<T>>;
124
+ ;
125
+
126
+
127
127
 
128
128
  // TODO: Filter operation types to only those needed for witness/standalone
129
- type YmaxWitnessOperationTypes<
130
- T extends OperationTypeNames = OperationTypeNames,
131
- > = {
132
- [K in T as YmaxWitnessTypeName<K>]: [
133
- ...OperationTypes[K],
134
- ...typeof SharedPortfolioTypeParams,
135
- ];
136
- };
137
- type YmaxWitnessTypes<T extends OperationTypeNames = OperationTypeNames> =
138
- YmaxWitnessOperationTypes<T> & typeof OperationSubTypes;
139
- type YmaxStandaloneOperationTypes<
140
- T extends OperationTypeNames = OperationTypeNames,
141
- > = {
142
- [K in T]: [
143
- ...OperationTypes[K],
144
- ...typeof SharedPortfolioTypeParams,
145
- ...typeof PortfolioStandaloneTypeParams,
146
- ];
147
- };
148
- type YmaxStandaloneTypes<T extends OperationTypeNames = OperationTypeNames> =
149
- YmaxStandaloneOperationTypes<T> &
150
- typeof OperationSubTypes & {
151
- EIP712Domain: typeof StandaloneDomainTypeParams;
152
- };
153
-
154
- export type YmaxOperationType<T extends OperationTypeNames> =
155
- TypedDataToPrimitiveTypes<OperationTypes & typeof OperationSubTypes>[T];
129
+ ;
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+ ;
138
+
139
+ ;
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ ;
149
+
150
+
151
+
152
+
153
+
154
+ ;
155
+
156
156
 
157
157
  // Hack to satisfy TypeScript limitations with generic inference in complex types
158
158
  // Equivalent to `YmaxWitnessTypeParam`
159
- type YmaxWitnessMappedTypeParam<T extends OperationTypeNames> =
160
- TypedDataParameter<
161
- YmaxWitnessFieldName<T>,
162
- Extract<keyof YmaxWitnessOperationTypes<T>, string>
163
- >;
159
+ ;
160
+
161
+
162
+
163
+
164
164
 
165
- const getYmaxWitnessTypes = <T extends OperationTypeNames>(operation: T) =>
165
+ const getYmaxWitnessTypes = (operation ) =>
166
166
  ({
167
167
  [getYmaxWitnessTypeName(operation)]: [
168
168
  ...OperationTypes[operation],
169
169
  ...SharedPortfolioTypeParams,
170
170
  ],
171
171
  ...OperationSubTypes,
172
- }) as YmaxWitnessTypes<T> satisfies TypedData;
172
+ }) ;
173
173
 
174
- const getYmaxStandaloneTypes = <T extends OperationTypeNames>(operation: T) =>
174
+ const getYmaxStandaloneTypes = (operation ) =>
175
175
  ({
176
176
  EIP712Domain: StandaloneDomainTypeParams,
177
177
  [operation]: [
@@ -180,24 +180,24 @@ const getYmaxStandaloneTypes = <T extends OperationTypeNames>(operation: T) =>
180
180
  ...PortfolioStandaloneTypeParams,
181
181
  ],
182
182
  ...OperationSubTypes,
183
- }) as YmaxStandaloneTypes<T> satisfies TypedData;
183
+ }) ;
184
184
 
185
- export const getYmaxOperationTypes = <T extends OperationTypeNames>(
186
- operation: T,
185
+ export const getYmaxOperationTypes = (
186
+ operation ,
187
187
  ) =>
188
188
  ({
189
189
  [operation]: OperationTypes[operation],
190
190
  ...OperationSubTypes,
191
- }) as {
192
- [K in T]: OperationTypes[K];
193
- } & typeof OperationSubTypes satisfies TypedData;
194
-
195
- export const getYmaxWitness = <T extends OperationTypeNames>(
196
- operation: T,
197
- data: NoInfer<
198
- TypedDataToPrimitiveTypes<YmaxWitnessTypes>[YmaxWitnessTypeName<T>]
199
- >,
200
- ): Witness<YmaxWitnessTypes<T>, YmaxWitnessMappedTypeParam<T>> =>
191
+ })
192
+
193
+ ;
194
+
195
+ export const getYmaxWitness = (
196
+ operation ,
197
+ data
198
+
199
+ ,
200
+ ) =>
201
201
  // @ts-expect-error some generic inference issue I suppose?
202
202
  makeWitness(
203
203
  // @ts-expect-error some generic inference issue I suppose?
@@ -207,22 +207,22 @@ export const getYmaxWitness = <T extends OperationTypeNames>(
207
207
  );
208
208
 
209
209
  export const getYmaxStandaloneDomain = (
210
- chainId: bigint | number,
211
- verifyingContract: Address,
212
- ): YmaxStandaloneDomain => ({
210
+ chainId ,
211
+ verifyingContract ,
212
+ ) => ({
213
213
  ...YmaxStandaloneDomainBase,
214
214
  chainId: BigInt(chainId),
215
215
  verifyingContract,
216
216
  });
217
217
 
218
- export const getYmaxStandaloneOperationData = <T extends OperationTypeNames>(
219
- data: NoInfer<TypedDataToPrimitiveTypes<YmaxStandaloneTypes>[T]>,
220
- operation: T,
221
- chainId: bigint | number,
222
- verifyingContract: Address,
223
- ): TypedDataDefinition<YmaxStandaloneTypes<T>, T, T> & {
224
- domain: YmaxStandaloneDomain;
225
- } => {
218
+ export const getYmaxStandaloneOperationData = (
219
+ data ,
220
+ operation ,
221
+ chainId ,
222
+ verifyingContract ,
223
+
224
+
225
+ ) => {
226
226
  const types = getYmaxStandaloneTypes(operation);
227
227
 
228
228
  // @ts-expect-error some generic inference issue I suppose?
@@ -234,32 +234,32 @@ export const getYmaxStandaloneOperationData = <T extends OperationTypeNames>(
234
234
  };
235
235
  };
236
236
 
237
- export type YmaxStandaloneOperationData<
238
- T extends OperationTypeNames = OperationTypeNames,
239
- > = ReturnType<typeof getYmaxStandaloneOperationData<T>>;
240
-
241
- export type YmaxPermitWitnessTransferFromData<
242
- T extends OperationTypeNames = OperationTypeNames,
243
- > = ReturnType<
244
- typeof getPermitWitnessTransferFromData<
245
- YmaxWitnessTypes<T>,
246
- YmaxWitnessMappedTypeParam<T>
247
- >
248
- >;
249
-
250
- export type YmaxPermitBatchWitnessTransferFromData<
251
- T extends OperationTypeNames = OperationTypeNames,
252
- > = ReturnType<
253
- typeof getPermitBatchWitnessTransferFromData<
254
- YmaxWitnessTypes<T>,
255
- YmaxWitnessMappedTypeParam<T>
256
- >
257
- >;
237
+ ;
238
+
239
+
240
+
241
+ ;
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+ ;
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
258
 
259
259
  export function validateYmaxDomain(
260
- domain: TypedDataDomain,
261
- validContractAddresses?: Record<number | string, Address>,
262
- ): asserts domain is YmaxStandaloneDomain {
260
+ domain ,
261
+ validContractAddresses ,
262
+ ) {
263
263
  if (domain.name !== YMAX_DOMAIN_NAME) {
264
264
  throw new Error(
265
265
  `Invalid Ymax domain name: ${domain.name} (expected ${YMAX_DOMAIN_NAME})`,
@@ -286,9 +286,9 @@ export function validateYmaxDomain(
286
286
  // XXX: check no extra fields?
287
287
  }
288
288
 
289
- export function validateYmaxOperationTypeName<T extends OperationTypeNames>(
290
- typeName: string,
291
- ): asserts typeName is T {
289
+ export function validateYmaxOperationTypeName (
290
+ typeName ,
291
+ ) {
292
292
  if (!(typeName in OperationTypes)) {
293
293
  throw new Error(
294
294
  `Unknown Ymax operation type: ${typeName} (expected one of ${Object.keys(OperationTypes).join(', ')})`,
@@ -296,8 +296,8 @@ export function validateYmaxOperationTypeName<T extends OperationTypeNames>(
296
296
  }
297
297
  }
298
298
 
299
- export const splitWitnessFieldType = <T extends OperationTypeNames>(
300
- fieldName: `${typeof YMAX_DOMAIN_NAME}V${typeof YMAX_DOMAIN_VERSION}${T}`,
299
+ export const splitWitnessFieldType = (
300
+ fieldName ,
301
301
  ) => {
302
302
  const match = fieldName.match(/^YmaxV(\d+)(\w+)$/u);
303
303
  if (!match) {
@@ -307,10 +307,10 @@ export const splitWitnessFieldType = <T extends OperationTypeNames>(
307
307
  const domain = {
308
308
  name: YMAX_DOMAIN_NAME,
309
309
  version,
310
- } satisfies TypedDataDomain;
310
+ } ;
311
311
 
312
312
  validateYmaxDomain(domain);
313
- validateYmaxOperationTypeName<T>(operation);
313
+ validateYmaxOperationTypeName (operation);
314
314
 
315
315
  return {
316
316
  domain,
@@ -7,8 +7,8 @@
7
7
  */
8
8
  import type { AbiParameterToPrimitiveType, Address, TypedDataDomain } from 'abitype';
9
9
  import type { hashStruct, isHex, recoverTypedDataAddress, validateTypedData } from 'viem/utils';
10
- import { encodeType, type WithSignature } from '@agoric/orchestration/src/utils/viem.ts';
11
- import { type PermitWitnessTransferFromInputComponents } from '@agoric/orchestration/src/utils/permit2.ts';
10
+ import { encodeType, type WithSignature } from '@agoric/orchestration/src/utils/viem.js';
11
+ import { type PermitWitnessTransferFromInputComponents } from '@agoric/orchestration/src/utils/permit2.js';
12
12
  import { type OperationTypeNames, type YmaxStandaloneOperationData, type YmaxPermitWitnessTransferFromData, type YmaxOperationType } from './eip712-messages.ts';
13
13
  export type YmaxOperationDetails<T extends OperationTypeNames = OperationTypeNames> = {
14
14
  [P in T]: {
@@ -6,82 +6,82 @@
6
6
  * on chain and in off-chain services.
7
7
  */
8
8
 
9
- import type {
10
- AbiParameterToPrimitiveType,
11
- Address,
12
- TypedDataDomain,
13
- } from 'abitype';
14
- import type {
15
- hashStruct,
16
- isHex,
17
- recoverTypedDataAddress,
18
- RecoverTypedDataAddressParameters,
19
- validateTypedData,
20
- } from 'viem/utils';
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
21
  import {
22
22
  encodeType,
23
- type WithSignature,
24
- } from '@agoric/orchestration/src/utils/viem.ts';
23
+
24
+ } from '@agoric/orchestration/src/utils/viem.js';
25
25
  import {
26
26
  extractWitnessFieldFromTypes,
27
27
  isPermit2MessageType,
28
28
  makeWitnessTypeStringExtractor,
29
- type PermitWitnessTransferFromInputComponents,
30
- } from '@agoric/orchestration/src/utils/permit2.ts';
29
+
30
+ } from '@agoric/orchestration/src/utils/permit2.js';
31
31
  import {
32
- type OperationTypeNames,
33
- type YmaxStandaloneOperationData,
34
- type YmaxPermitWitnessTransferFromData,
35
- type YmaxOperationType,
32
+
33
+
34
+
35
+
36
36
  splitWitnessFieldType,
37
37
  validateYmaxDomain,
38
38
  validateYmaxOperationTypeName,
39
39
  getYmaxOperationTypes,
40
40
  } from './eip712-messages.ts';
41
41
 
42
- export type YmaxOperationDetails<
43
- T extends OperationTypeNames = OperationTypeNames,
44
- > = {
45
- [P in T]: {
46
- operation: P;
47
- data: YmaxOperationType<P>;
48
- };
49
- }[T];
42
+ ;
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
50
 
51
- export type PermitWitnessTransferFromPayload = AbiParameterToPrimitiveType<{
52
- type: 'tuple';
53
- components: typeof PermitWitnessTransferFromInputComponents;
54
- }>;
51
+ ;
52
+
53
+
54
+
55
55
 
56
- export type PermitDetails = {
57
- chainId: NonNullable<TypedDataDomain['chainId']>;
58
- token: Address;
59
- amount: bigint;
60
- spender: Address;
61
- permit2Payload: Omit<PermitWitnessTransferFromPayload, 'transferDetails'>;
62
- };
56
+ ;
57
+
58
+
59
+
60
+
61
+
62
+
63
63
 
64
- export type FullMessageDetails<
65
- T extends OperationTypeNames = OperationTypeNames,
66
- > = YmaxOperationDetails<T> & {
67
- permitDetails?: PermitDetails;
68
- evmWalletAddress: Address;
69
- nonce: bigint;
70
- deadline: bigint;
71
- };
64
+ ;
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
72
 
73
73
  /**
74
74
  * EVM Message handler utils that depend on 'viem' utils for their
75
75
  * implementation. Since on-chain we cannot directly import from 'viem',
76
76
  * use a maker pattern to create these utils.
77
77
  */
78
- export const makeEVMHandlerUtils = (viemUtils: {
79
- isHex: typeof isHex;
80
- hashStruct: typeof hashStruct;
81
- recoverTypedDataAddress: typeof recoverTypedDataAddress;
82
- validateTypedData: typeof validateTypedData;
83
- encodeType: typeof encodeType;
84
- }) => {
78
+ export const makeEVMHandlerUtils = (viemUtils
79
+
80
+
81
+
82
+
83
+
84
+ ) => {
85
85
  const {
86
86
  isHex,
87
87
  hashStruct,
@@ -95,21 +95,21 @@ export const makeEVMHandlerUtils = (viemUtils: {
95
95
  * @param data - The EIP-712 typed data of a standalone message
96
96
  * @returns The operation type name and associated data
97
97
  */
98
- const extractOperationDetailsFromStandaloneData = <
99
- T extends OperationTypeNames,
100
- >(
101
- data: YmaxStandaloneOperationData<T>,
102
- validContractAddresses?: Record<number | string, Address>,
103
- ): YmaxOperationDetails<T> => {
98
+ const extractOperationDetailsFromStandaloneData = (
99
+
100
+
101
+ data ,
102
+ validContractAddresses ,
103
+ ) => {
104
104
  // @ts-expect-error generic/union type compatibility
105
- const standaloneData: YmaxStandaloneOperationData = data;
105
+ const standaloneData = data;
106
106
 
107
107
  validateYmaxDomain(standaloneData.domain, validContractAddresses);
108
- validateYmaxOperationTypeName<T>(standaloneData.primaryType);
108
+ validateYmaxOperationTypeName (standaloneData.primaryType);
109
109
 
110
110
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
111
  const { nonce, deadline, ..._operationData } = standaloneData.message;
112
- const operationData = _operationData as YmaxOperationType<T>;
112
+ const operationData = _operationData ;
113
113
  const operation = standaloneData.primaryType;
114
114
  // @ts-expect-error inference issue
115
115
  validateTypedData({
@@ -126,19 +126,19 @@ export const makeEVMHandlerUtils = (viemUtils: {
126
126
  * @param data - The EIP-712 typed data of a Permit2 witness message
127
127
  * @returns The operation type name and associated data
128
128
  */
129
- const extractOperationDetailsFromPermit2WitnessData = <
130
- T extends OperationTypeNames,
131
- >(
132
- data: YmaxPermitWitnessTransferFromData<T>,
133
- ): YmaxOperationDetails<T> => {
129
+ const extractOperationDetailsFromPermit2WitnessData = (
130
+
131
+
132
+ data ,
133
+ ) => {
134
134
  // @ts-expect-error generic/union type compatibility
135
- const permitData: YmaxPermitWitnessTransferFromData = data;
135
+ const permitData = data;
136
136
 
137
137
  const witnessField = extractWitnessFieldFromTypes(permitData.types);
138
138
  const witnessData = permitData.message[
139
139
  witnessField.name
140
- ] as YmaxOperationType<T>;
141
- const operation = splitWitnessFieldType(witnessField.type).primaryType as T;
140
+ ] ;
141
+ const operation = splitWitnessFieldType(witnessField.type).primaryType ;
142
142
  // @ts-expect-error inference issue
143
143
  validateTypedData({
144
144
  types: getYmaxOperationTypes(operation),
@@ -158,16 +158,16 @@ export const makeEVMHandlerUtils = (viemUtils: {
158
158
  * @param owner address of the permit2 message signer
159
159
  * @param signature signature of the permit2 message
160
160
  */
161
- const extractPermitDetails = <T extends OperationTypeNames>(
162
- data: YmaxPermitWitnessTransferFromData<T>,
163
- owner: Address,
164
- signature: WithSignature<object>['signature'],
165
- ): PermitDetails => {
161
+ const extractPermitDetails = (
162
+ data ,
163
+ owner ,
164
+ signature ,
165
+ ) => {
166
166
  const witnessTypeStringExtractor = makeWitnessTypeStringExtractor({
167
167
  encodeType,
168
168
  });
169
169
  // @ts-expect-error generic/union type compatibility
170
- const permitData: YmaxPermitWitnessTransferFromData = data;
170
+ const permitData = data;
171
171
 
172
172
  if (!isHex(signature)) {
173
173
  throw new Error(`Invalid signature format: ${signature}`);
@@ -184,10 +184,10 @@ export const makeEVMHandlerUtils = (viemUtils: {
184
184
 
185
185
  const { spender, ...permitStruct } = permit;
186
186
 
187
- const permit2Payload: Omit<
188
- PermitWitnessTransferFromPayload,
189
- 'transferDetails'
190
- > = {
187
+ const permit2Payload
188
+
189
+
190
+ = {
191
191
  permit: permitStruct,
192
192
  owner,
193
193
  witness,
@@ -195,8 +195,8 @@ export const makeEVMHandlerUtils = (viemUtils: {
195
195
  signature,
196
196
  };
197
197
 
198
- const details: PermitDetails = {
199
- chainId: permitData.domain!.chainId!,
198
+ const details = {
199
+ chainId: permitData.domain .chainId ,
200
200
  token: permit.permitted.token,
201
201
  amount: permit.permitted.amount,
202
202
  permit2Payload,
@@ -213,26 +213,26 @@ export const makeEVMHandlerUtils = (viemUtils: {
213
213
  * @param signedData
214
214
  * @returns
215
215
  */
216
- const extractOperationDetailsFromSignedData = async <
217
- T extends OperationTypeNames = OperationTypeNames,
218
- >(
219
- signedData: WithSignature<
220
- YmaxPermitWitnessTransferFromData<T> | YmaxStandaloneOperationData<T>
221
- >,
222
- validStandaloneContractAddresses?: Record<number | string, Address>,
223
- ): Promise<FullMessageDetails<T>> => {
216
+ const extractOperationDetailsFromSignedData = async (
217
+
218
+
219
+ signedData
220
+
221
+ ,
222
+ validStandaloneContractAddresses ,
223
+ ) => {
224
224
  const tokenOwner = await recoverTypedDataAddress(
225
- signedData as RecoverTypedDataAddressParameters,
225
+ signedData ,
226
226
  );
227
227
  const { nonce, deadline } = (
228
- signedData as unknown as
229
- | YmaxPermitWitnessTransferFromData
230
- | YmaxStandaloneOperationData
228
+ signedData
229
+
230
+
231
231
  ).message;
232
232
 
233
233
  if (isPermit2MessageType(signedData.primaryType)) {
234
234
  const permit2Data =
235
- signedData as unknown as YmaxPermitWitnessTransferFromData<T>;
235
+ signedData ;
236
236
 
237
237
  const permitDetails = extractPermitDetails(
238
238
  permit2Data,
@@ -251,7 +251,7 @@ export const makeEVMHandlerUtils = (viemUtils: {
251
251
  };
252
252
  } else {
253
253
  const standaloneData =
254
- signedData as unknown as YmaxStandaloneOperationData<T>;
254
+ signedData ;
255
255
  const operationDetails = extractOperationDetailsFromStandaloneData(
256
256
  standaloneData,
257
257
  validStandaloneContractAddresses,
@@ -1,18 +1,18 @@
1
- import type { InstrumentId } from './instruments.js';
2
- import type {
3
- DepositFromChainRef,
4
- LocalChainAccountRef,
5
- InterChainAccountRef,
6
- WithdrawToChainRef,
7
- } from './types.js';
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
8
 
9
9
  /**
10
10
  * Without regard to supported chains, is the input plausibly a
11
11
  * DepositFromChainRef (i.e., does it start with `+`)?
12
12
  */
13
13
  export const isDepositFromChainRef = (
14
- ref: string,
15
- ): ref is DepositFromChainRef => ref.startsWith('+');
14
+ ref ,
15
+ ) => ref.startsWith('+');
16
16
  harden(isDepositFromChainRef);
17
17
 
18
18
  /**
@@ -20,8 +20,8 @@ harden(isDepositFromChainRef);
20
20
  * LocalChainAccountRef (i.e., does it start with `+`)?
21
21
  */
22
22
  export const isLocalChainAccountRef = (
23
- ref: string,
24
- ): ref is LocalChainAccountRef => ref.startsWith('+');
23
+ ref ,
24
+ ) => ref.startsWith('+');
25
25
  harden(isLocalChainAccountRef);
26
26
 
27
27
  /**
@@ -29,15 +29,15 @@ harden(isLocalChainAccountRef);
29
29
  * InterChainAccountRef (i.e., does it start with `@`)?
30
30
  */
31
31
  export const isInterChainAccountRef = (
32
- ref: string,
33
- ): ref is InterChainAccountRef => ref.startsWith('@');
32
+ ref ,
33
+ ) => ref.startsWith('@');
34
34
  harden(isInterChainAccountRef);
35
35
 
36
36
  /**
37
37
  * Without regard to supported chains, is the input plausibly an InstrumentId
38
38
  * (i.e., does it start with an ASCII letter)?
39
39
  */
40
- export const isInstrumentId = (ref: string): ref is InstrumentId =>
40
+ export const isInstrumentId = (ref ) =>
41
41
  !!ref.match(/^[a-z]/i);
42
42
  harden(isInstrumentId);
43
43
 
@@ -45,6 +45,6 @@ harden(isInstrumentId);
45
45
  * Without regard to supported chains, is the input plausibly a
46
46
  * WithdrawToChainRef (i.e., does it start with `-`)?
47
47
  */
48
- export const isWithdrawToChainRef = (ref: string): ref is WithdrawToChainRef =>
48
+ export const isWithdrawToChainRef = (ref ) =>
49
49
  ref.startsWith('-');
50
50
  harden(isWithdrawToChainRef);
package/src/types.js ADDED
@@ -0,0 +1,234 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars -- doesn't see type usage in JSDoc */
2
+
3
+ import {
4
+
5
+
6
+
7
+
8
+ } from '@agoric/orchestration';
9
+ ;
10
+
11
+
12
+
13
+ ;
14
+
15
+
16
+
17
+
18
+ ;
19
+ ;
20
+ ;
21
+
22
+ /**
23
+ * Feature flags to handle contract upgrade flow compatibility.
24
+ */
25
+ ;
26
+
27
+
28
+
29
+
30
+ /**
31
+ * Configuration options for flows.
32
+ */
33
+ ;
34
+
35
+
36
+ ;
37
+
38
+ /**
39
+ * Reference to a local chain accounts (LCA).
40
+ * '+agoric' is published as `depositAddress`
41
+ */
42
+ ;
43
+
44
+ /**
45
+ * Identifies the blockchain hosting an address external to ymax from which
46
+ * funds for a deposit must be supplied.
47
+ */
48
+ ;
49
+
50
+ /**
51
+ * Identifies the blockchain hosting an address external to ymax to which
52
+ * withdrawn funds will be sent.
53
+ */
54
+ ;
55
+
56
+ ;
57
+
58
+ /**
59
+ * An AssetPlaceRef describes a place where funds can be, either an
60
+ * {@link InstrumentId} (starting with an ASCII letter), a {@link SeatKeyword}
61
+ * wrapped in `<...>` angle brackets, or a value consisting of a
62
+ * single-character punctuator followed by a SupportedChain (that character
63
+ * being `@` for {@link InterChainAccountRef}, `+` for
64
+ * {@link LocalChainAccountRef} and {@link DepositFromChainRef}, and `-` for
65
+ * {@link WithdrawToChainRef}).
66
+ */
67
+ ;
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ ;
76
+
77
+ /**
78
+ * Proposal shapes for portfolio operations.
79
+ *
80
+ * **openPortfolio**: Create portfolio with initial funding across protocols
81
+ * **rebalance**: Add funds (give) or withdraw funds (want) from protocols
82
+ */
83
+ ;
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ /**
100
+ * Target allocation mapping from PoolKey to numerator (typically in basis points).
101
+ * Denominator is implicitly the sum of all numerators.
102
+ */
103
+ ;
104
+
105
+ ;
106
+
107
+
108
+ // aka simpleRebalance
109
+
110
+ /** linked list of concurrent failures, including dependencies */
111
+ ;
112
+
113
+
114
+
115
+
116
+
117
+
118
+ ;
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+ ;
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ ;
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+ /**
155
+ * Each step in the `flow` of a FundsFlowPlan can depend upon any number of
156
+ * other steps, subject to the complete directed graph being acyclic.
157
+ * The dependencies are expressed using 0-based indices.
158
+ */
159
+ ;
160
+
161
+ ;
162
+
163
+
164
+
165
+
166
+
167
+ ;
168
+
169
+
170
+
171
+ ;
172
+ ;
173
+
174
+ ;
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ /**
220
+ * Names suitable for use as `publicInvitationMaker` in {@link ContractInvitationSpec}.
221
+ */
222
+ ;
223
+
224
+ /**
225
+ * Names suitable for use as `invitationMakerName` in {@link ContinuingInvitationSpec}.
226
+ *
227
+ * These continuing invitation makers are returned from portfolio creation and enable
228
+ * ongoing operations like rebalancing between yield protocols.
229
+ */
230
+ ;
231
+
232
+
233
+
234
+
package/src/evm/types.ts DELETED
@@ -1,22 +0,0 @@
1
- export type PortfolioPath =
2
- `published.ymax${0 | 1}.portfolios.portfolio${number}`;
3
-
4
- export type EIPMessageUpdate =
5
- | {
6
- updated: 'messageUpdate';
7
- nonce: bigint;
8
- status: 'pending';
9
- }
10
- | {
11
- updated: 'messageUpdate';
12
- nonce: bigint;
13
- error: string;
14
- status: 'error';
15
- }
16
- | {
17
- updated: 'messageUpdate';
18
- nonce: bigint;
19
- status: 'ok';
20
- };
21
-
22
- export type EVMWalletUpdate = EIPMessageUpdate | never;
package/src/types.ts DELETED
@@ -1,234 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars -- doesn't see type usage in JSDoc */
2
- import type { NatAmount } from '@agoric/ertp';
3
- import {
4
- type AccountId,
5
- type Bech32Address,
6
- type CosmosChainAddress,
7
- type TrafficEntry,
8
- } from '@agoric/orchestration';
9
- import type {
10
- ContinuingInvitationSpec,
11
- ContractInvitationSpec,
12
- } from '@agoric/smart-wallet/src/invitations.js';
13
- import type {
14
- AxelarChain,
15
- SupportedChain,
16
- YieldProtocol,
17
- } from './constants.js';
18
- import type { InstrumentId } from './instruments.js';
19
- import type { PublishedTx } from './resolver.js';
20
- import type { EVMWalletUpdate, PortfolioPath } from './evm/types.ts';
21
-
22
- /**
23
- * Feature flags to handle contract upgrade flow compatibility.
24
- */
25
- export type FlowFeatures = {
26
- /** Control `ProgressTracker` support. */
27
- useProgressTracker?: boolean;
28
- };
29
-
30
- /**
31
- * Configuration options for flows.
32
- */
33
- export type FlowConfig = {
34
- features?: FlowFeatures;
35
- };
36
- export type SeatKeyword = 'Cash' | 'Deposit';
37
-
38
- /**
39
- * Reference to a local chain accounts (LCA).
40
- * '+agoric' is published as `depositAddress`
41
- */
42
- export type LocalChainAccountRef = '+agoric';
43
-
44
- /**
45
- * Identifies the blockchain hosting an address external to ymax from which
46
- * funds for a deposit must be supplied.
47
- */
48
- export type DepositFromChainRef = `+${AxelarChain}`;
49
-
50
- /**
51
- * Identifies the blockchain hosting an address external to ymax to which
52
- * withdrawn funds will be sent.
53
- */
54
- export type WithdrawToChainRef = `-${AxelarChain}`;
55
-
56
- export type InterChainAccountRef = `@${SupportedChain}`;
57
-
58
- /**
59
- * An AssetPlaceRef describes a place where funds can be, either an
60
- * {@link InstrumentId} (starting with an ASCII letter), a {@link SeatKeyword}
61
- * wrapped in `<...>` angle brackets, or a value consisting of a
62
- * single-character punctuator followed by a SupportedChain (that character
63
- * being `@` for {@link InterChainAccountRef}, `+` for
64
- * {@link LocalChainAccountRef} and {@link DepositFromChainRef}, and `-` for
65
- * {@link WithdrawToChainRef}).
66
- */
67
- export type AssetPlaceRef =
68
- | `<${SeatKeyword}>`
69
- | LocalChainAccountRef
70
- | DepositFromChainRef
71
- | WithdrawToChainRef
72
- | InterChainAccountRef
73
- | InstrumentId;
74
-
75
- type Empty = Record<never, NatAmount>;
76
-
77
- /**
78
- * Proposal shapes for portfolio operations.
79
- *
80
- * **openPortfolio**: Create portfolio with initial funding across protocols
81
- * **rebalance**: Add funds (give) or withdraw funds (want) from protocols
82
- */
83
- export type ProposalType = {
84
- openPortfolio: {
85
- give: {
86
- /** required iff the contract was started with an Access issuer */
87
- Access?: NatAmount;
88
- Deposit?: NatAmount;
89
- };
90
- want?: Empty;
91
- };
92
- rebalance:
93
- | { give: { Deposit?: NatAmount }; want: Empty }
94
- | { want: { Cash: NatAmount }; give: Empty };
95
- withdraw: { want: { Cash: NatAmount }; give: Empty };
96
- deposit: { give: { Deposit: NatAmount }; want: Empty };
97
- };
98
-
99
- /**
100
- * Target allocation mapping from PoolKey to numerator (typically in basis points).
101
- * Denominator is implicitly the sum of all numerators.
102
- */
103
- export type TargetAllocation = Partial<Record<InstrumentId, bigint>>;
104
-
105
- export type FlowDetail =
106
- | { type: 'withdraw'; amount: NatAmount; toChain?: SupportedChain }
107
- | { type: 'deposit'; amount: NatAmount; fromChain?: SupportedChain }
108
- | { type: 'rebalance' }; // aka simpleRebalance
109
-
110
- /** linked list of concurrent failures, including dependencies */
111
- export type FlowErrors = {
112
- step: number;
113
- how: string;
114
- error: string;
115
- next?: FlowErrors;
116
- };
117
-
118
- export type FlowStatus =
119
- | {
120
- state: 'run';
121
- /** minimum currently running step */
122
- step: number;
123
- how: string;
124
- /** currently running steps, when executing concurrently */
125
- steps?: number[];
126
- }
127
- /** @deprecated - contract no longer does automatic recovery */
128
- | { state: 'undo'; step: number; how: string }
129
- | { state: 'done' }
130
- | ({ state: 'fail' } & FlowErrors);
131
-
132
- export type MovementDesc = {
133
- amount: NatAmount;
134
- src: AssetPlaceRef;
135
- dest: AssetPlaceRef;
136
- /** for example: GMP fee */
137
- fee?: NatAmount;
138
- /** for example: { usdnOut: 98n } */
139
- detail?: Record<string, bigint>;
140
- claim?: boolean;
141
- };
142
-
143
- export type FlowStep = {
144
- /** Human readable description of how the step accomplishes the transfer from `src` to `dest` */
145
- // Distinct from `Way.how` in the contract
146
- how: string;
147
- amount: NatAmount;
148
- src: AssetPlaceRef;
149
- dest: AssetPlaceRef;
150
- phases?: Record<string, any>;
151
- // XXX all parts: fee etc.
152
- };
153
-
154
- /**
155
- * Each step in the `flow` of a FundsFlowPlan can depend upon any number of
156
- * other steps, subject to the complete directed graph being acyclic.
157
- * The dependencies are expressed using 0-based indices.
158
- */
159
- type FlowStepDependency = [stepIndex: number, prerequisiteIndexes: number[]];
160
-
161
- export type FundsFlowPlan = {
162
- flow: MovementDesc[];
163
- /** When `order` is absent, default to fully sequential dependencies. */
164
- order?: FlowStepDependency[];
165
- };
166
-
167
- export type TrafficReport = {
168
- traffic: TrafficEntry[];
169
- };
170
-
171
- export type PortfolioKey = `portfolio${number}`;
172
- export type FlowKey = `flow${number}`;
173
-
174
- export type StatusFor = {
175
- contract: {
176
- contractAccount: CosmosChainAddress['value'];
177
- depositFactoryAddresses?: Record<AxelarChain, AccountId>;
178
- };
179
- pendingTx: PublishedTx;
180
- evmWallet: EVMWalletUpdate;
181
- evmWalletPortfolios: PortfolioPath[];
182
- portfolios: {
183
- addPortfolio: PortfolioKey;
184
- };
185
- portfolio: {
186
- positionKeys: InstrumentId[];
187
- accountIdByChain: Partial<Record<SupportedChain, AccountId>>;
188
- accountsPending?: SupportedChain[];
189
- depositAddress?: Bech32Address;
190
- /** Noble Forwarding Address (NFA) registered by the contract for the `@agoric` address */
191
- nobleForwardingAddress?: Bech32Address;
192
- targetAllocation?: TargetAllocation;
193
- /**
194
- * CAIP-10 account ID of the authenticated EVM account that opened this portfolio.
195
- * Derived from `permit2Payload.owner` in `openPortfolioFromEVM()`.
196
- * The Permit2 signature is verified on-chain by the `depositFactory` contract
197
- * when it receives the GMP call via `sendCreateAndDepositCall()`.
198
- */
199
- sourceAccountId?: AccountId;
200
- /** incremented by the contract every time the user sends a transaction that the planner should respond to */
201
- policyVersion: number;
202
- /** the count of acknowledged submissions [from the planner] associated with the current policyVersion */
203
- rebalanceCount: number;
204
- /** @deprecated in favor of flowsRunning */
205
- flowCount: number;
206
- flowsRunning?: Record<FlowKey, FlowDetail>;
207
- };
208
- position: {
209
- protocol: YieldProtocol;
210
- accountId: AccountId;
211
- totalIn: NatAmount;
212
- totalOut: NatAmount;
213
- };
214
- flow: FlowStatus & FlowDetail;
215
- flowSteps: FlowStep[];
216
- flowOrder: FundsFlowPlan['order'];
217
- };
218
-
219
- /**
220
- * Names suitable for use as `publicInvitationMaker` in {@link ContractInvitationSpec}.
221
- */
222
- export type PortfolioPublicInvitationMaker = 'makeOpenPortfolioInvitation';
223
-
224
- /**
225
- * Names suitable for use as `invitationMakerName` in {@link ContinuingInvitationSpec}.
226
- *
227
- * These continuing invitation makers are returned from portfolio creation and enable
228
- * ongoing operations like rebalancing between yield protocols.
229
- */
230
- export type PortfolioContinuingInvitationMaker =
231
- | 'Deposit'
232
- | 'Withdraw'
233
- | 'Rebalance'
234
- | 'SimpleRebalance';