@seljs/checker 1.3.0-beta.21 → 1.3.0-beta.27

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.
@@ -1,4 +1,5 @@
1
1
  require("../_virtual/_rolldown/runtime.cjs");
2
+ let _seljs_common = require("@seljs/common");
2
3
  let _seljs_types = require("@seljs/types");
3
4
  let viem = require("viem");
4
5
  //#region src/environment/register-types.ts
@@ -28,12 +29,12 @@ const registerIntegerOperators = (env) => {
28
29
  env.registerOperator("sol_int * sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) * (0, _seljs_types.toBigInt)(b)));
29
30
  env.registerOperator("sol_int / sol_int", (a, b) => {
30
31
  const divisor = (0, _seljs_types.toBigInt)(b);
31
- if (divisor === 0n) throw new Error("division by zero");
32
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("division by zero");
32
33
  return toSolInt((0, _seljs_types.toBigInt)(a) / divisor);
33
34
  });
34
35
  env.registerOperator("sol_int % sol_int", (a, b) => {
35
36
  const divisor = (0, _seljs_types.toBigInt)(b);
36
- if (divisor === 0n) throw new Error("modulo by zero");
37
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("modulo by zero");
37
38
  return toSolInt((0, _seljs_types.toBigInt)(a) % divisor);
38
39
  });
39
40
  env.registerOperator("-sol_int", (a) => toSolInt(-(0, _seljs_types.toBigInt)(a)));
@@ -47,12 +48,12 @@ const registerIntegerOperators = (env) => {
47
48
  tryRegisterOperator(env, "sol_int * int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) * (0, _seljs_types.toBigInt)(b)));
48
49
  tryRegisterOperator(env, "sol_int / int", (a, b) => {
49
50
  const divisor = (0, _seljs_types.toBigInt)(b);
50
- if (divisor === 0n) throw new Error("division by zero");
51
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("division by zero");
51
52
  return toSolInt((0, _seljs_types.toBigInt)(a) / divisor);
52
53
  });
53
54
  tryRegisterOperator(env, "sol_int % int", (a, b) => {
54
55
  const divisor = (0, _seljs_types.toBigInt)(b);
55
- if (divisor === 0n) throw new Error("modulo by zero");
56
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("modulo by zero");
56
57
  return toSolInt((0, _seljs_types.toBigInt)(a) % divisor);
57
58
  });
58
59
  tryRegisterOperator(env, "int + sol_int: sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) + (0, _seljs_types.toBigInt)(b)));
@@ -60,12 +61,12 @@ const registerIntegerOperators = (env) => {
60
61
  tryRegisterOperator(env, "int * sol_int: sol_int", (a, b) => toSolInt((0, _seljs_types.toBigInt)(a) * (0, _seljs_types.toBigInt)(b)));
61
62
  tryRegisterOperator(env, "int / sol_int: sol_int", (a, b) => {
62
63
  const divisor = (0, _seljs_types.toBigInt)(b);
63
- if (divisor === 0n) throw new Error("division by zero");
64
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("division by zero");
64
65
  return toSolInt((0, _seljs_types.toBigInt)(a) / divisor);
65
66
  });
66
67
  tryRegisterOperator(env, "int % sol_int: sol_int", (a, b) => {
67
68
  const divisor = (0, _seljs_types.toBigInt)(b);
68
- if (divisor === 0n) throw new Error("modulo by zero");
69
+ if (divisor === 0n) throw new _seljs_common.SELEvaluationError("modulo by zero");
69
70
  return toSolInt((0, _seljs_types.toBigInt)(a) % divisor);
70
71
  });
71
72
  tryRegisterOperator(env, "sol_int == int", (a, b) => (0, _seljs_types.toBigInt)(a) === (0, _seljs_types.toBigInt)(b));
@@ -119,6 +120,39 @@ const registerSolidityTypes = (env) => {
119
120
  const v = (0, _seljs_types.toBigInt)(a);
120
121
  return toSolInt(v < 0n ? -v : v);
121
122
  });
123
+ const registerListSolIntReducer = (name, handler) => {
124
+ env.registerFunction({
125
+ name,
126
+ receiverType: "list<sol_int>",
127
+ returnType: "sol_int",
128
+ params: []
129
+ }, handler);
130
+ };
131
+ registerListSolIntReducer("sum", (list) => {
132
+ let total = 0n;
133
+ for (const item of list) total += (0, _seljs_types.toBigInt)(item);
134
+ return toSolInt(total);
135
+ });
136
+ registerListSolIntReducer("min", (list) => {
137
+ const items = list;
138
+ if (items.length === 0) throw new Error("list<sol_int>.min(): list is empty");
139
+ let smallest = (0, _seljs_types.toBigInt)(items[0]);
140
+ for (let i = 1; i < items.length; i++) {
141
+ const v = (0, _seljs_types.toBigInt)(items[i]);
142
+ if (v < smallest) smallest = v;
143
+ }
144
+ return toSolInt(smallest);
145
+ });
146
+ registerListSolIntReducer("max", (list) => {
147
+ const items = list;
148
+ if (items.length === 0) throw new Error("list<sol_int>.max(): list is empty");
149
+ let largest = (0, _seljs_types.toBigInt)(items[0]);
150
+ for (let i = 1; i < items.length; i++) {
151
+ const v = (0, _seljs_types.toBigInt)(items[i]);
152
+ if (v > largest) largest = v;
153
+ }
154
+ return toSolInt(largest);
155
+ });
122
156
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
123
157
  env.registerFunction("isZeroAddress(sol_address): bool", (addr) => (0, _seljs_types.toAddress)(addr) === ZERO_ADDRESS);
124
158
  env.registerFunction("isZeroAddress(string): bool", (addr) => (0, _seljs_types.toAddress)(addr) === ZERO_ADDRESS);
@@ -126,7 +160,7 @@ const registerSolidityTypes = (env) => {
126
160
  env.registerFunction("hexBytes(string, int): bytes", (hex, length) => {
127
161
  const out = (0, _seljs_types.hexToBytes)(hex);
128
162
  const expected = Number((0, _seljs_types.toBigInt)(length));
129
- if (out.length !== expected) throw new Error(`hexBytes: expected ${String(expected)} bytes, got ${String(out.length)}`);
163
+ if (out.length !== expected) throw new _seljs_common.SELEvaluationError(`hexBytes: expected ${String(expected)} bytes, got ${String(out.length)}`);
130
164
  return out;
131
165
  });
132
166
  env.registerFunction("keccak256(string): bytes", (value) => (0, _seljs_types.hexToBytes)((0, viem.keccak256)((0, viem.toBytes)(value))));
@@ -1,3 +1,4 @@
1
+ import { SELEvaluationError } from "@seljs/common";
1
2
  import { EVM_CONSTANTS, SOLIDITY_TYPES, SolidityAddressTypeWrapper, SolidityIntTypeWrapper, formatUnitsValue, hexToBytes, parseUnitsValue, toAddress, toBigInt } from "@seljs/types";
2
3
  import { keccak256, toBytes } from "viem";
3
4
  //#region src/environment/register-types.ts
@@ -27,12 +28,12 @@ const registerIntegerOperators = (env) => {
27
28
  env.registerOperator("sol_int * sol_int", (a, b) => toSolInt(toBigInt(a) * toBigInt(b)));
28
29
  env.registerOperator("sol_int / sol_int", (a, b) => {
29
30
  const divisor = toBigInt(b);
30
- if (divisor === 0n) throw new Error("division by zero");
31
+ if (divisor === 0n) throw new SELEvaluationError("division by zero");
31
32
  return toSolInt(toBigInt(a) / divisor);
32
33
  });
33
34
  env.registerOperator("sol_int % sol_int", (a, b) => {
34
35
  const divisor = toBigInt(b);
35
- if (divisor === 0n) throw new Error("modulo by zero");
36
+ if (divisor === 0n) throw new SELEvaluationError("modulo by zero");
36
37
  return toSolInt(toBigInt(a) % divisor);
37
38
  });
38
39
  env.registerOperator("-sol_int", (a) => toSolInt(-toBigInt(a)));
@@ -46,12 +47,12 @@ const registerIntegerOperators = (env) => {
46
47
  tryRegisterOperator(env, "sol_int * int", (a, b) => toSolInt(toBigInt(a) * toBigInt(b)));
47
48
  tryRegisterOperator(env, "sol_int / int", (a, b) => {
48
49
  const divisor = toBigInt(b);
49
- if (divisor === 0n) throw new Error("division by zero");
50
+ if (divisor === 0n) throw new SELEvaluationError("division by zero");
50
51
  return toSolInt(toBigInt(a) / divisor);
51
52
  });
52
53
  tryRegisterOperator(env, "sol_int % int", (a, b) => {
53
54
  const divisor = toBigInt(b);
54
- if (divisor === 0n) throw new Error("modulo by zero");
55
+ if (divisor === 0n) throw new SELEvaluationError("modulo by zero");
55
56
  return toSolInt(toBigInt(a) % divisor);
56
57
  });
57
58
  tryRegisterOperator(env, "int + sol_int: sol_int", (a, b) => toSolInt(toBigInt(a) + toBigInt(b)));
@@ -59,12 +60,12 @@ const registerIntegerOperators = (env) => {
59
60
  tryRegisterOperator(env, "int * sol_int: sol_int", (a, b) => toSolInt(toBigInt(a) * toBigInt(b)));
60
61
  tryRegisterOperator(env, "int / sol_int: sol_int", (a, b) => {
61
62
  const divisor = toBigInt(b);
62
- if (divisor === 0n) throw new Error("division by zero");
63
+ if (divisor === 0n) throw new SELEvaluationError("division by zero");
63
64
  return toSolInt(toBigInt(a) / divisor);
64
65
  });
65
66
  tryRegisterOperator(env, "int % sol_int: sol_int", (a, b) => {
66
67
  const divisor = toBigInt(b);
67
- if (divisor === 0n) throw new Error("modulo by zero");
68
+ if (divisor === 0n) throw new SELEvaluationError("modulo by zero");
68
69
  return toSolInt(toBigInt(a) % divisor);
69
70
  });
70
71
  tryRegisterOperator(env, "sol_int == int", (a, b) => toBigInt(a) === toBigInt(b));
@@ -118,6 +119,39 @@ const registerSolidityTypes = (env) => {
118
119
  const v = toBigInt(a);
119
120
  return toSolInt(v < 0n ? -v : v);
120
121
  });
122
+ const registerListSolIntReducer = (name, handler) => {
123
+ env.registerFunction({
124
+ name,
125
+ receiverType: "list<sol_int>",
126
+ returnType: "sol_int",
127
+ params: []
128
+ }, handler);
129
+ };
130
+ registerListSolIntReducer("sum", (list) => {
131
+ let total = 0n;
132
+ for (const item of list) total += toBigInt(item);
133
+ return toSolInt(total);
134
+ });
135
+ registerListSolIntReducer("min", (list) => {
136
+ const items = list;
137
+ if (items.length === 0) throw new Error("list<sol_int>.min(): list is empty");
138
+ let smallest = toBigInt(items[0]);
139
+ for (let i = 1; i < items.length; i++) {
140
+ const v = toBigInt(items[i]);
141
+ if (v < smallest) smallest = v;
142
+ }
143
+ return toSolInt(smallest);
144
+ });
145
+ registerListSolIntReducer("max", (list) => {
146
+ const items = list;
147
+ if (items.length === 0) throw new Error("list<sol_int>.max(): list is empty");
148
+ let largest = toBigInt(items[0]);
149
+ for (let i = 1; i < items.length; i++) {
150
+ const v = toBigInt(items[i]);
151
+ if (v > largest) largest = v;
152
+ }
153
+ return toSolInt(largest);
154
+ });
121
155
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
122
156
  env.registerFunction("isZeroAddress(sol_address): bool", (addr) => toAddress(addr) === ZERO_ADDRESS);
123
157
  env.registerFunction("isZeroAddress(string): bool", (addr) => toAddress(addr) === ZERO_ADDRESS);
@@ -125,7 +159,7 @@ const registerSolidityTypes = (env) => {
125
159
  env.registerFunction("hexBytes(string, int): bytes", (hex, length) => {
126
160
  const out = hexToBytes(hex);
127
161
  const expected = Number(toBigInt(length));
128
- if (out.length !== expected) throw new Error(`hexBytes: expected ${String(expected)} bytes, got ${String(out.length)}`);
162
+ if (out.length !== expected) throw new SELEvaluationError(`hexBytes: expected ${String(expected)} bytes, got ${String(out.length)}`);
129
163
  return out;
130
164
  });
131
165
  env.registerFunction("keccak256(string): bytes", (value) => hexToBytes(keccak256(toBytes(value))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/checker",
3
- "version": "1.3.0-beta.21",
3
+ "version": "1.3.0-beta.27",
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.21",
53
+ "@seljs/common": "1.3.0-beta.27",
54
54
  "@seljs/schema": "1.2.0",
55
- "@seljs/types": "1.3.0-beta.21",
55
+ "@seljs/types": "1.3.0-beta.27",
56
56
  "debug": "^4.4.3",
57
57
  "viem": "^2.47.6"
58
58
  },