@strkfarm/sdk 2.0.0-dev.27 → 2.0.0-dev.28

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 (70) hide show
  1. package/dist/cli.js +190 -36
  2. package/dist/cli.mjs +188 -34
  3. package/dist/index.browser.global.js +79130 -49357
  4. package/dist/index.browser.mjs +18039 -11434
  5. package/dist/index.d.ts +2869 -898
  6. package/dist/index.js +19036 -12210
  7. package/dist/index.mjs +18942 -12161
  8. package/package.json +1 -1
  9. package/src/data/avnu.abi.json +840 -0
  10. package/src/data/ekubo-price-fethcer.abi.json +265 -0
  11. package/src/dataTypes/_bignumber.ts +13 -4
  12. package/src/dataTypes/index.ts +3 -2
  13. package/src/dataTypes/mynumber.ts +141 -0
  14. package/src/global.ts +76 -41
  15. package/src/index.browser.ts +2 -1
  16. package/src/interfaces/common.tsx +167 -2
  17. package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
  18. package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
  19. package/src/modules/apollo-client-config.ts +28 -0
  20. package/src/modules/avnu.ts +4 -4
  21. package/src/modules/ekubo-pricer.ts +79 -0
  22. package/src/modules/ekubo-quoter.ts +46 -30
  23. package/src/modules/erc20.ts +17 -0
  24. package/src/modules/harvests.ts +43 -29
  25. package/src/modules/pragma.ts +23 -8
  26. package/src/modules/pricer-from-api.ts +156 -15
  27. package/src/modules/pricer-lst.ts +1 -1
  28. package/src/modules/pricer.ts +40 -4
  29. package/src/modules/pricerBase.ts +2 -1
  30. package/src/node/deployer.ts +36 -1
  31. package/src/node/pricer-redis.ts +2 -1
  32. package/src/strategies/base-strategy.ts +78 -10
  33. package/src/strategies/ekubo-cl-vault.tsx +906 -347
  34. package/src/strategies/factory.ts +159 -0
  35. package/src/strategies/index.ts +6 -1
  36. package/src/strategies/registry.ts +239 -0
  37. package/src/strategies/sensei.ts +335 -7
  38. package/src/strategies/svk-strategy.ts +97 -27
  39. package/src/strategies/types.ts +4 -0
  40. package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
  41. package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
  42. package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
  43. package/src/strategies/universal-adapters/common-adapter.ts +206 -203
  44. package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
  45. package/src/strategies/universal-adapters/index.ts +9 -8
  46. package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
  47. package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
  48. package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
  49. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
  50. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
  51. package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
  52. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
  53. package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
  54. package/src/strategies/universal-strategy.tsx +1426 -1178
  55. package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
  56. package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
  57. package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
  58. package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
  59. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
  60. package/src/strategies/vesu-extended-strategy/utils/constants.ts +2 -0
  61. package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
  62. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1788
  63. package/src/strategies/vesu-rebalance.tsx +255 -152
  64. package/src/utils/health-factor-math.ts +4 -1
  65. package/src/utils/index.ts +2 -1
  66. package/src/utils/logger.browser.ts +22 -4
  67. package/src/utils/logger.node.ts +259 -24
  68. package/src/utils/starknet-call-parser.ts +1036 -0
  69. package/src/utils/strategy-utils.ts +61 -0
  70. package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
package/dist/cli.js CHANGED
@@ -28,7 +28,7 @@ var import_commander = require("commander");
28
28
  var import_inquirer = __toESM(require("inquirer"));
29
29
 
30
30
  // src/utils/store.ts
31
- var import_fs = __toESM(require("fs"));
31
+ var import_fs2 = __toESM(require("fs"));
32
32
  var import_starknet = require("starknet");
33
33
  var crypto2 = __toESM(require("crypto"));
34
34
 
@@ -82,41 +82,195 @@ var PasswordJsonCryptoUtil = class {
82
82
  };
83
83
 
84
84
  // src/utils/logger.node.ts
85
+ var import_fs = __toESM(require("fs"));
86
+ var import_path = __toESM(require("path"));
85
87
  var import_winston = __toESM(require("winston"));
86
88
  var colors = {
87
89
  error: "red",
88
90
  warn: "yellow",
89
91
  info: "blue",
90
- verbose: "white",
91
- debug: "white"
92
+ verbose: "cyan",
93
+ debug: "gray"
92
94
  };
