@mento-protocol/mento-sdk 3.0.0-beta.5 → 3.0.0-beta.7
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 +34 -0
- package/dist/cache/routes.d.ts.map +1 -1
- package/dist/cache/routes.js +5 -3
- package/dist/cache/routes.js.map +1 -1
- package/dist/core/abis/erc20.d.ts +7 -0
- package/dist/core/abis/erc20.d.ts.map +1 -1
- package/dist/core/abis/erc20.js +7 -0
- package/dist/core/abis/erc20.js.map +1 -1
- package/dist/core/abis/fpmm.d.ts +38 -0
- package/dist/core/abis/fpmm.d.ts.map +1 -1
- package/dist/core/abis/fpmm.js +1 -0
- package/dist/core/abis/fpmm.js.map +1 -1
- package/dist/core/constants/aaveConfig.js +2 -2
- package/dist/core/constants/addresses.d.ts.map +1 -1
- package/dist/core/constants/addresses.js +3 -1
- package/dist/core/constants/addresses.js.map +1 -1
- package/dist/core/types/index.d.ts +2 -1
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/index.js +2 -1
- package/dist/core/types/index.js.map +1 -1
- package/dist/core/types/pool.d.ts +4 -0
- package/dist/core/types/pool.d.ts.map +1 -1
- package/dist/core/types/provider.d.ts.map +1 -1
- package/dist/core/types/provider.js +0 -1
- package/dist/core/types/provider.js.map +1 -1
- package/dist/core/types/route.d.ts +3 -3
- package/dist/core/types/route.d.ts.map +1 -1
- package/dist/core/types/token.d.ts +13 -3
- package/dist/core/types/token.d.ts.map +1 -1
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.d.ts.map +1 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingLimits.js.map +1 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.d.ts.map +1 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/services/pools/PoolService.d.ts +1 -1
- package/dist/services/pools/PoolService.d.ts.map +1 -1
- package/dist/services/pools/PoolService.js +20 -12
- package/dist/services/pools/PoolService.js.map +1 -1
- package/dist/services/quotes/QuoteService.d.ts +21 -12
- package/dist/services/quotes/QuoteService.d.ts.map +1 -1
- package/dist/services/quotes/QuoteService.js +23 -11
- package/dist/services/quotes/QuoteService.js.map +1 -1
- package/dist/services/routes/RouteService.d.ts +3 -3
- package/dist/services/routes/RouteService.d.ts.map +1 -1
- package/dist/services/routes/RouteService.js +3 -5
- package/dist/services/routes/RouteService.js.map +1 -1
- package/dist/services/swap/SwapService.d.ts +18 -14
- package/dist/services/swap/SwapService.d.ts.map +1 -1
- package/dist/services/swap/SwapService.js +31 -14
- package/dist/services/swap/SwapService.js.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.d.ts +0 -4
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -1
- package/dist/services/tokens/supplyAdjustmentService.js +3 -8
- package/dist/services/tokens/supplyAdjustmentService.js.map +1 -1
- package/dist/services/tokens/tokenService.d.ts.map +1 -1
- package/dist/services/tokens/tokenService.js +2 -2
- package/dist/services/tokens/tokenService.js.map +1 -1
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.d.ts.map +1 -0
- package/dist/services/trading/TradingLimitsService.js +157 -0
- package/dist/services/trading/TradingLimitsService.js.map +1 -0
- package/dist/services/trading/TradingService.d.ts +39 -5
- package/dist/services/trading/TradingService.d.ts.map +1 -1
- package/dist/services/trading/TradingService.js +56 -4
- package/dist/services/trading/TradingService.js.map +1 -1
- package/dist/services/trading/index.d.ts +1 -0
- package/dist/services/trading/index.d.ts.map +1 -1
- package/dist/services/trading/index.js +1 -0
- package/dist/services/trading/index.js.map +1 -1
- package/dist/utils/costUtils.js +4 -4
- package/dist/utils/costUtils.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +3 -2
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +19 -3
- package/dist/utils/pathEncoder.js.map +1 -1
- package/dist/utils/routeUtils.d.ts +53 -53
- package/dist/utils/routeUtils.d.ts.map +1 -1
- package/dist/utils/routeUtils.js +41 -41
- package/dist/utils/routeUtils.js.map +1 -1
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.d.ts.map +1 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/tradingLimits.js.map +1 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeLimitId = computeLimitId;
|
|
4
|
+
exports.calculateTradingLimitsV1 = calculateTradingLimitsV1;
|
|
5
|
+
exports.calculateTradingLimitsV2 = calculateTradingLimitsV2;
|
|
6
|
+
exports.hasConfiguredLimitsV1 = hasConfiguredLimitsV1;
|
|
7
|
+
exports.hasConfiguredLimitsV2 = hasConfiguredLimitsV2;
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
/** V2 trading limits use 15 decimals internally */
|
|
10
|
+
const V2_INTERNAL_DECIMALS = 15;
|
|
11
|
+
/** V2 L0 window is fixed at 5 minutes */
|
|
12
|
+
const V2_L0_TIMESTEP = 5 * 60; // 300 seconds
|
|
13
|
+
/** V2 L1 window is fixed at 1 day */
|
|
14
|
+
const V2_L1_TIMESTEP = 24 * 60 * 60; // 86400 seconds
|
|
15
|
+
/** Far future timestamp for global limits (year 2030) */
|
|
16
|
+
const TIMESTAMP_FAR_FUTURE = 1893456000;
|
|
17
|
+
/**
|
|
18
|
+
* Compute limit ID for Broker (V1) trading limits.
|
|
19
|
+
* limitId = exchangeId XOR bytes32(uint256(uint160(token)))
|
|
20
|
+
*
|
|
21
|
+
* @param exchangeId - The exchange ID (bytes32)
|
|
22
|
+
* @param token - The token address
|
|
23
|
+
* @returns The limit ID as hex string
|
|
24
|
+
*/
|
|
25
|
+
function computeLimitId(exchangeId, token) {
|
|
26
|
+
// Pad token address to 32 bytes (left-padded with zeros)
|
|
27
|
+
const tokenBytes32 = (0, viem_1.pad)(token, { size: 32 });
|
|
28
|
+
// Convert both to BigInt for XOR operation
|
|
29
|
+
const exchangeIdBigInt = (0, viem_1.hexToBigInt)(exchangeId);
|
|
30
|
+
const tokenBigInt = (0, viem_1.hexToBigInt)(tokenBytes32);
|
|
31
|
+
// XOR operation
|
|
32
|
+
const limitIdBigInt = exchangeIdBigInt ^ tokenBigInt;
|
|
33
|
+
// Convert back to hex with proper padding
|
|
34
|
+
return (0, viem_1.pad)((0, viem_1.numberToHex)(limitIdBigInt), { size: 32 });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Calculate trading limits from V1 config and state (Broker/Virtual pools).
|
|
38
|
+
* Returns human-friendly TradingLimit objects with maxIn/maxOut/until.
|
|
39
|
+
*
|
|
40
|
+
* @param config - V1 trading limits configuration
|
|
41
|
+
* @param state - V1 trading limits state
|
|
42
|
+
* @param asset - Token address
|
|
43
|
+
* @param tokenDecimals - Token decimals for consumer reference
|
|
44
|
+
* @returns Array of TradingLimit objects
|
|
45
|
+
*/
|
|
46
|
+
function calculateTradingLimitsV1(config, state, asset, tokenDecimals) {
|
|
47
|
+
const nowEpoch = Math.floor(Date.now() / 1000);
|
|
48
|
+
const limits = [];
|
|
49
|
+
// Check if L0 is enabled (bit 0 of flags)
|
|
50
|
+
const isL0Enabled = (config.flags & 0x01) !== 0;
|
|
51
|
+
// Check if L1 is enabled (bit 1 of flags)
|
|
52
|
+
const isL1Enabled = (config.flags & 0x02) !== 0;
|
|
53
|
+
// Check if LG is enabled (bit 2 of flags)
|
|
54
|
+
const isLGEnabled = (config.flags & 0x04) !== 0;
|
|
55
|
+
// Reset netflows if time windows have passed
|
|
56
|
+
const isL0Outdated = isL0Enabled && nowEpoch > state.lastUpdated0 + config.timestep0;
|
|
57
|
+
const isL1Outdated = isL1Enabled && nowEpoch > state.lastUpdated1 + config.timestep1;
|
|
58
|
+
const effectiveNetflow0 = isL0Outdated ? 0n : state.netflow0;
|
|
59
|
+
const effectiveNetflow1 = isL1Outdated ? 0n : state.netflow1;
|
|
60
|
+
const effectiveLastUpdated0 = isL0Outdated ? nowEpoch : state.lastUpdated0;
|
|
61
|
+
const effectiveLastUpdated1 = isL1Outdated ? nowEpoch : state.lastUpdated1;
|
|
62
|
+
// Add L0 limit if configured
|
|
63
|
+
if (isL0Enabled && config.limit0 > 0n) {
|
|
64
|
+
limits.push({
|
|
65
|
+
asset,
|
|
66
|
+
maxIn: config.limit0 - effectiveNetflow0,
|
|
67
|
+
maxOut: config.limit0 + effectiveNetflow0,
|
|
68
|
+
until: effectiveLastUpdated0 + config.timestep0,
|
|
69
|
+
decimals: tokenDecimals,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Add L1 limit if configured
|
|
73
|
+
if (isL1Enabled && config.limit1 > 0n) {
|
|
74
|
+
limits.push({
|
|
75
|
+
asset,
|
|
76
|
+
maxIn: config.limit1 - effectiveNetflow1,
|
|
77
|
+
maxOut: config.limit1 + effectiveNetflow1,
|
|
78
|
+
until: effectiveLastUpdated1 + config.timestep1,
|
|
79
|
+
decimals: tokenDecimals,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Add LG (global) limit if configured
|
|
83
|
+
if (isLGEnabled && config.limitGlobal > 0n) {
|
|
84
|
+
limits.push({
|
|
85
|
+
asset,
|
|
86
|
+
maxIn: config.limitGlobal - state.netflowGlobal,
|
|
87
|
+
maxOut: config.limitGlobal + state.netflowGlobal,
|
|
88
|
+
until: TIMESTAMP_FAR_FUTURE,
|
|
89
|
+
decimals: tokenDecimals,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// Apply cascading restrictions: limits with larger timeframes restrict smaller ones
|
|
93
|
+
// e.g., if maxIn is 0 in LG, it should also be 0 in L1 and L0
|
|
94
|
+
for (let i = limits.length - 1; i > 0; i--) {
|
|
95
|
+
if (limits[i - 1].maxIn > limits[i].maxIn) {
|
|
96
|
+
limits[i - 1] = { ...limits[i - 1], maxIn: limits[i].maxIn };
|
|
97
|
+
}
|
|
98
|
+
if (limits[i - 1].maxOut > limits[i].maxOut) {
|
|
99
|
+
limits[i - 1] = { ...limits[i - 1], maxOut: limits[i].maxOut };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return limits;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Calculate trading limits from V2 config and state (FPMM pools).
|
|
106
|
+
* V2 uses fixed timeframes: 5 min for L0, 1 day for L1.
|
|
107
|
+
* Values are stored with 15 decimals precision.
|
|
108
|
+
*
|
|
109
|
+
* @param config - V2 trading limits configuration
|
|
110
|
+
* @param state - V2 trading limits state
|
|
111
|
+
* @param asset - Token address
|
|
112
|
+
* @returns Array of TradingLimit objects
|
|
113
|
+
*/
|
|
114
|
+
function calculateTradingLimitsV2(config, state, asset) {
|
|
115
|
+
const nowEpoch = Math.floor(Date.now() / 1000);
|
|
116
|
+
const limits = [];
|
|
117
|
+
// Check if L0 is configured (limit0 > 0)
|
|
118
|
+
const isL0Enabled = config.limit0 > 0n;
|
|
119
|
+
// Check if L1 is configured (limit1 > 0)
|
|
120
|
+
const isL1Enabled = config.limit1 > 0n;
|
|
121
|
+
// Reset netflows if time windows have passed
|
|
122
|
+
const isL0Outdated = isL0Enabled && nowEpoch > state.lastUpdated0 + V2_L0_TIMESTEP;
|
|
123
|
+
const isL1Outdated = isL1Enabled && nowEpoch > state.lastUpdated1 + V2_L1_TIMESTEP;
|
|
124
|
+
const effectiveNetflow0 = isL0Outdated ? 0n : state.netflow0;
|
|
125
|
+
const effectiveNetflow1 = isL1Outdated ? 0n : state.netflow1;
|
|
126
|
+
const effectiveLastUpdated0 = isL0Outdated ? nowEpoch : state.lastUpdated0;
|
|
127
|
+
const effectiveLastUpdated1 = isL1Outdated ? nowEpoch : state.lastUpdated1;
|
|
128
|
+
// Add L0 limit if configured
|
|
129
|
+
if (isL0Enabled) {
|
|
130
|
+
limits.push({
|
|
131
|
+
asset,
|
|
132
|
+
maxIn: config.limit0 - effectiveNetflow0,
|
|
133
|
+
maxOut: config.limit0 + effectiveNetflow0,
|
|
134
|
+
until: effectiveLastUpdated0 + V2_L0_TIMESTEP,
|
|
135
|
+
decimals: V2_INTERNAL_DECIMALS, // V2 returns 15 decimal values
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Add L1 limit if configured
|
|
139
|
+
if (isL1Enabled) {
|
|
140
|
+
limits.push({
|
|
141
|
+
asset,
|
|
142
|
+
maxIn: config.limit1 - effectiveNetflow1,
|
|
143
|
+
maxOut: config.limit1 + effectiveNetflow1,
|
|
144
|
+
until: effectiveLastUpdated1 + V2_L1_TIMESTEP,
|
|
145
|
+
decimals: V2_INTERNAL_DECIMALS, // V2 returns 15 decimal values
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Apply cascading restrictions
|
|
149
|
+
for (let i = limits.length - 1; i > 0; i--) {
|
|
150
|
+
if (limits[i - 1].maxIn > limits[i].maxIn) {
|
|
151
|
+
limits[i - 1] = { ...limits[i - 1], maxIn: limits[i].maxIn };
|
|
152
|
+
}
|
|
153
|
+
if (limits[i - 1].maxOut > limits[i].maxOut) {
|
|
154
|
+
limits[i - 1] = { ...limits[i - 1], maxOut: limits[i].maxOut };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return limits;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if any trading limits are configured (flags > 0 for V1, or limit0/limit1 > 0 for V2)
|
|
161
|
+
*/
|
|
162
|
+
function hasConfiguredLimitsV1(config) {
|
|
163
|
+
return config.flags > 0;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if any trading limits are configured for V2
|
|
167
|
+
*/
|
|
168
|
+
function hasConfiguredLimitsV2(config) {
|
|
169
|
+
return config.limit0 > 0n || config.limit1 > 0n;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=tradingLimits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tradingLimits.js","sourceRoot":"","sources":["../../src/utils/tradingLimits.ts"],"names":[],"mappings":";;AA6BA,wCAaC;AAYD,4DAsEC;AAYD,4DAuDC;AAKD,sDAEC;AAKD,sDAEC;AA7MD,+BAAoD;AASpD,mDAAmD;AACnD,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAE/B,yCAAyC;AACzC,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,CAAA,CAAC,cAAc;AAE5C,qCAAqC;AACrC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA,CAAC,gBAAgB;AAEpD,yDAAyD;AACzD,MAAM,oBAAoB,GAAG,UAAU,CAAA;AAEvC;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,UAAkB,EAAE,KAAa;IAC9D,yDAAyD;IACzD,MAAM,YAAY,GAAG,IAAA,UAAG,EAAC,KAAsB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IAE9D,2CAA2C;IAC3C,MAAM,gBAAgB,GAAG,IAAA,kBAAW,EAAC,UAA2B,CAAC,CAAA;IACjE,MAAM,WAAW,GAAG,IAAA,kBAAW,EAAC,YAAY,CAAC,CAAA;IAE7C,gBAAgB;IAChB,MAAM,aAAa,GAAG,gBAAgB,GAAG,WAAW,CAAA;IAEpD,0CAA0C;IAC1C,OAAO,IAAA,UAAG,EAAC,IAAA,kBAAW,EAAC,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,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,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;QAChE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,MAA6B;IACjE,OAAO,MAAM,CAAC,KAAK,GAAG,CAAC,CAAA;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,MAA6B;IACjE,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates an Ethereum address format using viem's isAddress utility
|
|
3
|
+
*
|
|
4
|
+
* @param address - The address string to validate
|
|
5
|
+
* @param paramName - Optional parameter name for better error messages
|
|
6
|
+
* @returns True if valid (type guard for `0x${string}`)
|
|
7
|
+
* @throws Error if address is invalid
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* validateAddress('0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
12
|
+
* // Returns true
|
|
13
|
+
*
|
|
14
|
+
* validateAddress('invalid', 'tokenIn')
|
|
15
|
+
* // Throws: "Invalid address for tokenIn: invalid"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateAddress(address: string, paramName?: string): address is `0x${string}`;
|
|
19
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,IAAI,KAAK,MAAM,EAAE,CAe7F"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAddress = validateAddress;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Validates an Ethereum address format using viem's isAddress utility
|
|
7
|
+
*
|
|
8
|
+
* @param address - The address string to validate
|
|
9
|
+
* @param paramName - Optional parameter name for better error messages
|
|
10
|
+
* @returns True if valid (type guard for `0x${string}`)
|
|
11
|
+
* @throws Error if address is invalid
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* validateAddress('0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
16
|
+
* // Returns true
|
|
17
|
+
*
|
|
18
|
+
* validateAddress('invalid', 'tokenIn')
|
|
19
|
+
* // Throws: "Invalid address for tokenIn: invalid"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function validateAddress(address, paramName) {
|
|
23
|
+
if (typeof address !== 'string') {
|
|
24
|
+
const param = paramName ? ` for ${paramName}` : '';
|
|
25
|
+
throw new Error(`Address${param} must be a string, got ${typeof address}`);
|
|
26
|
+
}
|
|
27
|
+
// Use viem's isAddress with strict: false to allow both checksummed and non-checksummed addresses
|
|
28
|
+
if (!(0, viem_1.isAddress)(address, { strict: false })) {
|
|
29
|
+
const param = paramName ? ` for ${paramName}` : '';
|
|
30
|
+
throw new Error(`Invalid address${param}: ${address}. Expected 0x followed by 40 hex characters`);
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;AAmBA,0CAeC;AAlCD,+BAAgC;AAEhC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,SAAkB;IACjE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAClD,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,0BAA0B,OAAO,OAAO,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,kGAAkG;IAClG,IAAI,CAAC,IAAA,gBAAS,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAClD,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,KAAK,OAAO,6CAA6C,CACjF,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|