@guardian-network/policy-intermediate-representation 0.3.2
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/README.md +36 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/ir-notation/errors/ErrorFactory.d.ts +7 -0
- package/dist/ir-notation/errors/ErrorFactory.d.ts.map +1 -0
- package/dist/ir-notation/errors/ErrorFactory.js +17 -0
- package/dist/ir-notation/errors/ErrorFactory.js.map +1 -0
- package/dist/ir-notation/errors/index.d.ts +2 -0
- package/dist/ir-notation/errors/index.d.ts.map +1 -0
- package/dist/ir-notation/errors/index.js +18 -0
- package/dist/ir-notation/errors/index.js.map +1 -0
- package/dist/ir-notation/errors/validation-errors.d.ts +11 -0
- package/dist/ir-notation/errors/validation-errors.d.ts.map +1 -0
- package/dist/ir-notation/errors/validation-errors.js +26 -0
- package/dist/ir-notation/errors/validation-errors.js.map +1 -0
- package/dist/ir-notation/helpers/formatters.d.ts +18 -0
- package/dist/ir-notation/helpers/formatters.d.ts.map +1 -0
- package/dist/ir-notation/helpers/formatters.js +45 -0
- package/dist/ir-notation/helpers/formatters.js.map +1 -0
- package/dist/ir-notation/helpers/index.d.ts +5 -0
- package/dist/ir-notation/helpers/index.d.ts.map +1 -0
- package/dist/ir-notation/helpers/index.js +21 -0
- package/dist/ir-notation/helpers/index.js.map +1 -0
- package/dist/ir-notation/helpers/matchers.d.ts +4 -0
- package/dist/ir-notation/helpers/matchers.d.ts.map +1 -0
- package/dist/ir-notation/helpers/matchers.js +17 -0
- package/dist/ir-notation/helpers/matchers.js.map +1 -0
- package/dist/ir-notation/helpers/morphs.d.ts +4 -0
- package/dist/ir-notation/helpers/morphs.d.ts.map +1 -0
- package/dist/ir-notation/helpers/morphs.js +26 -0
- package/dist/ir-notation/helpers/morphs.js.map +1 -0
- package/dist/ir-notation/helpers/validation/index.d.ts +2 -0
- package/dist/ir-notation/helpers/validation/index.d.ts.map +1 -0
- package/dist/ir-notation/helpers/validation/index.js +18 -0
- package/dist/ir-notation/helpers/validation/index.js.map +1 -0
- package/dist/ir-notation/helpers/validation/typing.validation.d.ts +10 -0
- package/dist/ir-notation/helpers/validation/typing.validation.d.ts.map +1 -0
- package/dist/ir-notation/helpers/validation/typing.validation.js +41 -0
- package/dist/ir-notation/helpers/validation/typing.validation.js.map +1 -0
- package/dist/ir-notation/parser/index.d.ts +4 -0
- package/dist/ir-notation/parser/index.d.ts.map +1 -0
- package/dist/ir-notation/parser/index.js +14 -0
- package/dist/ir-notation/parser/index.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/ParserWithValidation.d.ts +14 -0
- package/dist/ir-notation/parser/parser-contracts/ParserWithValidation.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/ParserWithValidation.js +44 -0
- package/dist/ir-notation/parser/parser-contracts/ParserWithValidation.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/SimplifiedParser.d.ts +12 -0
- package/dist/ir-notation/parser/parser-contracts/SimplifiedParser.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/SimplifiedParser.js +27 -0
- package/dist/ir-notation/parser/parser-contracts/SimplifiedParser.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/StaticParser.d.ts +7 -0
- package/dist/ir-notation/parser/parser-contracts/StaticParser.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/StaticParser.js +16 -0
- package/dist/ir-notation/parser/parser-contracts/StaticParser.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/base/ParserBase.d.ts +7 -0
- package/dist/ir-notation/parser/parser-contracts/base/ParserBase.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/base/ParserBase.js +40 -0
- package/dist/ir-notation/parser/parser-contracts/base/ParserBase.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/guards.d.ts +5 -0
- package/dist/ir-notation/parser/parser-contracts/guards.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/guards.js +14 -0
- package/dist/ir-notation/parser/parser-contracts/guards.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/index.d.ts +5 -0
- package/dist/ir-notation/parser/parser-contracts/index.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/index.js +13 -0
- package/dist/ir-notation/parser/parser-contracts/index.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/ParamsExtractor.d.ts +19 -0
- package/dist/ir-notation/parser/parser-contracts/tools/ParamsExtractor.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/ParamsExtractor.js +140 -0
- package/dist/ir-notation/parser/parser-contracts/tools/ParamsExtractor.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/TypesNormalizer.d.ts +7 -0
- package/dist/ir-notation/parser/parser-contracts/tools/TypesNormalizer.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/TypesNormalizer.js +49 -0
- package/dist/ir-notation/parser/parser-contracts/tools/TypesNormalizer.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/index.d.ts +6 -0
- package/dist/ir-notation/parser/parser-contracts/tools/index.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/index.js +25 -0
- package/dist/ir-notation/parser/parser-contracts/tools/index.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/tools.helper.d.ts +5 -0
- package/dist/ir-notation/parser/parser-contracts/tools/tools.helper.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/tools.helper.js +26 -0
- package/dist/ir-notation/parser/parser-contracts/tools/tools.helper.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/DSLConfigArgsTypesSource.d.ts +10 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/DSLConfigArgsTypesSource.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/DSLConfigArgsTypesSource.js +36 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/DSLConfigArgsTypesSource.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.d.ts +12 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.js +39 -0
- package/dist/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.js.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/types.d.ts +59 -0
- package/dist/ir-notation/parser/parser-contracts/types.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser-contracts/types.js +12 -0
- package/dist/ir-notation/parser/parser-contracts/types.js.map +1 -0
- package/dist/ir-notation/parser/parser.unvalidated.d.ts +6 -0
- package/dist/ir-notation/parser/parser.unvalidated.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser.unvalidated.js +92 -0
- package/dist/ir-notation/parser/parser.unvalidated.js.map +1 -0
- package/dist/ir-notation/parser/parser.validated.d.ts +17 -0
- package/dist/ir-notation/parser/parser.validated.d.ts.map +1 -0
- package/dist/ir-notation/parser/parser.validated.js +37 -0
- package/dist/ir-notation/parser/parser.validated.js.map +1 -0
- package/dist/ir-notation/parser/types.d.ts +9 -0
- package/dist/ir-notation/parser/types.d.ts.map +1 -0
- package/dist/ir-notation/parser/types.js +11 -0
- package/dist/ir-notation/parser/types.js.map +1 -0
- package/package.json +71 -0
- package/src/index.ts +5 -0
- package/src/ir-notation/errors/ErrorFactory.ts +25 -0
- package/src/ir-notation/errors/index.ts +1 -0
- package/src/ir-notation/errors/validation-errors.ts +38 -0
- package/src/ir-notation/helpers/formatters.ts +63 -0
- package/src/ir-notation/helpers/index.ts +4 -0
- package/src/ir-notation/helpers/matchers.ts +12 -0
- package/src/ir-notation/helpers/morphs.ts +26 -0
- package/src/ir-notation/helpers/validation/index.ts +1 -0
- package/src/ir-notation/helpers/validation/typing.validation.ts +89 -0
- package/src/ir-notation/parser/index.ts +10 -0
- package/src/ir-notation/parser/parser-contracts/ParserWithValidation.ts +99 -0
- package/src/ir-notation/parser/parser-contracts/SimplifiedParser.ts +41 -0
- package/src/ir-notation/parser/parser-contracts/StaticParser.ts +25 -0
- package/src/ir-notation/parser/parser-contracts/base/ParserBase.ts +79 -0
- package/src/ir-notation/parser/parser-contracts/guards.ts +17 -0
- package/src/ir-notation/parser/parser-contracts/index.ts +7 -0
- package/src/ir-notation/parser/parser-contracts/tools/ParamsExtractor.ts +251 -0
- package/src/ir-notation/parser/parser-contracts/tools/TypesNormalizer.ts +78 -0
- package/src/ir-notation/parser/parser-contracts/tools/index.ts +5 -0
- package/src/ir-notation/parser/parser-contracts/tools/tools.helper.ts +33 -0
- package/src/ir-notation/parser/parser-contracts/tools/types-source/DSLConfigArgsTypesSource.ts +52 -0
- package/src/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.ts +76 -0
- package/src/ir-notation/parser/parser-contracts/types.ts +78 -0
- package/src/ir-notation/parser/parser.unvalidated.ts +200 -0
- package/src/ir-notation/parser/parser.validated.ts +67 -0
- package/src/ir-notation/parser/types.ts +28 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnchainDescriptorArgsTypesSource = void 0;
|
|
4
|
+
const shared_1 = require("@guardian-network/shared");
|
|
5
|
+
class OnchainDescriptorArgsTypesSource {
|
|
6
|
+
provider;
|
|
7
|
+
artifactInstance;
|
|
8
|
+
constructor(provider) {
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
}
|
|
11
|
+
connectInstance = (artifactAddress) => {
|
|
12
|
+
this.artifactInstance = shared_1.MinArbitraryDataArtifactFactory.connect(artifactAddress, this.provider);
|
|
13
|
+
return this;
|
|
14
|
+
};
|
|
15
|
+
getTypesValues = async (instanceAddress) => {
|
|
16
|
+
this.connectInstance(instanceAddress);
|
|
17
|
+
const execDescriptorValue = await this.artifactInstance.getExecDescriptor();
|
|
18
|
+
const initDescriptorValue = await this.artifactInstance.getInitDescriptor();
|
|
19
|
+
return { execDescriptorValue, initDescriptorValue };
|
|
20
|
+
};
|
|
21
|
+
getTypes = async (instanceAddress) => {
|
|
22
|
+
const { execDescriptorValue: { argsTypes: execParamsTypes }, initDescriptorValue: { argsTypes: initParamsTypes }, } = await this.getTypesValues(instanceAddress);
|
|
23
|
+
return {
|
|
24
|
+
initParamsTypes: [...initParamsTypes],
|
|
25
|
+
execParamsTypes: [...execParamsTypes],
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
getTypesAndNames = async (instanceAddress) => {
|
|
29
|
+
const { execDescriptorValue: { argsTypes: execParamsTypes, argsNames: execParamsNames, }, initDescriptorValue: { argsTypes: initParamsTypes, argsNames: initParamsNames, }, } = await this.getTypesValues(instanceAddress);
|
|
30
|
+
return {
|
|
31
|
+
initParamsTypes: [...initParamsTypes],
|
|
32
|
+
initParamsNames: [...initParamsNames],
|
|
33
|
+
execParamsTypes: [...execParamsTypes],
|
|
34
|
+
execParamsNames: [...execParamsNames],
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.OnchainDescriptorArgsTypesSource = OnchainDescriptorArgsTypesSource;
|
|
39
|
+
//# sourceMappingURL=OnchainDescriptorArgsTypesSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnchainDescriptorArgsTypesSource.js","sourceRoot":"","sources":["../../../../../../src/ir-notation/parser/parser-contracts/tools/types-source/OnchainDescriptorArgsTypesSource.ts"],"names":[],"mappings":";;;AAAA,qDAGkC;AASlC,MAAa,gCAAgC;IAKvB;IAFZ,gBAAgB,CAA6B;IAErD,YAAoB,QAAwB;QAAxB,aAAQ,GAAR,QAAQ,CAAgB;IAAG,CAAC;IAEtC,eAAe,GAAG,CAAC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CAAC,GAAG,eAAe,CAAC;YACrC,eAAe,EAAE,CAAC,GAAG,eAAe,CAAC;SACtC,CAAC;IACJ,CAAC,CAAC;CACH;AA/DD,4EA+DC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type GetTypesValues = (artifactAddress: string, posAtConfigList?: number) => Promise<ExecInitArtifactTypes>;
|
|
2
|
+
export interface IArgsTypesSource {
|
|
3
|
+
getTypes: GetTypesValues;
|
|
4
|
+
}
|
|
5
|
+
export interface IArgsTypesAndNamesSource {
|
|
6
|
+
getTypesAndNames(instanceAddress: string): Promise<ExecInitArtifactTypesAndNames>;
|
|
7
|
+
}
|
|
8
|
+
export interface IParamsExtractor {
|
|
9
|
+
artifactData: (rawArtifact?: string) => Promise<ArtifactData>;
|
|
10
|
+
}
|
|
11
|
+
export type ArtifactData = {
|
|
12
|
+
artifactAddress: string;
|
|
13
|
+
argsCount: number;
|
|
14
|
+
execRuntimeVariablesIndices: number[];
|
|
15
|
+
execRuntimeVariablesInjectionsWithIndices: Parameter[];
|
|
16
|
+
execSubstitutionParamsList: SubstitutingParameter[];
|
|
17
|
+
execKnownParamsList: Parameter[];
|
|
18
|
+
initDataParamsSolidityPacked: string;
|
|
19
|
+
needsInitialization: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ExecInitArtifactTypes = {
|
|
22
|
+
execParamsTypes: string[];
|
|
23
|
+
initParamsTypes: string[];
|
|
24
|
+
};
|
|
25
|
+
export type ExecInitArtifactTypesAndNames = ExecInitArtifactTypes & {
|
|
26
|
+
execParamsNames: string[];
|
|
27
|
+
initParamsNames: string[];
|
|
28
|
+
};
|
|
29
|
+
export type KnownTSType = string | bigint | boolean | Uint8Array;
|
|
30
|
+
export type SolidityType = `${SupportedSolidityTypesEnum}`;
|
|
31
|
+
export declare enum SupportedSolidityTypesEnum {
|
|
32
|
+
Uint256 = "uint256",
|
|
33
|
+
String = "string",
|
|
34
|
+
Bool = "bool",
|
|
35
|
+
Bytes = "bytes",
|
|
36
|
+
Address = "address"
|
|
37
|
+
}
|
|
38
|
+
type AddressComponent = {
|
|
39
|
+
addressClause: string;
|
|
40
|
+
};
|
|
41
|
+
type UnprocessedInitDataAndExecParams = {
|
|
42
|
+
initClause: string | null;
|
|
43
|
+
paramsClause: string;
|
|
44
|
+
};
|
|
45
|
+
export type RawArtifactComponents = AddressComponent & UnprocessedInitDataAndExecParams;
|
|
46
|
+
export type NormalizedExecParameter = {
|
|
47
|
+
supplierNodeId: string;
|
|
48
|
+
index: number;
|
|
49
|
+
};
|
|
50
|
+
export type SubstitutingParameter = {
|
|
51
|
+
from: string;
|
|
52
|
+
atPos: number;
|
|
53
|
+
};
|
|
54
|
+
export type Parameter = {
|
|
55
|
+
value: string;
|
|
56
|
+
index: number;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ir-notation/parser/parser-contracts/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAC3B,eAAe,EAAE,MAAM,EACvB,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACvC,gBAAgB,CACd,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,6BAA6B,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CAC/D;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B,EAAE,MAAM,EAAE,CAAC;IACtC,yCAAyC,EAAE,SAAS,EA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0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupportedSolidityTypesEnum = void 0;
|
|
4
|
+
var SupportedSolidityTypesEnum;
|
|
5
|
+
(function (SupportedSolidityTypesEnum) {
|
|
6
|
+
SupportedSolidityTypesEnum["Uint256"] = "uint256";
|
|
7
|
+
SupportedSolidityTypesEnum["String"] = "string";
|
|
8
|
+
SupportedSolidityTypesEnum["Bool"] = "bool";
|
|
9
|
+
SupportedSolidityTypesEnum["Bytes"] = "bytes";
|
|
10
|
+
SupportedSolidityTypesEnum["Address"] = "address";
|
|
11
|
+
})(SupportedSolidityTypesEnum || (exports.SupportedSolidityTypesEnum = SupportedSolidityTypesEnum = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/ir-notation/parser/parser-contracts/types.ts"],"names":[],"mappings":";;;AA4CA,IAAY,0BAMX;AAND,WAAY,0BAA0B;IACpC,iDAAmB,CAAA;IACnB,+CAAiB,CAAA;IACjB,2CAAa,CAAA;IACb,6CAAe,CAAA;IACf,iDAAmB,CAAA;AACrB,CAAC,EANW,0BAA0B,0CAA1B,0BAA0B,QAMrC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TranspilerOutput } from '@guardian-network/shared';
|
|
2
|
+
import { ContractRunner } from 'ethers/providers';
|
|
3
|
+
import { ValidationMiddlware } from './types';
|
|
4
|
+
export declare const parseIRByDSLTypesWithInterceptor: ({ ir, typings }: TranspilerOutput, middleware?: ValidationMiddlware) => Promise<import("@guardian-network/shared").NodeInitDataStruct[]>;
|
|
5
|
+
export declare const parseIRByOnchainTypesWithInterceptor: ({ ir, typings }: TranspilerOutput, provider: ContractRunner, middleware?: ValidationMiddlware) => Promise<import("@guardian-network/shared").NodeInitDataStruct[]>;
|
|
6
|
+
//# sourceMappingURL=parser.unvalidated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.unvalidated.d.ts","sourceRoot":"","sources":["../../../src/ir-notation/parser/parser.unvalidated.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAalD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA4E7D,eAAO,MAAM,gCAAgC,oBAC1B,gBAAgB,eACpB,mBAAmB,qEAOjC,CAAC;AAGF,eAAO,MAAM,oCAAoC,oBAC9B,gBAAgB,YACvB,cAAc,eACX,mBAAmB,qEAQjC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIRByOnchainTypesWithInterceptor = exports.parseIRByDSLTypesWithInterceptor = void 0;
|
|
4
|
+
const shared_1 = require("@guardian-network/shared");
|
|
5
|
+
const helpers_1 = require("../helpers");
|
|
6
|
+
const tools_1 = require("./parser-contracts/tools");
|
|
7
|
+
const getKnownExecDataAndInitDataFromDslTypes = (parameters, initArgs, instanceConfig) => {
|
|
8
|
+
const execConstTypes = instanceConfig.execArguments
|
|
9
|
+
.filter((el) => el.constant)
|
|
10
|
+
.map((el) => el.type);
|
|
11
|
+
const knownExecParams = (0, helpers_1.indexConstants)(parameters.filter((arg) => (0, helpers_1.isConstant)(arg.value)), execConstTypes.map(helpers_1.DSLTypesToIRTypes));
|
|
12
|
+
const initTypes = instanceConfig.initArguments.map((el) => el.type);
|
|
13
|
+
const initDataEncoded = (0, helpers_1.bytesEncodeArgs)(initArgs, initTypes.map(helpers_1.DSLTypesToIRTypes));
|
|
14
|
+
return {
|
|
15
|
+
knownExecParams,
|
|
16
|
+
initDataEncoded,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const getKnownExecDataAndInitDataFromOnchainTypes = async (parameters, initArgs, instanceConfig, artifactAddress, provider) => {
|
|
20
|
+
const onchain = new tools_1.OnchainDescriptorArgsTypesSource(provider);
|
|
21
|
+
const { execParamsTypes, initParamsTypes } = await onchain.getTypes(artifactAddress);
|
|
22
|
+
const knownExecParams = (0, helpers_1.indexConstants)(parameters.filter((arg) => (0, helpers_1.isConstant)(arg.value)), execParamsTypes);
|
|
23
|
+
const initDataEncoded = (0, helpers_1.bytesEncodeArgs)(initArgs, initParamsTypes);
|
|
24
|
+
return {
|
|
25
|
+
knownExecParams,
|
|
26
|
+
initDataEncoded,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const parseIRByDSLTypesWithInterceptor = async ({ ir, typings }, middleware) => {
|
|
30
|
+
return parse({ ir, typings }, getKnownExecDataAndInitDataFromDslTypes, middleware);
|
|
31
|
+
};
|
|
32
|
+
exports.parseIRByDSLTypesWithInterceptor = parseIRByDSLTypesWithInterceptor;
|
|
33
|
+
const parseIRByOnchainTypesWithInterceptor = async ({ ir, typings }, provider, middleware) => {
|
|
34
|
+
return parse({ ir, typings }, getKnownExecDataAndInitDataFromOnchainTypes, middleware, provider);
|
|
35
|
+
};
|
|
36
|
+
exports.parseIRByOnchainTypesWithInterceptor = parseIRByOnchainTypesWithInterceptor;
|
|
37
|
+
const parse = async (transpileOutput, exectAndInitData, middleware, provider) => {
|
|
38
|
+
const res = [];
|
|
39
|
+
const artifacts = transpileOutput.ir.trim().split(/\r?\n/);
|
|
40
|
+
for (let [index, artifact] of artifacts.entries()) {
|
|
41
|
+
artifact = artifact.trim();
|
|
42
|
+
const { addressClause, paramsClause, initClause } = (0, helpers_1.extractComponents)(artifact);
|
|
43
|
+
const artifactAddress = addressClause;
|
|
44
|
+
const parameters = (0, helpers_1.extractArguments)(paramsClause).map((value, index) => ({
|
|
45
|
+
value,
|
|
46
|
+
index,
|
|
47
|
+
}));
|
|
48
|
+
const initArgs = (0, helpers_1.extractArguments)(initClause);
|
|
49
|
+
const variables = parameters
|
|
50
|
+
.filter((val) => (0, helpers_1.strIsVar)(val.value))
|
|
51
|
+
.map((val) => val.index);
|
|
52
|
+
const substitutions = parameters
|
|
53
|
+
.filter((val) => (0, helpers_1.strIsSubst)(val.value))
|
|
54
|
+
.map((val) => ({
|
|
55
|
+
supplierNodeId: val.value.replace(/\|/g, ''),
|
|
56
|
+
index: val.index,
|
|
57
|
+
}));
|
|
58
|
+
const currentInstanceConfig = transpileOutput.typings[index];
|
|
59
|
+
if (middleware) {
|
|
60
|
+
await middleware.innerValidations(artifactAddress, currentInstanceConfig);
|
|
61
|
+
}
|
|
62
|
+
const { knownExecParams: partialExecData, initDataEncoded: initData } = await exectAndInitData(parameters, initArgs, currentInstanceConfig, artifactAddress, provider);
|
|
63
|
+
const injections = parameters
|
|
64
|
+
.filter((val) => (0, helpers_1.strIsVar)(val.value))
|
|
65
|
+
.map((el, index) => {
|
|
66
|
+
const injection = (0, helpers_1.extractInjection)(el.value);
|
|
67
|
+
if (injection && injection != '') {
|
|
68
|
+
return {
|
|
69
|
+
value: el.value,
|
|
70
|
+
index,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.filter((el) => !!el);
|
|
75
|
+
res.push({
|
|
76
|
+
id: shared_1.NodeId.fromNotation(artifact, index),
|
|
77
|
+
artifactAddress,
|
|
78
|
+
constantExecArgs: partialExecData,
|
|
79
|
+
variableExecArgs: variables,
|
|
80
|
+
injections,
|
|
81
|
+
argsCount: parameters.length,
|
|
82
|
+
substitutedExecArgs: substitutions,
|
|
83
|
+
initData,
|
|
84
|
+
needsInitialization: initArgs.length != 0,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (middleware) {
|
|
88
|
+
await middleware.outerValidations(res);
|
|
89
|
+
}
|
|
90
|
+
return res;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=parser.unvalidated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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,KAAK,CAAC,CAAC;aACpC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACjB,MAAM,SAAS,GAAG,IAAA,0BAAgB,EAAC,EAAE,CAAC,KAAK,CAAC,CAAC;YAE7C,IAAI,SAAS,IAAI,SAAS,IAAI,EAAE,EAAE,CAAC;gBACjC,OAAO;oBACL,KAAK,EAAE,EAAE,CAAC,KAAK;oBACf,KAAK;iBACN,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAExB,GAAG,CAAC,IAAI,CAAC;YACP,EAAE,EAAE,eAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC;YACxC,eAAe;YACf,gBAAgB,EAAE,eAAe;YACjC,gBAAgB,EAAE,SAAS;YAC3B,UAAU;YACV,SAAS,EAAE,UAAU,CAAC,MAAM;YAC5B,mBAAmB,EAAE,aAAa;YAClC,QAAQ;YACR,mBAAmB,EAAE,QAAQ,CAAC,MAAM,IAAI,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,UAAU,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TranspilerOutput } from '@guardian-network/shared';
|
|
2
|
+
import { ContractRunner } from 'ethers';
|
|
3
|
+
export declare const TypingsValidator: (provider: ContractRunner) => {
|
|
4
|
+
innerValidations: (artifactAddress: string, initExecArgumentsConfig: {
|
|
5
|
+
execArguments: Array<import("@guardian-network/shared").MinTypedValue>;
|
|
6
|
+
initArguments: Array<import("@guardian-network/shared").MinTypedValue>;
|
|
7
|
+
}) => Promise<void>;
|
|
8
|
+
outerValidations: (output: import("@guardian-network/shared").NodeTreeInitData[]) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare const getIRParser: (input: TranspilerOutput, provider: ContractRunner) => {
|
|
11
|
+
validated: {
|
|
12
|
+
DSL_TYPING: () => Promise<import("@guardian-network/shared").NodeInitDataStruct[]>;
|
|
13
|
+
ONCHAIN_TYPING: () => Promise<import("@guardian-network/shared").NodeInitDataStruct[]>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const getIRParserUnvalidate: (input: TranspilerOutput) => () => Promise<import("@guardian-network/shared").NodeInitDataStruct[]>;
|
|
17
|
+
//# sourceMappingURL=parser.validated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.validated.d.ts","sourceRoot":"","sources":["../../../src/ir-notation/parser/parser.validated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAOxC,eAAO,MAAM,gBAAgB,aAAc,cAAc;;;;;;CAGvD,CAAC;AAEH,eAAO,MAAM,WAAW,UACf,gBAAgB,YACb,cAAc;;;;;CAoCzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,UAAW,gBAAgB,2EAa5D,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIRParserUnvalidate = exports.getIRParser = exports.TypingsValidator = void 0;
|
|
4
|
+
const helpers_1 = require("../helpers");
|
|
5
|
+
const parser_contracts_1 = require("./parser-contracts");
|
|
6
|
+
const TypingsValidator = (provider) => ({
|
|
7
|
+
innerValidations: (0, helpers_1.dslTypesToOnchainTypesParamsValidation)(provider),
|
|
8
|
+
outerValidations: (0, helpers_1.onchainSubstitutionToReturnTypesValidation)(provider),
|
|
9
|
+
});
|
|
10
|
+
exports.TypingsValidator = TypingsValidator;
|
|
11
|
+
const getIRParser = (input, provider) => {
|
|
12
|
+
return {
|
|
13
|
+
validated: {
|
|
14
|
+
DSL_TYPING: async () => {
|
|
15
|
+
const parser = parser_contracts_1.ParserWithValidation.fromDSLBasedConfig(input.ir, input.typings, provider);
|
|
16
|
+
const parsed = await parser.process();
|
|
17
|
+
return parsed;
|
|
18
|
+
},
|
|
19
|
+
ONCHAIN_TYPING: async () => {
|
|
20
|
+
const parser = parser_contracts_1.ParserWithValidation.fromOnchainSource(input.ir, provider);
|
|
21
|
+
const parsed = await parser.process();
|
|
22
|
+
return parsed;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.getIRParser = getIRParser;
|
|
28
|
+
const getIRParserUnvalidate = (input) => {
|
|
29
|
+
const unvalidateParser = async () => {
|
|
30
|
+
const parser = parser_contracts_1.ParserWithValidation.fromDSLBasedConfig(input.ir, input.typings);
|
|
31
|
+
const parsed = await parser.process();
|
|
32
|
+
return parsed;
|
|
33
|
+
};
|
|
34
|
+
return unvalidateParser;
|
|
35
|
+
};
|
|
36
|
+
exports.getIRParserUnvalidate = getIRParserUnvalidate;
|
|
37
|
+
//# sourceMappingURL=parser.validated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.validated.js","sourceRoot":"","sources":["../../../src/ir-notation/parser/parser.validated.ts"],"names":[],"mappings":";;;AAEA,wCAGoB;AACpB,yDAA0D;AAEnD,MAAM,gBAAgB,GAAG,CAAC,QAAwB,EAAE,EAAE,CAAC,CAAC;IAC7D,gBAAgB,EAAE,IAAA,gDAAsC,EAAC,QAAQ,CAAC;IAClE,gBAAgB,EAAE,IAAA,oDAA0C,EAAC,QAAQ,CAAC;CACvE,CAAC,CAAC;AAHU,QAAA,gBAAgB,oBAG1B;AAEI,MAAM,WAAW,GAAG,CACzB,KAAuB,EACvB,QAAwB,EACxB,EAAE;IAGF,OAAO;QACL,SAAS,EAAE;YACT,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,MAAM,MAAM,GAAG,uCAAoB,CAAC,kBAAkB,CACpD,KAAK,CAAC,EAAE,EACR,KAAK,CAAC,OAAO,EACb,QAAQ,CACT,CAAC;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBACtC,OAAO,MAAM,CAAC;YAMhB,CAAC;YACD,cAAc,EAAE,KAAK,IAAI,EAAE;gBACzB,MAAM,MAAM,GAAG,uCAAoB,CAAC,iBAAiB,CACnD,KAAK,CAAC,EAAE,EACR,QAAQ,CACT,CAAC;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBACtC,OAAO,MAAM,CAAC;YAOhB,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAtCW,QAAA,WAAW,eAsCtB;AAEK,MAAM,qBAAqB,GAAG,CAAC,KAAuB,EAAE,EAAE;IAC/D,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;QAClC,MAAM,MAAM,GAAG,uCAAoB,CAAC,kBAAkB,CACpD,KAAK,CAAC,EAAE,EACR,KAAK,CAAC,OAAO,CACd,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC;IAGhB,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DSLType, InstanceConfig, NodeTreeInitData, SupportedSolidityType } from '@guardian-network/shared';
|
|
2
|
+
export type ParsingResult = NodeTreeInitData;
|
|
3
|
+
export type DslTypeToSolidityType = Record<DSLType, SupportedSolidityType>;
|
|
4
|
+
export declare const DSLTypesMapping: DslTypeToSolidityType;
|
|
5
|
+
export type ValidationMiddlware = {
|
|
6
|
+
innerValidations: (artifactAddress: string, currentInstanceConfig: InstanceConfig) => Promise<void>;
|
|
7
|
+
outerValidations: (output: NodeTreeInitData[]) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ir-notation/parser/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAE7C,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;AAE3E,eAAO,MAAM,eAAe,EAAE,qBAQ7B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,EAAE,CAChB,eAAe,EAAE,MAAM,EACvB,qBAAqB,EAAE,cAAc,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,gBAAgB,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DSLTypesMapping = void 0;
|
|
4
|
+
exports.DSLTypesMapping = {
|
|
5
|
+
number: 'uint256',
|
|
6
|
+
address: 'address',
|
|
7
|
+
bool: 'bool',
|
|
8
|
+
string: 'string',
|
|
9
|
+
bytes: 'bytes',
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ir-notation/parser/types.ts"],"names":[],"mappings":";;;AAWa,QAAA,eAAe,GAA0B;IAGpD,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;CACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@guardian-network/policy-intermediate-representation",
|
|
3
|
+
"author": "v.grabovski@lacero.io, vpriadko@lacero.io",
|
|
4
|
+
"description": "Artifcts high level declaration language",
|
|
5
|
+
"version": "0.3.2",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18.20.4"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"registry": "https://registry.npmjs.org",
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@eslint/eslintrc": "^3.1.0",
|
|
22
|
+
"@eslint/js": "^9.13.0",
|
|
23
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
24
|
+
"@types/chai": "4.3.3",
|
|
25
|
+
"@types/mocha": "^10.0.9",
|
|
26
|
+
"@types/node": "^22.8.0",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
28
|
+
"@typescript-eslint/parser": "^8.8.0",
|
|
29
|
+
"chai": "^4.5.0",
|
|
30
|
+
"copyfiles": "^2.4.1",
|
|
31
|
+
"eslint": "^9.11.1",
|
|
32
|
+
"eslint-config-prettier": "^9.1.0",
|
|
33
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
34
|
+
"eslint-plugin-import": "^2.31.0",
|
|
35
|
+
"eslint-plugin-mocha": "^10.5.0",
|
|
36
|
+
"eslint-plugin-n": "^17.10.3",
|
|
37
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
38
|
+
"eslint-plugin-promise": "^7.1.0",
|
|
39
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
40
|
+
"globals": "^15.11.0",
|
|
41
|
+
"mocha": "^10.8.2",
|
|
42
|
+
"nyc": "^18.0.0",
|
|
43
|
+
"prettier": "^3.3.3",
|
|
44
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
45
|
+
"rimraf": "^6.0.1"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
49
|
+
"ethers": "^6.16.0",
|
|
50
|
+
"ts-node": "^10.9.2",
|
|
51
|
+
"typescript": "^5.6.2",
|
|
52
|
+
"@guardian-network/shared": "0.3.2"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "pnpm format:all:fix && tsc -p tsconfig-prod.json && pnpm copy-dts",
|
|
56
|
+
"check": "pnpm lint:ts && pnpm check:ts",
|
|
57
|
+
"check:ts": "tsc -p tsconfig-prod.json --noEmit",
|
|
58
|
+
"check:ts:dev": "tsc -p tsconfig.json --noEmit",
|
|
59
|
+
"clean": "pnpm remove:dist",
|
|
60
|
+
"copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" dist",
|
|
61
|
+
"format:all:fix": "pnpm format:ts:fix",
|
|
62
|
+
"format:ts:fix": "prettier -w -c \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
63
|
+
"lint:ts": "eslint",
|
|
64
|
+
"lint:ts:fix": "eslint --fix",
|
|
65
|
+
"publish-package": "pnpm publish --no-git-checks",
|
|
66
|
+
"remove:dist": "npx rimraf dist",
|
|
67
|
+
"test": "mocha",
|
|
68
|
+
"tests:coverage:ts": "nyc pnpm test",
|
|
69
|
+
"version": "pnpm version"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExecTypesDoNotMatchError,
|
|
3
|
+
InitTypesDoNotMatchError,
|
|
4
|
+
SubstitutionTypesDoNotMatchError,
|
|
5
|
+
} from './validation-errors';
|
|
6
|
+
|
|
7
|
+
export class ErrorFactory {
|
|
8
|
+
static initTypesNotMacth = (
|
|
9
|
+
...params: Parameters<typeof InitTypesDoNotMatchError.create>
|
|
10
|
+
) => {
|
|
11
|
+
return InitTypesDoNotMatchError.create(...params);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
static execTypesNotMacth = (
|
|
15
|
+
...params: Parameters<typeof ExecTypesDoNotMatchError.create>
|
|
16
|
+
) => {
|
|
17
|
+
return ExecTypesDoNotMatchError.create(...params);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
static substitutionTypesNotMatch = (
|
|
21
|
+
...params: Parameters<typeof SubstitutionTypesDoNotMatchError.create>
|
|
22
|
+
) => {
|
|
23
|
+
return SubstitutionTypesDoNotMatchError.create(...params);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ErrorFactory';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseError } from '@guardian-network/shared';
|
|
2
|
+
|
|
3
|
+
export class InitTypesDoNotMatchError extends BaseError {
|
|
4
|
+
static create = (
|
|
5
|
+
value: string,
|
|
6
|
+
onchainName: string,
|
|
7
|
+
onchainType: string,
|
|
8
|
+
offchainType: string,
|
|
9
|
+
) => {
|
|
10
|
+
const errorMessage = `Initialization value ${value} (onchain name: ${onchainName}) is not matched by type: \r\n Expected onchain: ${onchainType} \r\n Got from DSL: ${offchainType}`;
|
|
11
|
+
return this.build(errorMessage);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ExecTypesDoNotMatchError extends BaseError {
|
|
16
|
+
static create = (
|
|
17
|
+
value: string,
|
|
18
|
+
onchainName: string,
|
|
19
|
+
onchainType: string,
|
|
20
|
+
offchainType: string,
|
|
21
|
+
) => {
|
|
22
|
+
const errorMessage = `Execution value ${value} (onchain name: ${onchainName}) is not matched by type: \r\n Expected onchain: ${onchainType} \r\n Got from DSL: ${offchainType}`;
|
|
23
|
+
return this.build(errorMessage);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class SubstitutionTypesDoNotMatchError extends BaseError {
|
|
28
|
+
static create = (
|
|
29
|
+
selfInstanceId: string,
|
|
30
|
+
refInstanceId: string,
|
|
31
|
+
selfExecArgName: string,
|
|
32
|
+
selfExecArgType: string,
|
|
33
|
+
refInstanceReturnType: string,
|
|
34
|
+
) => {
|
|
35
|
+
const errorMessage = `Instance ${selfInstanceId} has exec argument ${selfExecArgName} of type ${selfExecArgType} that is being substituted with instance ${refInstanceId} of type ${refInstanceReturnType}`;
|
|
36
|
+
return this.build(errorMessage);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultAbiCoder,
|
|
3
|
+
DSLType,
|
|
4
|
+
SupportedSolidityType,
|
|
5
|
+
} from '@guardian-network/shared';
|
|
6
|
+
import { toTypedWithKnownType } from '.';
|
|
7
|
+
import { DSLTypesMapping } from '../parser/types';
|
|
8
|
+
|
|
9
|
+
export const bytesEncodeArgs = (
|
|
10
|
+
args: string[],
|
|
11
|
+
types: SupportedSolidityType[],
|
|
12
|
+
) => {
|
|
13
|
+
const typedArgs = args.map((arg, index) =>
|
|
14
|
+
toTypedWithKnownType(arg, types[index]),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return defaultAbiCoder.encode(types, typedArgs);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const indexConstants = (
|
|
21
|
+
parameters: { value: string; index: number }[],
|
|
22
|
+
argsTypes: SupportedSolidityType[],
|
|
23
|
+
) =>
|
|
24
|
+
parameters.map((arg, index) => ({
|
|
25
|
+
value: defaultAbiCoder.encode(
|
|
26
|
+
[argsTypes[index]],
|
|
27
|
+
[toTypedWithKnownType(arg.value, argsTypes[index])],
|
|
28
|
+
),
|
|
29
|
+
index: arg.index,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
export function extractComponents(input: string) {
|
|
33
|
+
const regex = /\{([^}]+)\}\s*\(([^)]*)\)\s*<([^>]*)>/;
|
|
34
|
+
const match = input.match(regex);
|
|
35
|
+
|
|
36
|
+
if (match && match.length === 4) {
|
|
37
|
+
const [, addressClause, paramsClause, initClause] = match;
|
|
38
|
+
return { addressClause, paramsClause, initClause };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error('Input string does not match the expected format.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function extractArguments(input: string): string[] {
|
|
45
|
+
if (input.trim() === '') {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return input.split(',').map((value) => value.trim());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function extractInjection(inputString: string): string {
|
|
53
|
+
const matcher = /\$"([^"]*)"$/;
|
|
54
|
+
const matched = inputString.match(matcher);
|
|
55
|
+
|
|
56
|
+
return matched ? matched[1] : '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const DSLTypesToIRTypes = (el: string) => {
|
|
60
|
+
// significantly un safe assertion
|
|
61
|
+
const typed = DSLTypesMapping[el as DSLType];
|
|
62
|
+
return typed;
|
|
63
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const strIsVar = (str: string): boolean => {
|
|
2
|
+
return /^var/.test(str);
|
|
3
|
+
};
|
|
4
|
+
export const strIsSubst = (str: string): boolean => {
|
|
5
|
+
return str[0] == '|' && str[str.length - 1] == '|';
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const isConstant = (arg: string): boolean => {
|
|
9
|
+
const regex = /^(?!var)(?!\|.*\|$).*/;
|
|
10
|
+
|
|
11
|
+
return regex.test(arg);
|
|
12
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SupportedSolidityType } from '@guardian-network/shared';
|
|
2
|
+
import { getAddress, getBytes } from 'ethers';
|
|
3
|
+
|
|
4
|
+
export const strToBool = (str: string): boolean => {
|
|
5
|
+
return str == 'true' ? true : false;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const toTypedWithKnownType = (
|
|
9
|
+
arg: string,
|
|
10
|
+
type: SupportedSolidityType,
|
|
11
|
+
) => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'address':
|
|
14
|
+
return getAddress(arg);
|
|
15
|
+
case 'bool':
|
|
16
|
+
return strToBool(arg);
|
|
17
|
+
case 'string':
|
|
18
|
+
return arg.replace(/^"(.*)"$/, '$1');
|
|
19
|
+
case 'bytes':
|
|
20
|
+
return getBytes(arg);
|
|
21
|
+
case 'uint256':
|
|
22
|
+
return BigInt(arg);
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`Unsupported constant value type: ${arg}: ${type}`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typing.validation';
|