@chainlink/cre-sdk 1.6.0-alpha.4 → 1.6.0-alpha.5

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.
Files changed (36) hide show
  1. package/README.md +9 -0
  2. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1023 -0
  3. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
  4. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2904 -0
  5. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +506 -0
  6. package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
  7. package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
  8. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
  9. package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
  10. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
  11. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
  12. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +52 -0
  13. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +186 -0
  14. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +92 -0
  15. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +343 -0
  16. package/dist/sdk/cre/index.d.ts +6 -0
  17. package/dist/sdk/cre/index.js +8 -0
  18. package/dist/sdk/impl/runtime-impl.d.ts +8 -0
  19. package/dist/sdk/impl/runtime-impl.js +15 -1
  20. package/dist/sdk/runtime.d.ts +3 -1
  21. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
  22. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
  23. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +33 -0
  24. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +178 -0
  25. package/dist/sdk/test/generated/index.d.ts +2 -0
  26. package/dist/sdk/test/generated/index.js +2 -0
  27. package/dist/sdk/testutils/test-runtime.d.ts +2 -0
  28. package/dist/sdk/testutils/test-runtime.js +7 -0
  29. package/dist/sdk/testutils/test-writer.d.ts +7 -1
  30. package/dist/sdk/testutils/test-writer.js +13 -1
  31. package/dist/sdk/types/global.d.ts +8 -0
  32. package/dist/sdk/wasm/host-bindings.d.ts +1 -0
  33. package/dist/sdk/wasm/host-bindings.js +4 -0
  34. package/dist/sdk/wasm/runtime.js +3 -0
  35. package/package.json +2 -2
  36. package/scripts/src/generate-sdks.ts +12 -0
