@seljs/checker 1.3.0-beta.14 → 1.3.0-beta.18
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.
|
@@ -54,6 +54,19 @@ const registerIntegerOperators = (env) => {
|
|
|
54
54
|
if (divisor === 0n) throw new Error("modulo by zero");
|
|
55
55
|
return toSolInt((0, _seljs_types.toBigInt)(a) % divisor);
|
|
56
56
|
});
|
|
57
|
+
tryRegisterOperator(env, "int + sol_int: sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) + (0, _seljs_types.toBigInt)(b)));
|
|
58
|
+
tryRegisterOperator(env, "int - sol_int: sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) - (0, _seljs_types.toBigInt)(b)));
|
|
59
|
+
tryRegisterOperator(env, "int * sol_int: sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) * (0, _seljs_types.toBigInt)(b)));
|
|
60
|
+
tryRegisterOperator(env, "int / sol_int: sol_int", (a, b) => {
|
|
61
|
+
const divisor = (0, _seljs_types.toBigInt)(b);
|
|
62
|
+
if (divisor === 0n) throw new Error("division by zero");
|
|
63
|
+
return toSolInt((0, _seljs_types.toBigInt)(a) / divisor);
|
|
64
|
+
});
|
|
65
|
+
tryRegisterOperator(env, "int % sol_int: sol_int", (a, b) => {
|
|
66
|
+
const divisor = (0, _seljs_types.toBigInt)(b);
|
|
67
|
+
if (divisor === 0n) throw new Error("modulo by zero");
|
|
68
|
+
return toSolInt((0, _seljs_types.toBigInt)(a) % divisor);
|
|
69
|
+
});
|
|
57
70
|
tryRegisterOperator(env, "sol_int == int", (a, b) => (0, _seljs_types.toBigInt)(a) === (0, _seljs_types.toBigInt)(b));
|
|
58
71
|
tryRegisterOperator(env, "int == sol_int", (a, b) => (0, _seljs_types.toBigInt)(a) === (0, _seljs_types.toBigInt)(b));
|
|
59
72
|
tryRegisterOperator(env, "sol_int < int", (a, b) => (0, _seljs_types.toBigInt)(a) < (0, _seljs_types.toBigInt)(b));
|
|
@@ -78,11 +91,17 @@ const registerSolidityTypes = (env) => {
|
|
|
78
91
|
for (const sig of entry.castSignatures) env.registerFunction(sig, (value) => new Ctor(value));
|
|
79
92
|
}
|
|
80
93
|
env.registerFunction("parseUnits(string, int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
94
|
+
env.registerFunction("parseUnits(string, sol_int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
81
95
|
env.registerFunction("parseUnits(int, int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
96
|
+
env.registerFunction("parseUnits(int, sol_int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
82
97
|
env.registerFunction("parseUnits(double, int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
98
|
+
env.registerFunction("parseUnits(double, sol_int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
83
99
|
env.registerFunction("parseUnits(sol_int, int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
100
|
+
env.registerFunction("parseUnits(sol_int, sol_int): sol_int", (value, decimals) => (0, _seljs_types.parseUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
84
101
|
env.registerFunction("formatUnits(sol_int, int): double", (value, decimals) => (0, _seljs_types.formatUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
102
|
+
env.registerFunction("formatUnits(sol_int, sol_int): double", (value, decimals) => (0, _seljs_types.formatUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
85
103
|
env.registerFunction("formatUnits(int, int): double", (value, decimals) => (0, _seljs_types.formatUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
104
|
+
env.registerFunction("formatUnits(int, sol_int): double", (value, decimals) => (0, _seljs_types.formatUnitsValue)(value, Number((0, _seljs_types.toBigInt)(decimals))));
|
|
86
105
|
env.registerFunction("min(sol_int, sol_int): sol_int", (a, b) => (0, _seljs_types.toBigInt)(a) <= (0, _seljs_types.toBigInt)(b) ? toSolInt(a) : toSolInt(b));
|
|
87
106
|
env.registerFunction("min(sol_int, int): sol_int", (a, b) => (0, _seljs_types.toBigInt)(a) <= (0, _seljs_types.toBigInt)(b) ? toSolInt(a) : toSolInt(b));
|
|
88
107
|
env.registerFunction("min(int, sol_int): sol_int", (a, b) => (0, _seljs_types.toBigInt)(a) <= (0, _seljs_types.toBigInt)(b) ? toSolInt(a) : toSolInt(b));
|
|
@@ -102,6 +121,18 @@ const registerSolidityTypes = (env) => {
|
|
|
102
121
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
103
122
|
env.registerFunction("isZeroAddress(sol_address): bool", (addr) => (0, _seljs_types.toAddress)(addr) === ZERO_ADDRESS);
|
|
104
123
|
env.registerFunction("isZeroAddress(string): bool", (addr) => (0, _seljs_types.toAddress)(addr) === ZERO_ADDRESS);
|
|
124
|
+
class SelNamespace {}
|
|
125
|
+
const selFields = {};
|
|
126
|
+
const selValues = {};
|
|
127
|
+
for (const constant of _seljs_types.EVM_CONSTANTS) {
|
|
128
|
+
selFields[constant.name] = constant.type;
|
|
129
|
+
selValues[constant.name] = constant.type === "sol_int" ? new _seljs_types.SolidityIntTypeWrapper(constant.value) : new _seljs_types.SolidityAddressTypeWrapper(constant.value);
|
|
130
|
+
}
|
|
131
|
+
env.registerType("SelNamespace", {
|
|
132
|
+
ctor: SelNamespace,
|
|
133
|
+
fields: selFields
|
|
134
|
+
});
|
|
135
|
+
env.registerConstant("sel", "SelNamespace", Object.assign(new SelNamespace(), selValues));
|
|
105
136
|
};
|
|
106
137
|
//#endregion
|
|
107
138
|
exports.registerSolidityTypes = registerSolidityTypes;
|
|
@@ -6,7 +6,7 @@ import { Environment } from "@marcbachmann/cel-js";
|
|
|
6
6
|
* Mirrors the parameter signatures from Environment but drops the return type
|
|
7
7
|
* to void — registerSolidityTypes never chains the return value.
|
|
8
8
|
*/
|
|
9
|
-
type SolidityTypeHost = { [K in "registerType" | "registerOperator" | "registerFunction"]: (...args: Parameters<Environment[K]>) => void };
|
|
9
|
+
type SolidityTypeHost = { [K in "registerType" | "registerOperator" | "registerFunction" | "registerConstant"]: (...args: Parameters<Environment[K]>) => void };
|
|
10
10
|
/**
|
|
11
11
|
* Register all Solidity primitive types on a CEL Environment.
|
|
12
12
|
*/
|
|
@@ -6,7 +6,7 @@ import { Environment } from "@marcbachmann/cel-js";
|
|
|
6
6
|
* Mirrors the parameter signatures from Environment but drops the return type
|
|
7
7
|
* to void — registerSolidityTypes never chains the return value.
|
|
8
8
|
*/
|
|
9
|
-
type SolidityTypeHost = { [K in "registerType" | "registerOperator" | "registerFunction"]: (...args: Parameters<Environment[K]>) => void };
|
|
9
|
+
type SolidityTypeHost = { [K in "registerType" | "registerOperator" | "registerFunction" | "registerConstant"]: (...args: Parameters<Environment[K]>) => void };
|
|
10
10
|
/**
|
|
11
11
|
* Register all Solidity primitive types on a CEL Environment.
|
|
12
12
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SOLIDITY_TYPES, SolidityIntTypeWrapper, formatUnitsValue, parseUnitsValue, toAddress, toBigInt } from "@seljs/types";
|
|
1
|
+
import { EVM_CONSTANTS, SOLIDITY_TYPES, SolidityAddressTypeWrapper, SolidityIntTypeWrapper, formatUnitsValue, parseUnitsValue, toAddress, toBigInt } from "@seljs/types";
|
|
2
2
|
//#region src/environment/register-types.ts
|
|
3
3
|
/**
|
|
4
4
|
* Try to register an operator, silently ignoring "already registered" errors.
|
|
@@ -53,6 +53,19 @@ const registerIntegerOperators = (env) => {
|
|
|
53
53
|
if (divisor === 0n) throw new Error("modulo by zero");
|
|
54
54
|
return toSolInt(toBigInt(a) % divisor);
|
|
55
55
|
});
|
|
56
|
+
tryRegisterOperator(env, "int + sol_int: sol_int", (a, b) => toSolInt(toBigInt(a) + toBigInt(b)));
|
|
57
|
+
tryRegisterOperator(env, "int - sol_int: sol_int", (a, b) => toSolInt(toBigInt(a) - toBigInt(b)));
|
|
58
|
+
tryRegisterOperator(env, "int * sol_int: sol_int", (a, b) => toSolInt(toBigInt(a) * toBigInt(b)));
|
|
59
|
+
tryRegisterOperator(env, "int / sol_int: sol_int", (a, b) => {
|
|
60
|
+
const divisor = toBigInt(b);
|
|
61
|
+
if (divisor === 0n) throw new Error("division by zero");
|
|
62
|
+
return toSolInt(toBigInt(a) / divisor);
|
|
63
|
+
});
|
|
64
|
+
tryRegisterOperator(env, "int % sol_int: sol_int", (a, b) => {
|
|
65
|
+
const divisor = toBigInt(b);
|
|
66
|
+
if (divisor === 0n) throw new Error("modulo by zero");
|
|
67
|
+
return toSolInt(toBigInt(a) % divisor);
|
|
68
|
+
});
|
|
56
69
|
tryRegisterOperator(env, "sol_int == int", (a, b) => toBigInt(a) === toBigInt(b));
|
|
57
70
|
tryRegisterOperator(env, "int == sol_int", (a, b) => toBigInt(a) === toBigInt(b));
|
|
58
71
|
tryRegisterOperator(env, "sol_int < int", (a, b) => toBigInt(a) < toBigInt(b));
|
|
@@ -77,11 +90,17 @@ const registerSolidityTypes = (env) => {
|
|
|
77
90
|
for (const sig of entry.castSignatures) env.registerFunction(sig, (value) => new Ctor(value));
|
|
78
91
|
}
|
|
79
92
|
env.registerFunction("parseUnits(string, int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
93
|
+
env.registerFunction("parseUnits(string, sol_int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
80
94
|
env.registerFunction("parseUnits(int, int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
95
|
+
env.registerFunction("parseUnits(int, sol_int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
81
96
|
env.registerFunction("parseUnits(double, int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
97
|
+
env.registerFunction("parseUnits(double, sol_int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
82
98
|
env.registerFunction("parseUnits(sol_int, int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
99
|
+
env.registerFunction("parseUnits(sol_int, sol_int): sol_int", (value, decimals) => parseUnitsValue(value, Number(toBigInt(decimals))));
|
|
83
100
|
env.registerFunction("formatUnits(sol_int, int): double", (value, decimals) => formatUnitsValue(value, Number(toBigInt(decimals))));
|
|
101
|
+
env.registerFunction("formatUnits(sol_int, sol_int): double", (value, decimals) => formatUnitsValue(value, Number(toBigInt(decimals))));
|
|
84
102
|
env.registerFunction("formatUnits(int, int): double", (value, decimals) => formatUnitsValue(value, Number(toBigInt(decimals))));
|
|
103
|
+
env.registerFunction("formatUnits(int, sol_int): double", (value, decimals) => formatUnitsValue(value, Number(toBigInt(decimals))));
|
|
85
104
|
env.registerFunction("min(sol_int, sol_int): sol_int", (a, b) => toBigInt(a) <= toBigInt(b) ? toSolInt(a) : toSolInt(b));
|
|
86
105
|
env.registerFunction("min(sol_int, int): sol_int", (a, b) => toBigInt(a) <= toBigInt(b) ? toSolInt(a) : toSolInt(b));
|
|
87
106
|
env.registerFunction("min(int, sol_int): sol_int", (a, b) => toBigInt(a) <= toBigInt(b) ? toSolInt(a) : toSolInt(b));
|
|
@@ -101,6 +120,18 @@ const registerSolidityTypes = (env) => {
|
|
|
101
120
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
102
121
|
env.registerFunction("isZeroAddress(sol_address): bool", (addr) => toAddress(addr) === ZERO_ADDRESS);
|
|
103
122
|
env.registerFunction("isZeroAddress(string): bool", (addr) => toAddress(addr) === ZERO_ADDRESS);
|
|
123
|
+
class SelNamespace {}
|
|
124
|
+
const selFields = {};
|
|
125
|
+
const selValues = {};
|
|
126
|
+
for (const constant of EVM_CONSTANTS) {
|
|
127
|
+
selFields[constant.name] = constant.type;
|
|
128
|
+
selValues[constant.name] = constant.type === "sol_int" ? new SolidityIntTypeWrapper(constant.value) : new SolidityAddressTypeWrapper(constant.value);
|
|
129
|
+
}
|
|
130
|
+
env.registerType("SelNamespace", {
|
|
131
|
+
ctor: SelNamespace,
|
|
132
|
+
fields: selFields
|
|
133
|
+
});
|
|
134
|
+
env.registerConstant("sel", "SelNamespace", Object.assign(new SelNamespace(), selValues));
|
|
104
135
|
};
|
|
105
136
|
//#endregion
|
|
106
137
|
export { registerSolidityTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seljs/checker",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.18",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/abinnovision/seljs"
|
|
6
6
|
},
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@marcbachmann/cel-js": "^7.5.3",
|
|
53
|
-
"@seljs/common": "1.3.0-beta.
|
|
53
|
+
"@seljs/common": "1.3.0-beta.18",
|
|
54
54
|
"@seljs/schema": "1.2.0",
|
|
55
|
-
"@seljs/types": "1.3.0-beta.
|
|
55
|
+
"@seljs/types": "1.3.0-beta.18",
|
|
56
56
|
"debug": "^4.4.3"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|