93
95
  import_winston.default.addColors(colors);
94
- var logger = import_winston.default.createLogger({
95
- level: "debug",
96
- // Set the minimum logging level
97
- format: import_winston.format.combine(
98
- import_winston.format.colorize({ all: true }),
99
- // Apply custom colors
100
- import_winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
101
- // Add timestamp to log messages
102
- import_winston.format.printf(({ timestamp, level, message, ...meta }) => {
103
- let msg = `${timestamp} ${level}: ${message}`;
104
- if (meta && meta[Symbol.for("splat")]) {
105
- for (const arg of meta[Symbol.for("splat")]) {
106
- if (arg instanceof Error) {
107
- msg += `
108
- ${arg.stack}`;
109
- }
110
- }
96
+ var stringifyUnknown = (value) => {
97
+ if (typeof value === "string") return value;
98
+ if (typeof value === "undefined") return "undefined";
99
+ if (value === null) return "null";
100
+ if (value instanceof Error) return value.message || value.name || "Error";
101
+ try {
102
+ const encoded = JSON.stringify(
103
+ value,
104
+ (_, v) => typeof v === "bigint" ? v.toString() : v
105
+ );
106
+ return encoded ?? String(value);
107
+ } catch {
108
+ return String(value);
109
+ }
110
+ };
111
+ var stripAnsi = (text) => stringifyUnknown(text).replace(/\u001b\[[0-9;]*m/g, "");
112
+ var escapeValue = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
113
+ var escapeMessageValue = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, "'").replace(/\n/g, "\\n");
114
+ var ANSI = {
115
+ reset: "\x1B[0m",
116
+ red: "\x1B[31m",
117
+ yellow: "\x1B[33m",
118
+ green: "\x1B[32m"
119
+ };
120
+ var paint = (text, color) => `${color}${text}${ANSI.reset}`;
121
+ var highlightRoutes = (text) => text.replace(/\b[A-Z][A-Z0-9_]{2,}\b/g, (token) => paint(token, ANSI.yellow));
122
+ var highlightCases = (text) => text.replace(/\[[A-Z][A-Z0-9_]+\]/g, (token) => paint(token, ANSI.green));
123
+ var colorizeMessageForConsole = (message) => {
124
+ const hasExtendedTradeContext = /\bEXTENDED_(LIMIT|MARKET)_(BUY|SELL)\b/.test(message) || /\bEXTENDED_(INCREASE|DECREASE)_LEVER\b/.test(message);
125
+ if (hasExtendedTradeContext && /\b(SUCCESS|SUCCEEDED|FILLED)\b/i.test(message)) {
126
+ return paint(highlightRoutes(message), ANSI.green);
127
+ }
128
+ if (hasExtendedTradeContext && /\b(INITIATED|PENDING|SUBMITTED|RETRY|PARTIAL)\b/i.test(message)) {
129
+ return paint(highlightRoutes(message), ANSI.yellow);
130
+ }
131
+ if (/\b(fail|failed|failure|error)\b/i.test(message)) {
132
+ return paint(highlightRoutes(highlightCases(message)), ANSI.red);
133
+ }
134
+ if (/Transaction sent/i.test(message)) {
135
+ return paint(message, ANSI.yellow);
136
+ }
137
+ if (/Transaction succeeded/i.test(message)) {
138
+ return paint(message, ANSI.green);
139
+ }
140
+ if (/Detected \d+ case\(s\)/i.test(message)) {
141
+ return paint(highlightRoutes(highlightCases(message)), ANSI.green);
142
+ }
143
+ if (/_executeStandardCase route/i.test(message)) {
144
+ return paint(highlightRoutes(message), ANSI.green);
145
+ }
146
+ if (/\broute\b/i.test(message)) {
147
+ return highlightRoutes(message);
148
+ }
149
+ return message;
150
+ };
151
+ var FIXED_TAG_WIDTH = 10;
152
+ var toFixedTag = (rawTag) => {
153
+ const compact = rawTag.replace(/[^A-Za-z0-9_-]/g, "");
154
+ if (!compact) return "general".slice(0, FIXED_TAG_WIDTH).padEnd(FIXED_TAG_WIDTH, " ");
155
+ return compact.slice(0, FIXED_TAG_WIDTH).padEnd(FIXED_TAG_WIDTH, " ");
156
+ };
157
+ var extractTagAndMessage = (rawMessage) => {
158
+ const normalized = stripAnsi(rawMessage).trim();
159
+ const bracketTagMatch = normalized.match(/^\[([^\]]+)\]\s*(.*)$/);
160
+ if (bracketTagMatch) {
161
+ return {
162
+ tag: toFixedTag(bracketTagMatch[1]),
163
+ body: bracketTagMatch[2] || normalized
164
+ };
165
+ }
166
+ const scopeTagMatch = normalized.match(/^([A-Za-z0-9_-]+)::\s*(.*)$/);
167
+ if (scopeTagMatch) {
168
+ return {
169
+ tag: toFixedTag(scopeTagMatch[1]),
170
+ body: scopeTagMatch[2] || normalized
171
+ };
172
+ }
173
+ return {
174
+ tag: toFixedTag("general"),
175
+ body: normalized
176
+ };
177
+ };
178
+ var getStackFromMeta = (stack, meta) => {
179
+ if (typeof stack === "string" && stack.length > 0) {
180
+ return stack;
181
+ }
182
+ const splat = meta[Symbol.for("splat")];
183
+ if (Array.isArray(splat)) {
184
+ for (const item of splat) {
185
+ if (item instanceof Error && item.stack) {
186
+ return item.stack;
111
187
  }
112
- return msg;
113
- })
114
- ),
115
- transports: [
116
- new import_winston.default.transports.Console()
117
- // Output logs to the console
118
- ]
188
+ }
189
+ }
190
+ return void 0;
191
+ };
192
+ var DEFAULT_LEVEL = (process.env.LOG_LEVEL || process.env.SDK_LOG_LEVEL || "debug").toLowerCase();
193
+ var DEFAULT_CONSOLE_LEVEL = (process.env.LOG_CONSOLE_LEVEL || "info").toLowerCase();
194
+ var DEFAULT_FILE_LEVEL = (process.env.LOG_FILE_LEVEL || DEFAULT_LEVEL).toLowerCase();
195
+ var DEFAULT_FILE_PATH = process.env.LOG_FILE_PATH;
196
+ var logger = import_winston.default.createLogger({
197
+ level: DEFAULT_LEVEL,
198
+ transports: []
119
199
  });
200
+ function configureLogger(config = {}) {
201
+ const level = config.level ?? DEFAULT_LEVEL;
202
+ const consoleLevel = config.consoleLevel ?? DEFAULT_CONSOLE_LEVEL;
203
+ const fileLevel = config.fileLevel ?? DEFAULT_FILE_LEVEL;
204
+ const filePath = config.filePath ?? DEFAULT_FILE_PATH;
205
+ const enableConsole = config.enableConsole ?? true;
206
+ const enableFile = config.enableFile ?? Boolean(filePath);
207
+ const colorizeConsole = config.colorizeConsole ?? true;
208
+ const shortErrorsInConsole = config.shortErrorsInConsole ?? true;
209
+ const emitConfigLog = config.emitConfigLog ?? false;
210
+ logger.clear();
211
+ logger.level = level;
212
+ if (enableConsole) {
213
+ logger.add(
214
+ new import_winston.default.transports.Console({
215
+ level: consoleLevel,
216
+ format: import_winston.format.combine(
217
+ colorizeConsole ? import_winston.format.colorize({ level: true }) : import_winston.format.uncolorize(),
218
+ import_winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
219
+ import_winston.format.errors({ stack: true }),
220
+ import_winston.format.printf(({ timestamp, level: level2, message, stack, ...meta }) => {
221
+ const baseMessage = stringifyUnknown(message);
222
+ const { tag, body } = extractTagAndMessage(baseMessage);
223
+ const consoleBody = colorizeConsole ? colorizeMessageForConsole(body) : body;
224
+ let out = `ts="${timestamp}" level=${stringifyUnknown(level2)} [${tag}] msg="${escapeMessageValue(consoleBody)}"`;
225
+ if (!shortErrorsInConsole) {
226
+ const derivedStack = getStackFromMeta(stack, meta);
227
+ if (derivedStack) {
228
+ out += ` stack="${escapeValue(derivedStack)}"`;
229
+ }
230
+ }
231
+ return out;
232
+ })
233
+ )
234
+ })
235
+ );
236
+ }
237
+ if (enableFile && filePath) {
238
+ import_fs.default.mkdirSync(import_path.default.dirname(filePath), { recursive: true });
239
+ logger.add(
240
+ new import_winston.default.transports.File({
241
+ filename: filePath,
242
+ level: fileLevel,
243
+ format: import_winston.format.combine(
244
+ import_winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
245
+ import_winston.format.errors({ stack: true }),
246
+ import_winston.format.printf(({ timestamp, level: level2, message, stack, ...meta }) => {
247
+ const parsedMessage = stringifyUnknown(message);
248
+ const normalizedMessage = stripAnsi(parsedMessage);
249
+ const { tag, body } = extractTagAndMessage(normalizedMessage);
250
+ let out = `ts="${timestamp}" level=${stripAnsi(level2)} [${tag}] msg="${escapeMessageValue(body)}"`;
251
+ const derivedStack = getStackFromMeta(stack, meta);
252
+ if (derivedStack) {
253
+ out += ` stack="${escapeValue(stripAnsi(derivedStack))}"`;
254
+ }
255
+ const metaCopy = { ...meta };
256
+ delete metaCopy[Symbol.for("splat")];
257
+ if (Object.keys(metaCopy).length > 0) {
258
+ out += ` meta=${escapeValue(stringifyUnknown(metaCopy))}`;
259
+ }
260
+ return out;
261
+ })
262
+ )
263
+ })
264
+ );
265
+ }
266
+ if (emitConfigLog) {
267
+ logger.info(
268
+ `[Logger] configured level=${level} console=${enableConsole ? consoleLevel : "off"} file=${enableFile ? fileLevel : "off"}${filePath ? ` path=${filePath}` : ""}`
269
+ );
270
+ }
271
+ return logger;
272
+ }
273
+ configureLogger();
120
274
 
121
275
  // src/utils/store.ts
122
276
  function getDefaultStoreConfig(network) {
@@ -179,21 +333,21 @@ var Store = class _Store {
179
333
  pk
180
334
  };
181
335
  const encryptedData = this.encryptor.encrypt(allAccounts, this.storeConfig.PASSWORD);
182
- (0, import_fs.writeFileSync)(this.getAccountFilePath(), encryptedData);
336
+ (0, import_fs2.writeFileSync)(this.getAccountFilePath(), encryptedData);
183
337
  logger.verbose(`Account added: ${accountKey} to network: ${this.config.network}`);
184
338
  }
185
339
  getAccountFilePath() {
186
- const path = `${this.storeConfig.SECRET_FILE_FOLDER}/${this.storeConfig.ACCOUNTS_FILE_NAME}`;
187
- logger.verbose(`Path: ${path}`);
188
- return path;
340
+ const path2 = `${this.storeConfig.SECRET_FILE_FOLDER}/${this.storeConfig.ACCOUNTS_FILE_NAME}`;
341
+ logger.verbose(`Path: ${path2}`);
342
+ return path2;
189
343
  }
190
344
  getAllAccounts() {
191
345
  const PATH = this.getAccountFilePath();
192
- if (!import_fs.default.existsSync(PATH)) {
346
+ if (!import_fs2.default.existsSync(PATH)) {
193
347
  logger.verbose(`Accounts: files doesnt exist`);
194
348
  return {};
195
349
  }
196
- let encryptedData = (0, import_fs.readFileSync)(PATH, {
350
+ let encryptedData = (0, import_fs2.readFileSync)(PATH, {
197
351
  encoding: "utf-8"
198
352
  });
199
353
  let data = this.encryptor.decrypt(encryptedData, this.storeConfig.PASSWORD);
@@ -219,10 +373,10 @@ var Store = class _Store {
219
373
  return Object.keys(this.loadAccounts());
220
374
  }
221
375
  static ensureFolder(folder) {
222
- if (!import_fs.default.existsSync(folder)) {
223
- import_fs.default.mkdirSync(folder, { recursive: true });
376
+ if (!import_fs2.default.existsSync(folder)) {
377
+ import_fs2.default.mkdirSync(folder, { recursive: true });
224
378
  }
225
- if (!import_fs.default.existsSync(`${folder}`)) {
379
+ if (!import_fs2.default.existsSync(`${folder}`)) {
226
380
  throw new Error(`Store folder not found: ${folder}`);
227
381
  }
228
382
  }
package/dist/cli.mjs CHANGED
@@ -5,7 +5,7 @@ import { Command } from "commander";
5
5
  import inquirer from "inquirer";
6
6
 
7
7
  // src/utils/store.ts
8
- import fs, { readFileSync, writeFileSync } from "fs";
8
+ import fs2, { readFileSync, writeFileSync } from "fs";
9
9
  import { Account } from "starknet";
10
10
  import * as crypto2 from "crypto";
11
11
 
@@ -59,41 +59,195 @@ var PasswordJsonCryptoUtil = class {
59
59
  };
60
60
 
61
61
  // src/utils/logger.node.ts
62
+ import fs from "fs";
63
+ import path from "path";
62
64
  import winston, { format } from "winston";
63
65
  var colors = {
64
66
  error: "red",
65
67
  warn: "yellow",
66
68
  info: "blue",
67
- verbose: "white",
68
- debug: "white"
69
+ verbose: "cyan",
70
+ debug: "gray"
69
71
  };
70
72
  winston.addColors(colors);
71
- var logger = winston.createLogger({
72
- level: "debug",
73
- // Set the minimum logging level
74
- format: format.combine(
75
- format.colorize({ all: true }),
76
- // Apply custom colors
77
- format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
78
- // Add timestamp to log messages
79
- format.printf(({ timestamp, level, message, ...meta }) => {
80
- let msg = `${timestamp} ${level}: ${message}`;
81
- if (meta && meta[Symbol.for("splat")]) {
82
- for (const arg of meta[Symbol.for("splat")]) {
83
- if (arg instanceof Error) {
84
- msg += `
85
- ${arg.stack}`;
86
- }
87
- }
73
+ var stringifyUnknown = (value) => {
74
+ if (typeof value === "string") return value;
75
+ if (typeof value === "undefined") return "undefined";
76
+ if (value === null) return "null";
77
+ if (value instanceof Error) return value.message || value.name || "Error";
78
+ try {
79
+ const encoded = JSON.stringify(
80
+ value,
81
+ (_, v) => typeof v === "bigint" ? v.toString() : v
82
+ );
83
+ return encoded ?? String(value);
84
+ } catch {
85
+ return String(value);
86
+ }
87
+ };
88
+ var stripAnsi = (text) => stringifyUnknown(text).replace(/\u001b\[[0-9;]*m/g, "");
89
+ var escapeValue = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
90
+ var escapeMessageValue = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, "'").replace(/\n/g, "\\n");
91
+ var ANSI = {
92
+ reset: "\x1B[0m",
93
+ red: "\x1B[31m",
94
+ yellow: "\x1B[33m",
95
+ green: "\x1B[32m"
96
+ };
97
+ var paint = (text, color) => `${color}${text}${ANSI.reset}`;
98
+ var highlightRoutes = (text) => text.replace(/\b[A-Z][A-Z0-9_]{2,}\b/g, (token) => paint(token, ANSI.yellow));
99
+ var highlightCases = (text) => text.replace(/\[[A-Z][A-Z0-9_]+\]/g, (token) => paint(token, ANSI.green));
100
+ var colorizeMessageForConsole = (message) => {
101
+ const hasExtendedTradeContext = /\bEXTENDED_(LIMIT|MARKET)_(BUY|SELL)\b/.test(message) || /\bEXTENDED_(INCREASE|DECREASE)_LEVER\b/.test(message);
102
+ if (hasExtendedTradeContext && /\b(SUCCESS|SUCCEEDED|FILLED)\b/i.test(message)) {
103
+ return paint(highlightRoutes(message), ANSI.green);
104
+ }
105
+ if (hasExtendedTradeContext && /\b(INITIATED|PENDING|SUBMITTED|RETRY|PARTIAL)\b/i.test(message)) {
106
+ return paint(highlightRoutes(message), ANSI.yellow);
107
+ }
108
+ if (/\b(fail|failed|failure|error)\b/i.test(message)) {
109
+ return paint(highlightRoutes(highlightCases(message)), ANSI.red);
110
+ }
111
+ if (/Transaction sent/i.test(message)) {
112
+ return paint(message, ANSI.yellow);
113
+ }
114
+ if (/Transaction succeeded/i.test(message)) {
115
+ return paint(message, ANSI.green);
116
+ }
117
+ if (/Detected \d+ case\(s\)/i.test(message)) {
118
+ return paint(highlightRoutes(highlightCases(message)), ANSI.green);
119
+ }
120
+ if (/_executeStandardCase route/i.test(message)) {
121
+ return paint(highlightRoutes(message), ANSI.green);
122
+ }
123
+ if (/\broute\b/i.test(message)) {
124
+ return highlightRoutes(message);
125
+ }
126
+ return message;
127
+ };
128
+ var FIXED_TAG_WIDTH = 10;
129
+ var toFixedTag = (rawTag) => {
130
+ const compact = rawTag.replace(/[^A-Za-z0-9_-]/g, "");
131
+ if (!compact) return "general".slice(0, FIXED_TAG_WIDTH).padEnd(FIXED_TAG_WIDTH, " ");
132
+ return compact.slice(0, FIXED_TAG_WIDTH).padEnd(FIXED_TAG_WIDTH, " ");
133
+ };
134
+ var extractTagAndMessage = (rawMessage) => {
135
+ const normalized = stripAnsi(rawMessage).trim();
136
+ const bracketTagMatch = normalized.match(/^\[([^\]]+)\]\s*(.*)$/);
137
+ if (bracketTagMatch) {
138
+ return {
139
+ tag: toFixedTag(bracketTagMatch[1]),
140
+ body: bracketTagMatch[2] || normalized
141
+ };
142
+ }
143
+ const scopeTagMatch = normalized.match(/^([A-Za-z0-9_-]+)::\s*(.*)$/);
144
+ if (scopeTagMatch) {
145
+ return {
146
+ tag: toFixedTag(scopeTagMatch[1]),
147
+ body: scopeTagMatch[2] || normalized
148
+ };
149
+ }
150
+ return {
151
+ tag: toFixedTag("general"),
152
+ body: normalized
153
+ };
154
+ };
155
+ var getStackFromMeta = (stack, meta) => {
156
+ if (typeof stack === "string" && stack.length > 0) {
157
+ return stack;
158
+ }
159
+ const splat = meta[Symbol.for("splat")];
160
+ if (Array.isArray(splat)) {
161
+ for (const item of splat) {
162
+ if (item instanceof Error && item.stack) {
163
+ return item.stack;
88
164
  }
89
- return msg;
90
- })
91
- ),
92
- transports: [
93
- new winston.transports.Console()
94
- // Output logs to the console
95
- ]
165
+ }
166
+ }
167
+ return void 0;
168
+ };
169
+ var DEFAULT_LEVEL = (process.env.LOG_LEVEL || process.env.SDK_LOG_LEVEL || "debug").toLowerCase();
170
+ var DEFAULT_CONSOLE_LEVEL = (process.env.LOG_CONSOLE_LEVEL || "info").toLowerCase();
171
+ var DEFAULT_FILE_LEVEL = (process.env.LOG_FILE_LEVEL || DEFAULT_LEVEL).toLowerCase();
172
+ var DEFAULT_FILE_PATH = process.env.LOG_FILE_PATH;
173
+ var logger = winston.createLogger({
174
+ level: DEFAULT_LEVEL,
175
+ transports: []
96
176
  });
177
+ function configureLogger(config = {}) {
178
+ const level = config.level ?? DEFAULT_LEVEL;
179
+ const consoleLevel = config.consoleLevel ?? DEFAULT_CONSOLE_LEVEL;
180
+ const fileLevel = config.fileLevel ?? DEFAULT_FILE_LEVEL;
181
+ const filePath = config.filePath ?? DEFAULT_FILE_PATH;
182
+ const enableConsole = config.enableConsole ?? true;
183
+ const enableFile = config.enableFile ?? Boolean(filePath);
184
+ const colorizeConsole = config.colorizeConsole ?? true;
185
+ const shortErrorsInConsole = config.shortErrorsInConsole ?? true;
186
+ const emitConfigLog = config.emitConfigLog ?? false;
187
+ logger.clear();
188
+ logger.level = level;
189
+ if (enableConsole) {
190
+ logger.add(
191
+ new winston.transports.Console({
192
+ level: consoleLevel,
193
+ format: format.combine(
194
+ colorizeConsole ? format.colorize({ level: true }) : format.uncolorize(),
195
+ format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
196
+ format.errors({ stack: true }),
197
+ format.printf(({ timestamp, level: level2, message, stack, ...meta }) => {
198
+ const baseMessage = stringifyUnknown(message);
199
+ const { tag, body } = extractTagAndMessage(baseMessage);
200
+ const consoleBody = colorizeConsole ? colorizeMessageForConsole(body) : body;
201
+ let out = `ts="${timestamp}" level=${stringifyUnknown(level2)} [${tag}] msg="${escapeMessageValue(consoleBody)}"`;
202
+ if (!shortErrorsInConsole) {
203
+ const derivedStack = getStackFromMeta(stack, meta);
204
+ if (derivedStack) {
205
+ out += ` stack="${escapeValue(derivedStack)}"`;
206
+ }
207
+ }
208
+ return out;
209
+ })
210
+ )
211
+ })
212
+ );
213
+ }
214
+ if (enableFile && filePath) {
215
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
216
+ logger.add(
217
+ new winston.transports.File({
218
+ filename: filePath,
219
+ level: fileLevel,
220
+ format: format.combine(
221
+ format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
222
+ format.errors({ stack: true }),
223
+ format.printf(({ timestamp, level: level2, message, stack, ...meta }) => {
224
+ const parsedMessage = stringifyUnknown(message);
225
+ const normalizedMessage = stripAnsi(parsedMessage);
226
+ const { tag, body } = extractTagAndMessage(normalizedMessage);
227
+ let out = `ts="${timestamp}" level=${stripAnsi(level2)} [${tag}] msg="${escapeMessageValue(body)}"`;
228
+ const derivedStack = getStackFromMeta(stack, meta);
229
+ if (derivedStack) {
230
+ out += ` stack="${escapeValue(stripAnsi(derivedStack))}"`;
231
+ }
232
+ const metaCopy = { ...meta };
233
+ delete metaCopy[Symbol.for("splat")];
234
+ if (Object.keys(metaCopy).length > 0) {
235
+ out += ` meta=${escapeValue(stringifyUnknown(metaCopy))}`;
236
+ }
237
+ return out;
238
+ })
239
+ )
240
+ })
241
+ );
242
+ }
243
+ if (emitConfigLog) {
244
+ logger.info(
245
+ `[Logger] configured level=${level} console=${enableConsole ? consoleLevel : "off"} file=${enableFile ? fileLevel : "off"}${filePath ? ` path=${filePath}` : ""}`
246
+ );
247
+ }
248
+ return logger;
249
+ }
250
+ configureLogger();
97
251
 
98
252
  // src/utils/store.ts
99
253
  function getDefaultStoreConfig(network) {
@@ -160,13 +314,13 @@ var Store = class _Store {
160
314
  logger.verbose(`Account added: ${accountKey} to network: ${this.config.network}`);
161
315
  }
162
316
  getAccountFilePath() {
163
- const path = `${this.storeConfig.SECRET_FILE_FOLDER}/${this.storeConfig.ACCOUNTS_FILE_NAME}`;
164
- logger.verbose(`Path: ${path}`);
165
- return path;
317
+ const path2 = `${this.storeConfig.SECRET_FILE_FOLDER}/${this.storeConfig.ACCOUNTS_FILE_NAME}`;
318
+ logger.verbose(`Path: ${path2}`);
319
+ return path2;
166
320
  }
167
321
  getAllAccounts() {
168
322
  const PATH = this.getAccountFilePath();
169
- if (!fs.existsSync(PATH)) {
323
+ if (!fs2.existsSync(PATH)) {
170
324
  logger.verbose(`Accounts: files doesnt exist`);
171
325
  return {};
172
326
  }
@@ -196,10 +350,10 @@ var Store = class _Store {
196
350
  return Object.keys(this.loadAccounts());
197
351
  }
198
352
  static ensureFolder(folder) {
199
- if (!fs.existsSync(folder)) {
200
- fs.mkdirSync(folder, { recursive: true });
353
+ if (!fs2.existsSync(folder)) {
354
+ fs2.mkdirSync(folder, { recursive: true });
201
355
  }
202
- if (!fs.existsSync(`${folder}`)) {
356
+ if (!fs2.existsSync(`${folder}`)) {
203
357
  throw new Error(`Store folder not found: ${folder}`);
204
358
  }
205
359
  }