@mimicprotocol/test-ts 0.0.1-rc.9 → 0.0.1
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/CHANGELOG.md +134 -0
- package/README.md +21 -22
- package/dist/RunnerMock.d.ts +6 -1
- package/dist/RunnerMock.js +80 -26
- package/dist/RunnerMock.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/processors/evm-call.d.ts +3 -0
- package/dist/processors/evm-call.js +24 -0
- package/dist/processors/evm-call.js.map +1 -0
- package/dist/processors/index.d.ts +4 -0
- package/dist/processors/index.js +21 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/price.d.ts +3 -0
- package/dist/processors/price.js +16 -0
- package/dist/processors/price.js.map +1 -0
- package/dist/processors/relevant-tokens.d.ts +3 -0
- package/dist/processors/relevant-tokens.js +14 -0
- package/dist/processors/relevant-tokens.js.map +1 -0
- package/dist/processors/subgraph.d.ts +3 -0
- package/dist/processors/subgraph.js +16 -0
- package/dist/processors/subgraph.js.map +1 -0
- package/dist/run-function.d.ts +2 -0
- package/dist/run-function.js +83 -0
- package/dist/run-function.js.map +1 -0
- package/dist/types.d.ts +65 -41
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +93 -0
- package/dist/utils.js.map +1 -0
- package/dist/validators.d.ts +447 -20
- package/dist/validators.js +58 -10
- package/dist/validators.js.map +1 -1
- package/package.json +9 -3
- package/dist/run-task.d.ts +0 -2
- package/dist/run-task.js +0 -107
- package/dist/run-task.js.map +0 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.runFunction = runFunction;
|
|
27
|
+
const runner_node_1 = require("@mimicprotocol/runner-node");
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const processors_1 = require("./processors");
|
|
30
|
+
const utils_1 = require("./utils");
|
|
31
|
+
const validators_1 = require("./validators");
|
|
32
|
+
const DEFAULT_CONTEXT = {
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
consensusThreshold: 1,
|
|
35
|
+
triggerSig: '0x',
|
|
36
|
+
triggerPayload: { type: 0, data: '0x' },
|
|
37
|
+
};
|
|
38
|
+
async function runFunction(functionDir, context, optional = {}, oracleUrl = '') {
|
|
39
|
+
const functionPath = path.join(functionDir, 'function.wasm');
|
|
40
|
+
const inputs = optional.inputs || {};
|
|
41
|
+
const showLogs = optional.showLogs ?? true;
|
|
42
|
+
const contextResult = validators_1.ContextValidator.safeParse(context);
|
|
43
|
+
if (!contextResult.success) {
|
|
44
|
+
throw (0, utils_1.formatValidationError)(contextResult.error, {
|
|
45
|
+
queryType: 'context',
|
|
46
|
+
request: context,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const validatedContext = contextResult.data;
|
|
50
|
+
const oracleResponses = getOracleResponses(optional, validatedContext.timestamp || DEFAULT_CONTEXT.timestamp);
|
|
51
|
+
const fullContext = { ...DEFAULT_CONTEXT, ...validatedContext, oracleResponses };
|
|
52
|
+
const result = await (0, runner_node_1.runExecution)(functionPath, JSON.stringify(inputs), JSON.stringify(fullContext), oracleUrl);
|
|
53
|
+
const logs = JSON.parse(result.logsJson);
|
|
54
|
+
if (showLogs && !result.success && logs.length > 0) {
|
|
55
|
+
console.log('The execution produced the following logs, which may indicate a problem:\n');
|
|
56
|
+
for (const log of logs) {
|
|
57
|
+
console.log(`- ${log}`);
|
|
58
|
+
}
|
|
59
|
+
console.log('\n');
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
success: result.success,
|
|
63
|
+
timestamp: Number(result.timestamp),
|
|
64
|
+
fuelUsed: Number(result.fuelUsed),
|
|
65
|
+
oracleResponses: JSON.parse(result.responsesJson),
|
|
66
|
+
intents: (0, utils_1.toIntents)(result.intentsJson),
|
|
67
|
+
logs,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function getOracleResponses(optional, contextTimestamp) {
|
|
71
|
+
const { prices = [], relevantTokens = [], calls = [], subgraphQueries = [] } = optional;
|
|
72
|
+
const priceResponses = (0, utils_1.processQueries)(prices, processors_1.priceQueryProcessor, contextTimestamp);
|
|
73
|
+
const relevantTokensResponses = (0, utils_1.processQueries)(relevantTokens, processors_1.relevantTokensQueryProcessor, contextTimestamp);
|
|
74
|
+
const callsResponses = (0, utils_1.processQueries)(calls, processors_1.evmCallQueryProcessor, contextTimestamp);
|
|
75
|
+
const subgraphQueriesResponses = (0, utils_1.processQueries)(subgraphQueries, processors_1.subgraphQueryProcessor, contextTimestamp);
|
|
76
|
+
return {
|
|
77
|
+
...priceResponses,
|
|
78
|
+
...relevantTokensResponses,
|
|
79
|
+
...callsResponses,
|
|
80
|
+
...subgraphQueriesResponses,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=run-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-function.js","sourceRoot":"","sources":["../src/run-function.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,kCAyCC;AA7DD,4DAAyD;AACzD,2CAA4B;AAE5B,6CAKqB;AAErB,mCAA0E;AAC1E,6CAA+C;AAE/C,MAAM,eAAe,GAAG;IACtB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;IACrB,kBAAkB,EAAE,CAAC;IACrB,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;CACxC,CAAA;AAEM,KAAK,UAAU,WAAW,CAC/B,WAAmB,EACnB,OAAgB,EAChB,WAAsC,EAAE,EACxC,YAAoB,EAAE;IAEtB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IAC5D,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAA;IACpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,IAAI,IAAI,CAAA;IAE1C,MAAM,aAAa,GAAG,6BAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACzD,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAA,6BAAqB,EAAC,aAAa,CAAC,KAAK,EAAE;YAC/C,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,OAAO;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,gBAAgB,GAAG,aAAa,CAAC,IAAI,CAAA;IAC3C,MAAM,eAAe,G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G,QAAQ,CAAA;IAEvF,MAAM,cAAc,GAAG,IAAA,sBAAc,EAAC,MAAM,EAAE,gCAAmB,EAAE,gBAAgB,CAAC,CAAA;IACpF,MAAM,uBAAuB,GAAG,IAAA,sBAAc,EAAC,cAAc,EAAE,yCAA4B,EAAE,gBAAgB,CAAC,CAAA;IAC9G,MAAM,cAAc,GAAG,IAAA,sBAAc,EAAC,KAAK,EAAE,kCAAqB,EAAE,gBAAgB,CAAC,CAAA;IACrF,MAAM,wBAAwB,GAAG,IAAA,sBAAc,EAAC,eAAe,EAAE,mCAAsB,EAAE,gBAAgB,CAAC,CAAA;IAE1G,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,uBAAuB;QAC1B,GAAG,cAAc;QACjB,GAAG,wBAAwB;KAC5B,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,62 +1,73 @@
|
|
|
1
|
-
import { z } from '
|
|
2
|
-
import { InputsValidator, MockConfigValidator, MockFunctionResponseValidator, ParameterizedResponseValidator } from './validators';
|
|
1
|
+
import { AnyOracleResponse, OracleQueryName, OracleQueryParams, OracleQueryResult, TokenAmountValidator, TokenValidator, z } from '@mimicprotocol/sdk';
|
|
2
|
+
import { ContextValidator, EvmCallRequestValidator, EvmCallTypedValueValidator, InputsValidator, MockConfigValidator, MockFunctionResponseValidator, ParameterizedResponseValidator, RelevantTokenBalanceValidator, RelevantTokensRequestValidator as RelevantTokensQueryRequestValidator, RelevantTokensResponseValidator as RelevantTokensQueryResponseValidator, SubgraphQueryRequestValidator, SubgraphQueryResponseValidator, TokenPriceRequestValidator as TokenPriceQueryRequestValidator, TokenPriceResponseValidator as TokenPriceQueryResponseValidator } from './validators';
|
|
3
|
+
export declare const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
3
4
|
export type MockResponseValue = z.infer<typeof MockFunctionResponseValidator>;
|
|
4
5
|
export type ParameterizedResponse = z.infer<typeof ParameterizedResponseValidator>;
|
|
5
6
|
export type MockConfig = z.output<typeof MockConfigValidator>;
|
|
6
7
|
export type Inputs = z.infer<typeof InputsValidator>;
|
|
7
|
-
export type Context =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
export type TokenPrice = {
|
|
13
|
-
token: string;
|
|
14
|
-
chainId: number;
|
|
15
|
-
usdPrice: string;
|
|
16
|
-
timestamp?: string;
|
|
8
|
+
export type Context = z.infer<typeof ContextValidator>;
|
|
9
|
+
export type QueryMock<T, R> = {
|
|
10
|
+
request: T;
|
|
11
|
+
response: R;
|
|
17
12
|
};
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
to: string;
|
|
26
|
-
chainId: number;
|
|
27
|
-
timestamp?: string;
|
|
28
|
-
data: string;
|
|
29
|
-
output: string;
|
|
30
|
-
outputType: string;
|
|
13
|
+
export type QueryProcessor<TRequest, TResponse, TParams extends OracleQueryParams<OracleQueryName>, TValue extends OracleQueryResult<OracleQueryName>> = {
|
|
14
|
+
queryName: OracleQueryName;
|
|
15
|
+
queryTypeLabel: string;
|
|
16
|
+
requestValidator: z.ZodType<TRequest>;
|
|
17
|
+
responseValidator: z.ZodType<TResponse>;
|
|
18
|
+
transformParams: (request: TRequest, contextTimestamp: number) => TParams;
|
|
19
|
+
transformResponse: (response: TResponse) => TValue;
|
|
31
20
|
};
|
|
21
|
+
export type TokenPriceQueryRequest = z.infer<typeof TokenPriceQueryRequestValidator>;
|
|
22
|
+
export type TokenPriceQueryResponse = z.infer<typeof TokenPriceQueryResponseValidator>;
|
|
23
|
+
export type TokenPriceQueryMock = QueryMock<TokenPriceQueryRequest, TokenPriceQueryResponse>;
|
|
24
|
+
export type Token = z.infer<typeof TokenValidator>;
|
|
25
|
+
export type TokenAmount = z.infer<typeof TokenAmountValidator>;
|
|
26
|
+
export type RelevantTokensQueryRequest = z.infer<typeof RelevantTokensQueryRequestValidator>;
|
|
27
|
+
export type RelevantTokenBalance = z.infer<typeof RelevantTokenBalanceValidator>;
|
|
28
|
+
export type RelevantTokensQueryResponse = z.infer<typeof RelevantTokensQueryResponseValidator>;
|
|
29
|
+
export type RelevantTokensQueryMock = QueryMock<RelevantTokensQueryRequest, RelevantTokensQueryResponse[]>;
|
|
30
|
+
export type EvmCallTypedValue = z.infer<typeof EvmCallTypedValueValidator>;
|
|
31
|
+
export type EvmCallQueryRequest = z.infer<typeof EvmCallRequestValidator>;
|
|
32
|
+
export type EvmCallQueryResponse = EvmCallTypedValue;
|
|
33
|
+
export type EvmCallQueryMock = QueryMock<EvmCallQueryRequest, EvmCallQueryResponse>;
|
|
34
|
+
export type SubgraphQueryRequest = z.infer<typeof SubgraphQueryRequestValidator>;
|
|
35
|
+
export type SubgraphQueryResponse = z.infer<typeof SubgraphQueryResponseValidator>;
|
|
36
|
+
export type SubgraphQueryMock = QueryMock<SubgraphQueryRequest, SubgraphQueryResponse>;
|
|
32
37
|
export type GenerateMockParams = {
|
|
33
38
|
context: Context;
|
|
34
39
|
inputs: Inputs;
|
|
35
|
-
prices:
|
|
36
|
-
|
|
37
|
-
calls:
|
|
40
|
+
prices: TokenPriceQueryMock[];
|
|
41
|
+
relevantTokens: RelevantTokensQueryMock[];
|
|
42
|
+
calls: EvmCallQueryMock[];
|
|
43
|
+
subgraphQueries: SubgraphQueryMock[];
|
|
44
|
+
showLogs: boolean;
|
|
38
45
|
};
|
|
39
|
-
export type
|
|
40
|
-
export type
|
|
46
|
+
export type RunFunctionOptionalParams = Partial<Omit<GenerateMockParams, 'context'>>;
|
|
47
|
+
export type IntentBase = {
|
|
41
48
|
op: number;
|
|
42
49
|
settler: string;
|
|
43
50
|
user: string;
|
|
44
51
|
deadline: string;
|
|
45
52
|
nonce: string;
|
|
53
|
+
maxFees: {
|
|
54
|
+
token: string;
|
|
55
|
+
amount: string;
|
|
56
|
+
}[];
|
|
57
|
+
events: {
|
|
58
|
+
topic: string;
|
|
59
|
+
data: string;
|
|
60
|
+
}[];
|
|
46
61
|
};
|
|
47
|
-
export type Transfer =
|
|
48
|
-
type: 'transfer';
|
|
62
|
+
export type Transfer = IntentBase & {
|
|
49
63
|
chainId: number;
|
|
50
64
|
transfers: {
|
|
51
65
|
token: string;
|
|
52
66
|
amount: string;
|
|
53
67
|
recipient: string;
|
|
54
68
|
}[];
|
|
55
|
-
feeToken: string;
|
|
56
|
-
feeAmount: string;
|
|
57
69
|
};
|
|
58
|
-
export type Swap =
|
|
59
|
-
type: 'swap';
|
|
70
|
+
export type Swap = IntentBase & {
|
|
60
71
|
sourceChain: number;
|
|
61
72
|
destinationChain: number;
|
|
62
73
|
tokensIn: {
|
|
@@ -69,15 +80,28 @@ export type Swap = Intent & {
|
|
|
69
80
|
recipient: string;
|
|
70
81
|
}[];
|
|
71
82
|
};
|
|
72
|
-
export type Call =
|
|
73
|
-
type: 'call';
|
|
83
|
+
export type Call = IntentBase & {
|
|
74
84
|
chainId: number;
|
|
75
85
|
calls: {
|
|
76
86
|
target: string;
|
|
77
87
|
data: string;
|
|
78
88
|
value: string;
|
|
79
89
|
}[];
|
|
80
|
-
feeToken: string;
|
|
81
|
-
feeAmount: string;
|
|
82
90
|
};
|
|
83
|
-
export type
|
|
91
|
+
export type Intent = Transfer | Swap | Call;
|
|
92
|
+
export type OracleResponse = AnyOracleResponse;
|
|
93
|
+
export type RunFunctionResult = {
|
|
94
|
+
success: boolean;
|
|
95
|
+
timestamp: number;
|
|
96
|
+
fuelUsed: number;
|
|
97
|
+
oracleResponses: OracleResponse[];
|
|
98
|
+
intents: Intent[];
|
|
99
|
+
logs: string[];
|
|
100
|
+
};
|
|
101
|
+
export type ValidationErrorContext = {
|
|
102
|
+
entryIndex?: number;
|
|
103
|
+
queryType?: string;
|
|
104
|
+
validationTarget?: 'request' | 'response';
|
|
105
|
+
request?: Record<string, unknown>;
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
};
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA2Ba,QAAA,YAAY,GAAG,4CAA4C,CAAA"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OracleQueryName, OracleQueryParams, OracleQueryResult, z } from '@mimicprotocol/sdk';
|
|
2
|
+
import { OracleResponse, QueryMock, QueryProcessor, ValidationErrorContext } from './types';
|
|
3
|
+
export declare function toIntents(intentsJson: string): any;
|
|
4
|
+
export declare function formatValidationError(error: z.ZodError, context?: ValidationErrorContext): Error;
|
|
5
|
+
export declare function processQueries<TRequest, TResponse, TParams extends OracleQueryParams<OracleQueryName>, TValue extends OracleQueryResult<OracleQueryName>>(items: QueryMock<unknown, unknown>[], processor: QueryProcessor<TRequest, TResponse, TParams, TValue>, contextTimestamp: number): Record<string, OracleResponse[]>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toIntents = toIntents;
|
|
4
|
+
exports.formatValidationError = formatValidationError;
|
|
5
|
+
exports.processQueries = processQueries;
|
|
6
|
+
const sdk_1 = require("@mimicprotocol/sdk");
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const SIGNER = new sdk_1.OracleSigner(sdk_1.EthersSigner.fromPrivateKey(ethers_1.Wallet.createRandom().privateKey));
|
|
9
|
+
function toIntents(intentsJson) {
|
|
10
|
+
const raw = JSON.parse(intentsJson);
|
|
11
|
+
return raw.map((intent) => {
|
|
12
|
+
if (intent.op == sdk_1.OpType.Swap) {
|
|
13
|
+
const { sourceChain, destinationChain } = intent;
|
|
14
|
+
return { ...intent, sourceChain: Number(sourceChain), destinationChain: Number(destinationChain) };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const { chainId } = intent;
|
|
18
|
+
return { ...intent, chainId: Number(chainId) };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function formatValidationError(error, context) {
|
|
23
|
+
const parts = [];
|
|
24
|
+
const validationTarget = context?.validationTarget ? ` (${context.validationTarget})` : '';
|
|
25
|
+
if (context?.entryIndex !== undefined) {
|
|
26
|
+
const queryType = context.queryType || 'entry';
|
|
27
|
+
parts.push(`Validation error in ${queryType} #${context.entryIndex}${validationTarget}:`);
|
|
28
|
+
}
|
|
29
|
+
else if (context?.queryType) {
|
|
30
|
+
parts.push(`Validation error in ${context.queryType}${validationTarget}:`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
parts.push(`Validation error${validationTarget}:`);
|
|
34
|
+
}
|
|
35
|
+
if (context?.request)
|
|
36
|
+
parts.push(` Request: ${JSON.stringify(context.request)}`);
|
|
37
|
+
for (const issue of error.errors) {
|
|
38
|
+
const pathStr = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
39
|
+
const pathDisplay = pathStr !== 'root' ? ` (at ${pathStr})` : '';
|
|
40
|
+
let valueInfo = '';
|
|
41
|
+
if (issue.code === 'invalid_type' && 'received' in issue) {
|
|
42
|
+
valueInfo = `Received: ${issue.received}`;
|
|
43
|
+
}
|
|
44
|
+
else if ('input' in issue && issue.input !== undefined) {
|
|
45
|
+
const inputStr = typeof issue.input === 'string' ? issue.input : JSON.stringify(issue.input);
|
|
46
|
+
valueInfo = `Invalid value: ${inputStr}${pathDisplay}`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
valueInfo = `At path: ${pathStr}`;
|
|
50
|
+
}
|
|
51
|
+
parts.push(` ${valueInfo}`);
|
|
52
|
+
parts.push(` Error: ${issue.message}`);
|
|
53
|
+
}
|
|
54
|
+
return new Error(parts.join('\n'));
|
|
55
|
+
}
|
|
56
|
+
function processQueries(items, processor, contextTimestamp) {
|
|
57
|
+
const oracleResponses = {};
|
|
58
|
+
for (let i = 0; i < items.length; i++) {
|
|
59
|
+
const item = items[i];
|
|
60
|
+
const requestResult = processor.requestValidator.safeParse(item.request);
|
|
61
|
+
if (!requestResult.success) {
|
|
62
|
+
throw formatValidationError(requestResult.error, {
|
|
63
|
+
entryIndex: i,
|
|
64
|
+
queryType: processor.queryTypeLabel,
|
|
65
|
+
validationTarget: 'request',
|
|
66
|
+
request: item.request,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const params = processor.transformParams(requestResult.data, contextTimestamp);
|
|
70
|
+
const responseResult = processor.responseValidator.safeParse(item.response);
|
|
71
|
+
if (!responseResult.success) {
|
|
72
|
+
throw formatValidationError(responseResult.error, {
|
|
73
|
+
entryIndex: i,
|
|
74
|
+
queryType: processor.queryTypeLabel,
|
|
75
|
+
validationTarget: 'response',
|
|
76
|
+
request: requestResult.data,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const value = processor.transformResponse(responseResult.data);
|
|
80
|
+
addOracleResponse(oracleResponses, processor.queryName, params, value);
|
|
81
|
+
}
|
|
82
|
+
return oracleResponses;
|
|
83
|
+
}
|
|
84
|
+
function addOracleResponse(oracleResponses, queryName, params, value) {
|
|
85
|
+
const hash = SIGNER.getQueryHash(params, queryName);
|
|
86
|
+
const response = {
|
|
87
|
+
result: { value },
|
|
88
|
+
query: { params, name: queryName, hash },
|
|
89
|
+
signature: '',
|
|
90
|
+
};
|
|
91
|
+
oracleResponses[hash] = [response];
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAwBA,8BAWC;AAED,sDAmCC;AAED,wCAwCC;AAlHD,4CAQ2B;AAC3B,mCAA+B;AAa/B,MAAM,MAAM,GAAG,IAAI,kBAAY,CAAC,kBAAY,CAAC,cAAc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