@@ -0,0 +1,343 @@
1
+ import { create, fromJson } from '@bufbuild/protobuf';
2
+ import { AnySchema, anyPack } from '@bufbuild/protobuf/wkt';
3
+ import { AccountMetaSchema, ComputeConfigSchema, FilterLogTriggerRequestSchema, GetAccountInfoWithOptsReplySchema, GetAccountInfoWithOptsRequestSchema, GetBalanceReplySchema, GetBalanceRequestSchema, GetBlockReplySchema, GetBlockRequestSchema, GetFeeForMessageReplySchema, GetFeeForMessageRequestSchema, GetMultipleAccountsWithOptsReplySchema, GetMultipleAccountsWithOptsRequestSchema, GetSignatureStatusesReplySchema, GetSignatureStatusesRequestSchema, GetSlotHeightReplySchema, GetSlotHeightRequestSchema, GetTransactionReplySchema, GetTransactionRequestSchema, LogSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
4
+ import { ReportResponseSchema, } from '../../../../../generated/sdk/v1alpha/sdk_pb';
5
+ import { Report } from '../../../../../sdk/report';
6
+ import { hexToBytes } from '../../../../../sdk/utils/hex-utils';
7
+ export function x_generatedCodeOnly_wrap_WriteCreReportRequest(input) {
8
+ return {
9
+ remainingAccounts: input.remainingAccounts,
10
+ receiver: input.receiver,
11
+ computeConfig: input.computeConfig,
12
+ report: input.report !== undefined ? new Report(input.report) : undefined,
13
+ $report: true,
14
+ };
15
+ }
16
+ export function createWriteCreReportRequest(input) {
17
+ return {
18
+ remainingAccounts: (input.remainingAccounts ?? []).map((v) => fromJson(AccountMetaSchema, v)),
19
+ receiver: hexToBytes(input.receiver),
20
+ computeConfig: input.computeConfig !== undefined
21
+ ? fromJson(ComputeConfigSchema, input.computeConfig)
22
+ : undefined,
23
+ report: input.report,
24
+ $report: true,
25
+ };
26
+ }
27
+ export function x_generatedCodeOnly_unwrap_WriteCreReportRequest(input) {
28
+ return create(WriteReportRequestSchema, {
29
+ remainingAccounts: input.remainingAccounts,
30
+ receiver: input.receiver,
31
+ computeConfig: input.computeConfig,
32
+ report: input.report !== undefined ? input.report.x_generatedCodeOnly_unwrap() : undefined,
33
+ });
34
+ }
35
+ /**
36
+ * Client Capability
37
+ *
38
+ * Capability ID: solana@1.0.0
39
+ * Capability Name: solana
40
+ * Capability Version: 1.0.0
41
+ */
42
+ export class ClientCapability {
43
+ ChainSelector;
44
+ /** The capability ID for this service */
45
+ static CAPABILITY_ID = 'solana@1.0.0';
46
+ static CAPABILITY_NAME = 'solana';
47
+ static CAPABILITY_VERSION = '1.0.0';
48
+ /** Available ChainSelector values */
49
+ static SUPPORTED_CHAIN_SELECTORS = {
50
+ 'solana-devnet': 16423721717087811551n,
51
+ 'solana-mainnet': 124615329519749607n,
52
+ 'solana-testnet': 6302590918974934319n,
53
+ };
54
+ constructor(ChainSelector) {
55
+ this.ChainSelector = ChainSelector;
56
+ }
57
+ getAccountInfoWithOpts(runtime, input) {
58
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
59
+ let payload;
60
+ if (input.$typeName) {
61
+ // It's the original protobuf type
62
+ payload = input;
63
+ }
64
+ else {
65
+ // It's regular JSON, convert using fromJson
66
+ payload = fromJson(GetAccountInfoWithOptsRequestSchema, input);
67
+ }
68
+ // Include all labels in capability ID for routing when specified
69
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
70
+ const capabilityResponse = runtime.callCapability({
71
+ capabilityId,
72
+ method: 'GetAccountInfoWithOpts',
73
+ payload,
74
+ inputSchema: GetAccountInfoWithOptsRequestSchema,
75
+ outputSchema: GetAccountInfoWithOptsReplySchema,
76
+ });
77
+ return {
78
+ result: () => {
79
+ const result = capabilityResponse.result();
80
+ return result;
81
+ },
82
+ };
83
+ }
84
+ getBalance(runtime, input) {
85
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
86
+ let payload;
87
+ if (input.$typeName) {
88
+ // It's the original protobuf type
89
+ payload = input;
90
+ }
91
+ else {
92
+ // It's regular JSON, convert using fromJson
93
+ payload = fromJson(GetBalanceRequestSchema, input);
94
+ }
95
+ // Include all labels in capability ID for routing when specified
96
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
97
+ const capabilityResponse = runtime.callCapability({
98
+ capabilityId,
99
+ method: 'GetBalance',
100
+ payload,
101
+ inputSchema: GetBalanceRequestSchema,
102
+ outputSchema: GetBalanceReplySchema,
103
+ });
104
+ return {
105
+ result: () => {
106
+ const result = capabilityResponse.result();
107
+ return result;
108
+ },
109
+ };
110
+ }
111
+ getBlock(runtime, input) {
112
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
113
+ let payload;
114
+ if (input.$typeName) {
115
+ // It's the original protobuf type
116
+ payload = input;
117
+ }
118
+ else {
119
+ // It's regular JSON, convert using fromJson
120
+ payload = fromJson(GetBlockRequestSchema, input);
121
+ }
122
+ // Include all labels in capability ID for routing when specified
123
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
124
+ const capabilityResponse = runtime.callCapability({
125
+ capabilityId,
126
+ method: 'GetBlock',
127
+ payload,
128
+ inputSchema: GetBlockRequestSchema,
129
+ outputSchema: GetBlockReplySchema,
130
+ });
131
+ return {
132
+ result: () => {
133
+ const result = capabilityResponse.result();
134
+ return result;
135
+ },
136
+ };
137
+ }
138
+ getFeeForMessage(runtime, input) {
139
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
140
+ let payload;
141
+ if (input.$typeName) {
142
+ // It's the original protobuf type
143
+ payload = input;
144
+ }
145
+ else {
146
+ // It's regular JSON, convert using fromJson
147
+ payload = fromJson(GetFeeForMessageRequestSchema, input);
148
+ }
149
+ // Include all labels in capability ID for routing when specified
150
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
151
+ const capabilityResponse = runtime.callCapability({
152
+ capabilityId,
153
+ method: 'GetFeeForMessage',
154
+ payload,
155
+ inputSchema: GetFeeForMessageRequestSchema,
156
+ outputSchema: GetFeeForMessageReplySchema,
157
+ });
158
+ return {
159
+ result: () => {
160
+ const result = capabilityResponse.result();
161
+ return result;
162
+ },
163
+ };
164
+ }
165
+ getMultipleAccountsWithOpts(runtime, input) {
166
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
167
+ let payload;
168
+ if (input.$typeName) {
169
+ // It's the original protobuf type
170
+ payload = input;
171
+ }
172
+ else {
173
+ // It's regular JSON, convert using fromJson
174
+ payload = fromJson(GetMultipleAccountsWithOptsRequestSchema, input);
175
+ }
176
+ // Include all labels in capability ID for routing when specified
177
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
178
+ const capabilityResponse = runtime.callCapability({
179
+ capabilityId,
180
+ method: 'GetMultipleAccountsWithOpts',
181
+ payload,
182
+ inputSchema: GetMultipleAccountsWithOptsRequestSchema,
183
+ outputSchema: GetMultipleAccountsWithOptsReplySchema,
184
+ });
185
+ return {
186
+ result: () => {
187
+ const result = capabilityResponse.result();
188
+ return result;
189
+ },
190
+ };
191
+ }
192
+ getSignatureStatuses(runtime, input) {
193
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
194
+ let payload;
195
+ if (input.$typeName) {
196
+ // It's the original protobuf type
197
+ payload = input;
198
+ }
199
+ else {
200
+ // It's regular JSON, convert using fromJson
201
+ payload = fromJson(GetSignatureStatusesRequestSchema, input);
202
+ }
203
+ // Include all labels in capability ID for routing when specified
204
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
205
+ const capabilityResponse = runtime.callCapability({
206
+ capabilityId,
207
+ method: 'GetSignatureStatuses',
208
+ payload,
209
+ inputSchema: GetSignatureStatusesRequestSchema,
210
+ outputSchema: GetSignatureStatusesReplySchema,
211
+ });
212
+ return {
213
+ result: () => {
214
+ const result = capabilityResponse.result();
215
+ return result;
216
+ },
217
+ };
218
+ }
219
+ getSlotHeight(runtime, input) {
220
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
221
+ let payload;
222
+ if (input.$typeName) {
223
+ // It's the original protobuf type
224
+ payload = input;
225
+ }
226
+ else {
227
+ // It's regular JSON, convert using fromJson
228
+ payload = fromJson(GetSlotHeightRequestSchema, input);
229
+ }
230
+ // Include all labels in capability ID for routing when specified
231
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
232
+ const capabilityResponse = runtime.callCapability({
233
+ capabilityId,
234
+ method: 'GetSlotHeight',
235
+ payload,
236
+ inputSchema: GetSlotHeightRequestSchema,
237
+ outputSchema: GetSlotHeightReplySchema,
238
+ });
239
+ return {
240
+ result: () => {
241
+ const result = capabilityResponse.result();
242
+ return result;
243
+ },
244
+ };
245
+ }
246
+ getTransaction(runtime, input) {
247
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
248
+ let payload;
249
+ if (input.$typeName) {
250
+ // It's the original protobuf type
251
+ payload = input;
252
+ }
253
+ else {
254
+ // It's regular JSON, convert using fromJson
255
+ payload = fromJson(GetTransactionRequestSchema, input);
256
+ }
257
+ // Include all labels in capability ID for routing when specified
258
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
259
+ const capabilityResponse = runtime.callCapability({
260
+ capabilityId,
261
+ method: 'GetTransaction',
262
+ payload,
263
+ inputSchema: GetTransactionRequestSchema,
264
+ outputSchema: GetTransactionReplySchema,
265
+ });
266
+ return {
267
+ result: () => {
268
+ const result = capabilityResponse.result();
269
+ return result;
270
+ },
271
+ };
272
+ }
273
+ logTrigger(config) {
274
+ // Include all labels in capability ID for routing when specified
275
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
276
+ return new ClientLogTrigger(config, capabilityId, 'LogTrigger', this.ChainSelector);
277
+ }
278
+ writeReport(runtime, input) {
279
+ // Handle input conversion - unwrap if it's a wrapped type, convert from JSON if needed
280
+ let payload;
281
+ // Check if it's a wrapped type by looking for the $report property
282
+ if (input.$report) {
283
+ // It's a wrapped type, unwrap it
284
+ payload = x_generatedCodeOnly_unwrap_WriteCreReportRequest(input);
285
+ }
286
+ else {
287
+ // It's wrapped JSON, convert using create function
288
+ payload = x_generatedCodeOnly_unwrap_WriteCreReportRequest(createWriteCreReportRequest(input));
289
+ }
290
+ // Include all labels in capability ID for routing when specified
291
+ const capabilityId = `${ClientCapability.CAPABILITY_NAME}:ChainSelector:${this.ChainSelector}@${ClientCapability.CAPABILITY_VERSION}`;
292
+ const capabilityResponse = runtime.callCapability({
293
+ capabilityId,
294
+ method: 'WriteReport',
295
+ payload,
296
+ inputSchema: WriteReportRequestSchema,
297
+ outputSchema: WriteReportReplySchema,
298
+ });
299
+ return {
300
+ result: () => {
301
+ const result = capabilityResponse.result();
302
+ return result;
303
+ },
304
+ };
305
+ }
306
+ }
307
+ /**
308
+ * Trigger implementation for LogTrigger
309
+ */
310
+ class ClientLogTrigger {
311
+ _capabilityId;
312
+ _method;
313
+ ChainSelector;
314
+ config;
315
+ constructor(config, _capabilityId, _method, ChainSelector) {
316
+ this._capabilityId = _capabilityId;
317
+ this._method = _method;
318
+ this.ChainSelector = ChainSelector;
319
+ // biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages
320
+ this.config = config.$typeName
321
+ ? config
322
+ : fromJson(FilterLogTriggerRequestSchema, config);
323
+ }
324
+ capabilityId() {
325
+ return this._capabilityId;
326
+ }
327
+ method() {
328
+ return this._method;
329
+ }
330
+ outputSchema() {
331
+ return LogSchema;
332
+ }
333
+ configAsAny() {
334
+ return anyPack(FilterLogTriggerRequestSchema, this.config);
335
+ }
336
+ /**
337
+ * Transform the raw trigger output - override this method if needed
338
+ * Default implementation returns the raw output unchanged
339
+ */
340
+ adapt(rawOutput) {
341
+ return rawOutput;
342
+ }
343
+ }
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Public API for the CRE SDK.
3
3
  */
4
+ import { ClientCapability as AptosClient } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
4
5
  import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
6
+ import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
5
7
  import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
6
8
  import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
7
9
  import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
@@ -12,7 +14,9 @@ import { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/
12
14
  export { type Log as EVMLog, TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
13
15
  export type { Payload as HTTPPayload } from '../../generated/capabilities/networking/http/v1alpha/trigger_pb';
14
16
  export type { Payload as CronPayload } from '../../generated/capabilities/scheduler/cron/v1/trigger_pb';
17
+ export { ClientCapability as AptosClient, type WriteCreReportRequest as AptosWriteCreReportRequest, type WriteCreReportRequestJson as AptosWriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
15
18
  export { ClientCapability as EVMClient, type WriteCreReportRequest, type WriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
19
+ export { ClientCapability as SolanaClient, type WriteCreReportRequest as SolanaWriteCreReportRequest, type WriteCreReportRequestJson as SolanaWriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
16
20
  export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
17
21
  export { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
18
22
  export { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
@@ -26,6 +30,8 @@ export declare const cre: {
26
30
  ConfidentialHTTPClient: typeof ConfidentialHTTPClient;
27
31
  HTTPClient: typeof HTTPClient;
28
32
  EVMClient: typeof EVMClient;
33
+ AptosClient: typeof AptosClient;
34
+ SolanaClient: typeof SolanaClient;
29
35
  };
30
36
  handler: <TRawTriggerOutput extends import("@bufbuild/protobuf").Message<string>, TTriggerOutput, TConfig, TResult>(trigger: import("../utils/triggers/trigger-interface").Trigger<TRawTriggerOutput, TTriggerOutput>, fn: import("../workflow").HandlerFn<TConfig, TTriggerOutput, TResult>) => import("../workflow").HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult>;
31
37
  };
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Public API for the CRE SDK.
3
3
  */
4
+ import { ClientCapability as AptosClient } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
4
5
  import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
6
+ import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
5
7
  import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
6
8
  import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
7
9
  import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
@@ -12,8 +14,12 @@ import { handler } from '../workflow';
12
14
  * Public exports for the CRE SDK.
13
15
  */
14
16
  export { TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
17
+ // Aptos Capability
18
+ export { ClientCapability as AptosClient, } from '../../generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen';
15
19
  // EVM Capability
16
20
  export { ClientCapability as EVMClient, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
21
+ // Solana Capability
22
+ export { ClientCapability as SolanaClient, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
17
23
  // Confidential HTTP Capability
18
24
  export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
19
25
  // HTTP Capability
@@ -30,6 +36,8 @@ export const cre = {
30
36
  ConfidentialHTTPClient,
31
37
  HTTPClient,
32
38
  EVMClient,
39
+ AptosClient,
40
+ SolanaClient,
33
41
  },
34
42
  handler,
35
43
  };
@@ -43,7 +43,10 @@ export declare class BaseRuntimeImpl<C> implements BaseRuntime<C> {
43
43
  getNextCallId(): number;
44
44
  now(): Date;
45
45
  log(message: string): void;
46
+ emitMetric(name: string, value: number, type: MetricType, labels?: Record<string, string>): boolean;
46
47
  }
48
+ /** Ergonomic union for {@link BaseRuntimeImpl.emitMetric}. */
49
+ export type MetricType = 'counter' | 'gauge';
47
50
  /**
48
51
  * It is used when a BFT guarantee cannot be provided automatically (e.g. calling a standard API).
49
52
  * You tell each node to perform a task on its own.
@@ -112,4 +115,9 @@ export interface RuntimeHelpers {
112
115
  now(): number;
113
116
  /** Logs a message to the host environment. */
114
117
  log(message: string): void;
118
+ /**
119
+ * Emits a user metric to the host. Payload is a protobuf-encoded
120
+ * `workflows.v2.WorkflowUserMetric`. Returns false if the host rejected it.
121
+ */
122
+ emitMetric(payload: Uint8Array): boolean;
115
123
  }
@@ -1,6 +1,7 @@
1
- import { create } from '@bufbuild/protobuf';
1
+ import { create, toBinary } from '@bufbuild/protobuf';
2
2
  import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
3
  import { AwaitCapabilitiesRequestSchema, AwaitSecretsRequestSchema, CapabilityRequestSchema, GetSecretsRequestSchema, Mode, SecretRequestSchema, SimpleConsensusInputsSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
4
+ import { UserMetricType, WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
4
5
  import { ConsensusCapability } from '../../generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen';
5
6
  import { Value, } from '../utils';
6
7
  import { CapabilityError } from '../utils/capabilities/capability-error';
@@ -139,7 +140,20 @@ export class BaseRuntimeImpl {
139
140
  log(message) {
140
141
  this.helpers.log(message);
141
142
  }
143
+ emitMetric(name, value, type, labels) {
144
+ const metric = create(WorkflowUserMetricSchema, {
145
+ name,
146
+ value,
147
+ type: METRIC_TYPE_TO_PROTO[type],
148
+ labels: labels ?? {},
149
+ });
150
+ return this.helpers.emitMetric(toBinary(WorkflowUserMetricSchema, metric));
151
+ }
142
152
  }
153
+ const METRIC_TYPE_TO_PROTO = {
154
+ counter: UserMetricType.COUNTER,
155
+ gauge: UserMetricType.GAUGE,
156
+ };
143
157
  /**
144
158
  * It is used when a BFT guarantee cannot be provided automatically (e.g. calling a standard API).
145
159
  * You tell each node to perform a task on its own.
@@ -1,10 +1,11 @@
1
1
  import type { Message } from '@bufbuild/protobuf';
2
2
  import type { GenMessage } from '@bufbuild/protobuf/codegenv2';
3
3
  import type { ReportRequest, ReportRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
4
+ import type { MetricType } from './impl/runtime-impl';
4
5
  import type { Report } from './report';
5
6
  import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from './utils';
6
7
  import type { SecretsProvider } from '.';
7
- export type { ReportRequest, ReportRequestJson };
8
+ export type { ReportRequest, ReportRequestJson, MetricType };
8
9
  export type CallCapabilityParams<I extends Message, O extends Message> = {
9
10
  capabilityId: string;
10
11
  method: string;
@@ -23,6 +24,7 @@ export interface BaseRuntime<C> {
23
24
  };
24
25
  now(): Date;
25
26
  log(message: string): void;
27
+ emitMetric(name: string, value: number, type: MetricType, labels?: Record<string, string>): boolean;
26
28
  }
27
29
  /**
28
30
  * Runtime for Node mode execution.
@@ -0,0 +1,25 @@
1
+ import { type AccountAPTBalanceReply, type AccountAPTBalanceReplyJson, type AccountAPTBalanceRequest, type AccountTransactionsReply, type AccountTransactionsReplyJson, type AccountTransactionsRequest, type TransactionByHashReply, type TransactionByHashReplyJson, type TransactionByHashRequest, type ViewReply, type ViewReplyJson, type ViewRequest, type WriteReportReply, type WriteReportReplyJson, type WriteReportRequest } from '../../../../../../../generated/capabilities/blockchain/aptos/v1alpha/client_pb';
2
+ /**
3
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
4
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
+ */
6
+ export declare class AptosMock {
7
+ static readonly CAPABILITY_ID = "aptos@1.0.0";
8
+ /** Set to define the return value for AccountAPTBalance. May return a plain object (AccountAPTBalanceReplyJson) or the message type. */
9
+ accountAPTBalance?: (input: AccountAPTBalanceRequest) => AccountAPTBalanceReply | AccountAPTBalanceReplyJson;
10
+ /** Set to define the return value for View. May return a plain object (ViewReplyJson) or the message type. */
11
+ view?: (input: ViewRequest) => ViewReply | ViewReplyJson;
12
+ /** Set to define the return value for TransactionByHash. May return a plain object (TransactionByHashReplyJson) or the message type. */
13
+ transactionByHash?: (input: TransactionByHashRequest) => TransactionByHashReply | TransactionByHashReplyJson;
14
+ /** Set to define the return value for AccountTransactions. May return a plain object (AccountTransactionsReplyJson) or the message type. */
15
+ accountTransactions?: (input: AccountTransactionsRequest) => AccountTransactionsReply | AccountTransactionsReplyJson;
16
+ /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
17
+ writeReport?: (input: WriteReportRequest) => WriteReportReply | WriteReportReplyJson;
18
+ private constructor();
19
+ /**
20
+ * Returns the mock instance for this capability and the specified tags.
21
+ * Multiple calls with the same tag values return the same instance.
22
+ * Must be called within the test framework's test() method.
23
+ */
24
+ static testInstance(chainSelector: bigint): AptosMock;
25
+ }
@@ -0,0 +1,111 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { AccountAPTBalanceReplySchema, AccountAPTBalanceRequestSchema, AccountTransactionsReplySchema, AccountTransactionsRequestSchema, TransactionByHashReplySchema, TransactionByHashRequestSchema, ViewReplySchema, ViewRequestSchema, WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/aptos/v1alpha/client_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class AptosMock {
10
+ static CAPABILITY_ID = 'aptos@1.0.0';
11
+ /** Set to define the return value for AccountAPTBalance. May return a plain object (AccountAPTBalanceReplyJson) or the message type. */
12
+ accountAPTBalance;
13
+ /** Set to define the return value for View. May return a plain object (ViewReplyJson) or the message type. */
14
+ view;
15
+ /** Set to define the return value for TransactionByHash. May return a plain object (TransactionByHashReplyJson) or the message type. */
16
+ transactionByHash;
17
+ /** Set to define the return value for AccountTransactions. May return a plain object (AccountTransactionsReplyJson) or the message type. */
18
+ accountTransactions;
19
+ /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
20
+ writeReport;
21
+ constructor(chainSelector) {
22
+ const self = this;
23
+ const qualifiedId = `aptos:ChainSelector:${chainSelector}@1.0.0`;
24
+ try {
25
+ registerTestCapability(qualifiedId, (req) => {
26
+ switch (req.method) {
27
+ case 'AccountAPTBalance': {
28
+ const input = anyUnpack(req.payload, AccountAPTBalanceRequestSchema);
29
+ const handler = self.accountAPTBalance;
30
+ if (typeof handler !== 'function')
31
+ throw new Error("AccountAPTBalance: no implementation provided; set the mock's accountAPTBalance property to define the return value.");
32
+ const raw = handler(input);
33
+ const output = raw && typeof raw.$typeName === 'string'
34
+ ? raw
35
+ : fromJson(AccountAPTBalanceReplySchema, raw);
36
+ return {
37
+ response: { case: 'payload', value: anyPack(AccountAPTBalanceReplySchema, output) },
38
+ };
39
+ }
40
+ case 'View': {
41
+ const input = anyUnpack(req.payload, ViewRequestSchema);
42
+ const handler = self.view;
43
+ if (typeof handler !== 'function')
44
+ throw new Error("View: no implementation provided; set the mock's view property to define the return value.");
45
+ const raw = handler(input);
46
+ const output = raw && typeof raw.$typeName === 'string'
47
+ ? raw
48
+ : fromJson(ViewReplySchema, raw);
49
+ return { response: { case: 'payload', value: anyPack(ViewReplySchema, output) } };
50
+ }
51
+ case 'TransactionByHash': {
52
+ const input = anyUnpack(req.payload, TransactionByHashRequestSchema);
53
+ const handler = self.transactionByHash;
54
+ if (typeof handler !== 'function')
55
+ throw new Error("TransactionByHash: no implementation provided; set the mock's transactionByHash property to define the return value.");
56
+ const raw = handler(input);
57
+ const output = raw && typeof raw.$typeName === 'string'
58
+ ? raw
59
+ : fromJson(TransactionByHashReplySchema, raw);
60
+ return {
61
+ response: { case: 'payload', value: anyPack(TransactionByHashReplySchema, output) },
62
+ };
63
+ }
64
+ case 'AccountTransactions': {
65
+ const input = anyUnpack(req.payload, AccountTransactionsRequestSchema);
66
+ const handler = self.accountTransactions;
67
+ if (typeof handler !== 'function')
68
+ throw new Error("AccountTransactions: no implementation provided; set the mock's accountTransactions property to define the return value.");
69
+ const raw = handler(input);
70
+ const output = raw && typeof raw.$typeName === 'string'
71
+ ? raw
72
+ : fromJson(AccountTransactionsReplySchema, raw);
73
+ return {
74
+ response: { case: 'payload', value: anyPack(AccountTransactionsReplySchema, output) },
75
+ };
76
+ }
77
+ case 'WriteReport': {
78
+ const input = anyUnpack(req.payload, WriteReportRequestSchema);
79
+ const handler = self.writeReport;
80
+ if (typeof handler !== 'function')
81
+ throw new Error("WriteReport: no implementation provided; set the mock's writeReport property to define the return value.");
82
+ const raw = handler(input);
83
+ const output = raw && typeof raw.$typeName === 'string'
84
+ ? raw
85
+ : fromJson(WriteReportReplySchema, raw);
86
+ return { response: { case: 'payload', value: anyPack(WriteReportReplySchema, output) } };
87
+ }
88
+ default:
89
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
90
+ }
91
+ });
92
+ }
93
+ catch {
94
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
95
+ }
96
+ }
97
+ /**
98
+ * Returns the mock instance for this capability and the specified tags.
99
+ * Multiple calls with the same tag values return the same instance.
100
+ * Must be called within the test framework's test() method.
101
+ */
102
+ static testInstance(chainSelector) {
103
+ const qualifiedId = `aptos:ChainSelector:${chainSelector}@1.0.0`;
104
+ let instance = __getTestMockInstance(qualifiedId);
105
+ if (!instance) {
106
+ instance = new AptosMock(chainSelector);
107
+ __setTestMockInstance(qualifiedId, instance);
108
+ }
109
+ return instance;
110
+ }
111
+ }
@@ -0,0 +1,33 @@
1
+ import { type GetAccountInfoWithOptsReply, type GetAccountInfoWithOptsReplyJson, type GetAccountInfoWithOptsRequest, type GetBalanceReply, type GetBalanceReplyJson, type GetBalanceRequest, type GetBlockReply, type GetBlockReplyJson, type GetBlockRequest, type GetFeeForMessageReply, type GetFeeForMessageReplyJson, type GetFeeForMessageRequest, type GetMultipleAccountsWithOptsReply, type GetMultipleAccountsWithOptsReplyJson, type GetMultipleAccountsWithOptsRequest, type GetSignatureStatusesReply, type GetSignatureStatusesReplyJson, type GetSignatureStatusesRequest, type GetSlotHeightReply, type GetSlotHeightReplyJson, type GetSlotHeightRequest, type GetTransactionReply, type GetTransactionReplyJson, type GetTransactionRequest, type WriteReportReply, type WriteReportReplyJson, type WriteReportRequest } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
2
+ /**
3
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
4
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
+ */
6
+ export declare class SolanaMock {
7
+ static readonly CAPABILITY_ID = "solana@1.0.0";
8
+ /** Set to define the return value for GetAccountInfoWithOpts. May return a plain object (GetAccountInfoWithOptsReplyJson) or the message type. */
9
+ getAccountInfoWithOpts?: (input: GetAccountInfoWithOptsRequest) => GetAccountInfoWithOptsReply | GetAccountInfoWithOptsReplyJson;
10
+ /** Set to define the return value for GetBalance. May return a plain object (GetBalanceReplyJson) or the message type. */
11
+ getBalance?: (input: GetBalanceRequest) => GetBalanceReply | GetBalanceReplyJson;
12
+ /** Set to define the return value for GetBlock. May return a plain object (GetBlockReplyJson) or the message type. */
13
+ getBlock?: (input: GetBlockRequest) => GetBlockReply | GetBlockReplyJson;
14
+ /** Set to define the return value for GetFeeForMessage. May return a plain object (GetFeeForMessageReplyJson) or the message type. */
15
+ getFeeForMessage?: (input: GetFeeForMessageRequest) => GetFeeForMessageReply | GetFeeForMessageReplyJson;
16
+ /** Set to define the return value for GetMultipleAccountsWithOpts. May return a plain object (GetMultipleAccountsWithOptsReplyJson) or the message type. */
17
+ getMultipleAccountsWithOpts?: (input: GetMultipleAccountsWithOptsRequest) => GetMultipleAccountsWithOptsReply | GetMultipleAccountsWithOptsReplyJson;
18
+ /** Set to define the return value for GetSignatureStatuses. May return a plain object (GetSignatureStatusesReplyJson) or the message type. */
19
+ getSignatureStatuses?: (input: GetSignatureStatusesRequest) => GetSignatureStatusesReply | GetSignatureStatusesReplyJson;
20
+ /** Set to define the return value for GetSlotHeight. May return a plain object (GetSlotHeightReplyJson) or the message type. */
21
+ getSlotHeight?: (input: GetSlotHeightRequest) => GetSlotHeightReply | GetSlotHeightReplyJson;
22
+ /** Set to define the return value for GetTransaction. May return a plain object (GetTransactionReplyJson) or the message type. */
23
+ getTransaction?: (input: GetTransactionRequest) => GetTransactionReply | GetTransactionReplyJson;
24
+ /** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
25
+ writeReport?: (input: WriteReportRequest) => WriteReportReply | WriteReportReplyJson;
26
+ private constructor();
27
+ /**
28
+ * Returns the mock instance for this capability and the specified tags.
29
+ * Multiple calls with the same tag values return the same instance.
30
+ * Must be called within the test framework's test() method.
31
+ */
32
+ static testInstance(chainSelector: bigint): SolanaMock;
33
+ }