@the-situation/utils 0.5.0-alpha.0 → 0.8.4
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/dist/abi-encode.d.ts +99 -8
- package/dist/abi-encode.d.ts.map +1 -1
- package/dist/abi-encode.js +107 -8
- package/dist/abi-encode.js.map +1 -1
- package/dist/categorical-hints.d.ts +29 -0
- package/dist/categorical-hints.d.ts.map +1 -0
- package/dist/categorical-hints.js +62 -0
- package/dist/categorical-hints.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/abi-encode.d.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { type Abi } from 'starknet';
|
|
21
21
|
import type { NormalDistributionRaw, NormalSqrtHintsRaw, SQ128x128Raw } from '@the-situation/core';
|
|
22
|
+
import type { SellExecutionGuardsRaw } from '@the-situation/abi';
|
|
22
23
|
/**
|
|
23
24
|
* SQ128x128 in ABI format with snake_case field names.
|
|
24
25
|
*
|
|
@@ -76,6 +77,23 @@ export declare function toAbiDistribution(raw: NormalDistributionRaw): AbiNormal
|
|
|
76
77
|
* @returns ABI-compatible hints with snake_case field names
|
|
77
78
|
*/
|
|
78
79
|
export declare function toAbiHints(hints: NormalSqrtHintsRaw): AbiNormalSqrtHints;
|
|
80
|
+
/**
|
|
81
|
+
* Sell execution guards in ABI format with snake_case field names.
|
|
82
|
+
*/
|
|
83
|
+
export interface AbiSellExecutionGuards {
|
|
84
|
+
readonly expected_market_dist: AbiNormalDistribution;
|
|
85
|
+
readonly expected_backing: AbiSQ128x128;
|
|
86
|
+
readonly expected_tolerance: AbiSQ128x128;
|
|
87
|
+
readonly expected_min_trade_collateral: AbiSQ128x128;
|
|
88
|
+
readonly min_token_out: bigint;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts SDK SellExecutionGuardsRaw to ABI format with snake_case field names.
|
|
92
|
+
*
|
|
93
|
+
* @param guards - SDK guards
|
|
94
|
+
* @returns ABI-compatible guards
|
|
95
|
+
*/
|
|
96
|
+
export declare function toAbiSellGuards(guards: SellExecutionGuardsRaw): AbiSellExecutionGuards;
|
|
79
97
|
/**
|
|
80
98
|
* Encodes a single ABI type using starknet.js parseCalldataField.
|
|
81
99
|
*
|
|
@@ -114,6 +132,72 @@ export declare function encodeNormalSqrtHintsRawType(abi: Abi, value: NormalSqrt
|
|
|
114
132
|
* Decodes NormalSqrtHintsRaw using ABI type metadata.
|
|
115
133
|
*/
|
|
116
134
|
export declare function decodeNormalSqrtHintsRawType(abi: Abi, calldata: readonly (string | bigint)[]): NormalSqrtHintsRaw;
|
|
135
|
+
/**
|
|
136
|
+
* Categorical distribution in ABI format.
|
|
137
|
+
*/
|
|
138
|
+
export interface AbiCategoricalDistribution {
|
|
139
|
+
readonly probs: readonly AbiSQ128x128[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Categorical L2 hint in ABI format with snake_case field names.
|
|
143
|
+
*/
|
|
144
|
+
export interface AbiCategoricalL2Hint {
|
|
145
|
+
readonly l2_norm_hint: AbiSQ128x128;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Converts categorical distribution to ABI format.
|
|
149
|
+
*
|
|
150
|
+
* @param probs - Array of SQ128x128Raw probability values
|
|
151
|
+
* @returns ABI-compatible categorical distribution
|
|
152
|
+
*/
|
|
153
|
+
export declare function toAbiCategoricalDistribution(probs: readonly SQ128x128Raw[]): AbiCategoricalDistribution;
|
|
154
|
+
/**
|
|
155
|
+
* Converts categorical L2 hint to ABI format.
|
|
156
|
+
*
|
|
157
|
+
* @param hint - SQ128x128Raw L2 norm hint value
|
|
158
|
+
* @returns ABI-compatible categorical L2 hint
|
|
159
|
+
*/
|
|
160
|
+
export declare function toAbiCategoricalL2Hint(hint: SQ128x128Raw): AbiCategoricalL2Hint;
|
|
161
|
+
/**
|
|
162
|
+
* Encodes CategoricalDistributionRaw using ABI type metadata.
|
|
163
|
+
*
|
|
164
|
+
* @param abi - Contract ABI that defines the type
|
|
165
|
+
* @param value - The categorical distribution to encode
|
|
166
|
+
* @returns Encoded calldata as string array
|
|
167
|
+
*/
|
|
168
|
+
export declare function encodeCategoricalDistributionRawType(abi: Abi, value: {
|
|
169
|
+
probs: readonly SQ128x128Raw[];
|
|
170
|
+
}): string[];
|
|
171
|
+
/**
|
|
172
|
+
* Decodes CategoricalDistributionRaw using ABI type metadata.
|
|
173
|
+
*
|
|
174
|
+
* @param abi - Contract ABI that defines the type
|
|
175
|
+
* @param calldata - Encoded calldata for the type
|
|
176
|
+
* @returns The decoded categorical distribution
|
|
177
|
+
*/
|
|
178
|
+
export declare function decodeCategoricalDistributionRawType(abi: Abi, calldata: readonly (string | bigint)[]): {
|
|
179
|
+
probs: SQ128x128Raw[];
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Encodes CategoricalL2HintRaw using ABI type metadata.
|
|
183
|
+
*
|
|
184
|
+
* @param abi - Contract ABI that defines the type
|
|
185
|
+
* @param value - The L2 hint to encode
|
|
186
|
+
* @returns Encoded calldata as string array
|
|
187
|
+
*/
|
|
188
|
+
export declare function encodeCategoricalL2HintRawType(abi: Abi, value: {
|
|
189
|
+
l2NormHint: SQ128x128Raw;
|
|
190
|
+
}): string[];
|
|
191
|
+
/**
|
|
192
|
+
* Decodes CategoricalL2HintRaw using ABI type metadata.
|
|
193
|
+
*
|
|
194
|
+
* @param abi - Contract ABI that defines the type
|
|
195
|
+
* @param calldata - Encoded calldata for the type
|
|
196
|
+
* @returns The decoded L2 hint
|
|
197
|
+
*/
|
|
198
|
+
export declare function decodeCategoricalL2HintRawType(abi: Abi, calldata: readonly (string | bigint)[]): {
|
|
199
|
+
l2NormHint: SQ128x128Raw;
|
|
200
|
+
};
|
|
117
201
|
/**
|
|
118
202
|
* Encoder class for trade calldata using ABI-aware encoding.
|
|
119
203
|
*
|
|
@@ -156,23 +240,30 @@ export declare class TradeCalldataEncoder {
|
|
|
156
240
|
*/
|
|
157
241
|
encodeExecuteTrade(candidate: NormalDistributionRaw, xStar: SQ128x128Raw, suppliedCollateral: SQ128x128Raw, hints: NormalSqrtHintsRaw): string[];
|
|
158
242
|
/**
|
|
159
|
-
* Encodes
|
|
243
|
+
* Encodes sell_position_guarded calldata using ABI-aware encoding (v0.8.0).
|
|
160
244
|
*
|
|
161
|
-
* The
|
|
245
|
+
* The sell_position_guarded function signature is:
|
|
162
246
|
* ```cairo
|
|
163
|
-
* fn
|
|
247
|
+
* fn sell_position_guarded(
|
|
164
248
|
* ref self: ContractState,
|
|
249
|
+
* candidate: NormalDistribution,
|
|
165
250
|
* x_star: SQ128x128,
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* ) ->
|
|
251
|
+
* candidate_hints: NormalSqrtHints,
|
|
252
|
+
* guards: SellExecutionGuards,
|
|
253
|
+
* ) -> PositionSellResult
|
|
169
254
|
* ```
|
|
170
255
|
*
|
|
256
|
+
* @param candidate - Target distribution for the sell (typically the original distribution)
|
|
171
257
|
* @param xStar - The x* value for collateral computation
|
|
172
|
-
* @param
|
|
173
|
-
* @param
|
|
258
|
+
* @param candidateHints - Hints for the candidate distribution
|
|
259
|
+
* @param guards - Execution guards for stale-state protection
|
|
174
260
|
* @returns Encoded calldata as string array
|
|
175
261
|
*/
|
|
262
|
+
encodeSellPosition(candidate: NormalDistributionRaw, xStar: SQ128x128Raw, candidateHints: NormalSqrtHintsRaw, guards: SellExecutionGuardsRaw): string[];
|
|
263
|
+
/**
|
|
264
|
+
* @deprecated Use `encodeSellPosition` instead. The `close_position` entrypoint
|
|
265
|
+
* does not exist in v0.8.0 contracts.
|
|
266
|
+
*/
|
|
176
267
|
encodeClosePosition(xStar: SQ128x128Raw, additionalCollateral: SQ128x128Raw, targetHints: NormalSqrtHintsRaw): string[];
|
|
177
268
|
}
|
|
178
269
|
/**
|
package/dist/abi-encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-encode.d.ts","sourceRoot":"","sources":["../src/abi-encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,KAAK,GAAG,EAMT,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"abi-encode.d.ts","sourceRoot":"","sources":["../src/abi-encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,KAAK,GAAG,EAMT,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAEjC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;IAErC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY,CAQ9D;AAED;;;;;GAKG;AACH,wBAAgB,iBA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ACR,QAAQ,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GACrC;IAAE,UAAU,EAAE,YAAY,CAAA;CAAE,CAE9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;gBAExB,GAAG,EAAE,GAAG;IAIpB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAChB,SAAS,EAAE,qBAAqB,EAChC,KAAK,EAAE,YAAY,EACnB,kBAAkB,EAAE,YAAY,EAChC,KAAK,EAAE,kBAAkB,GACxB,MAAM,EAAE;IAYX;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAChB,SAAS,EAAE,qBAAqB,EAChC,KAAK,EAAE,YAAY,EACnB,cAAc,EAAE,kBAAkB,EAClC,MAAM,EAAE,sBAAsB,GAC7B,MAAM,EAAE;IAWX;;;OAGG;IACH,mBAAmB,CACjB,KAAK,EAAE,YAAY,EACnB,oBAAoB,EAAE,YAAY,EAClC,WAAW,EAAE,kBAAkB,GAC9B,MAAM,EAAE;CAUZ;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAEjE"}
|
package/dist/abi-encode.js
CHANGED
|
@@ -67,6 +67,26 @@ export function toAbiHints(hints) {
|
|
|
67
67
|
backing_denom: toAbiSQ128x128(hints.backing_denom),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Converts SDK SellExecutionGuardsRaw to ABI format with snake_case field names.
|
|
72
|
+
*
|
|
73
|
+
* @param guards - SDK guards
|
|
74
|
+
* @returns ABI-compatible guards
|
|
75
|
+
*/
|
|
76
|
+
export function toAbiSellGuards(guards) {
|
|
77
|
+
return {
|
|
78
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
79
|
+
expected_market_dist: toAbiDistribution(guards.expectedMarketDist),
|
|
80
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
81
|
+
expected_backing: toAbiSQ128x128(guards.expectedBacking),
|
|
82
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
83
|
+
expected_tolerance: toAbiSQ128x128(guards.expectedTolerance),
|
|
84
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
85
|
+
expected_min_trade_collateral: toAbiSQ128x128(guards.expectedMinTradeCollateral),
|
|
86
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
87
|
+
min_token_out: guards.minTokenOut,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
70
90
|
// ============================================================================
|
|
71
91
|
// Type Codec (ABI-aware single-type encode/decode)
|
|
72
92
|
// ============================================================================
|
|
@@ -184,6 +204,69 @@ export function encodeNormalSqrtHintsRawType(abi, value) {
|
|
|
184
204
|
export function decodeNormalSqrtHintsRawType(abi, calldata) {
|
|
185
205
|
return decodeAbiType(abi, NORMAL_SQRT_HINTS_RAW_ABI_TYPE, calldata);
|
|
186
206
|
}
|
|
207
|
+
// ============================================================================
|
|
208
|
+
// Categorical Type Codec
|
|
209
|
+
// ============================================================================
|
|
210
|
+
const CATEGORICAL_DISTRIBUTION_RAW_ABI_TYPE = 'the_situation::types::categorical::types::CategoricalDistributionRaw';
|
|
211
|
+
const CATEGORICAL_L2_HINT_RAW_ABI_TYPE = 'the_situation::onchain::common::CategoricalL2HintRaw';
|
|
212
|
+
/**
|
|
213
|
+
* Converts categorical distribution to ABI format.
|
|
214
|
+
*
|
|
215
|
+
* @param probs - Array of SQ128x128Raw probability values
|
|
216
|
+
* @returns ABI-compatible categorical distribution
|
|
217
|
+
*/
|
|
218
|
+
export function toAbiCategoricalDistribution(probs) {
|
|
219
|
+
return { probs: probs.map(toAbiSQ128x128) };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Converts categorical L2 hint to ABI format.
|
|
223
|
+
*
|
|
224
|
+
* @param hint - SQ128x128Raw L2 norm hint value
|
|
225
|
+
* @returns ABI-compatible categorical L2 hint
|
|
226
|
+
*/
|
|
227
|
+
export function toAbiCategoricalL2Hint(hint) {
|
|
228
|
+
return { l2_norm_hint: toAbiSQ128x128(hint) };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Encodes CategoricalDistributionRaw using ABI type metadata.
|
|
232
|
+
*
|
|
233
|
+
* @param abi - Contract ABI that defines the type
|
|
234
|
+
* @param value - The categorical distribution to encode
|
|
235
|
+
* @returns Encoded calldata as string array
|
|
236
|
+
*/
|
|
237
|
+
export function encodeCategoricalDistributionRawType(abi, value) {
|
|
238
|
+
return encodeAbiType(abi, CATEGORICAL_DISTRIBUTION_RAW_ABI_TYPE, { probs: value.probs.map(toAbiSQ128x128) });
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Decodes CategoricalDistributionRaw using ABI type metadata.
|
|
242
|
+
*
|
|
243
|
+
* @param abi - Contract ABI that defines the type
|
|
244
|
+
* @param calldata - Encoded calldata for the type
|
|
245
|
+
* @returns The decoded categorical distribution
|
|
246
|
+
*/
|
|
247
|
+
export function decodeCategoricalDistributionRawType(abi, calldata) {
|
|
248
|
+
return decodeAbiType(abi, CATEGORICAL_DISTRIBUTION_RAW_ABI_TYPE, calldata);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Encodes CategoricalL2HintRaw using ABI type metadata.
|
|
252
|
+
*
|
|
253
|
+
* @param abi - Contract ABI that defines the type
|
|
254
|
+
* @param value - The L2 hint to encode
|
|
255
|
+
* @returns Encoded calldata as string array
|
|
256
|
+
*/
|
|
257
|
+
export function encodeCategoricalL2HintRawType(abi, value) {
|
|
258
|
+
return encodeAbiType(abi, CATEGORICAL_L2_HINT_RAW_ABI_TYPE, { l2_norm_hint: toAbiSQ128x128(value.l2NormHint) });
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Decodes CategoricalL2HintRaw using ABI type metadata.
|
|
262
|
+
*
|
|
263
|
+
* @param abi - Contract ABI that defines the type
|
|
264
|
+
* @param calldata - Encoded calldata for the type
|
|
265
|
+
* @returns The decoded L2 hint
|
|
266
|
+
*/
|
|
267
|
+
export function decodeCategoricalL2HintRawType(abi, calldata) {
|
|
268
|
+
return decodeAbiType(abi, CATEGORICAL_L2_HINT_RAW_ABI_TYPE, calldata);
|
|
269
|
+
}
|
|
187
270
|
/**
|
|
188
271
|
* Encoder class for trade calldata using ABI-aware encoding.
|
|
189
272
|
*
|
|
@@ -238,23 +321,39 @@ export class TradeCalldataEncoder {
|
|
|
238
321
|
});
|
|
239
322
|
}
|
|
240
323
|
/**
|
|
241
|
-
* Encodes
|
|
324
|
+
* Encodes sell_position_guarded calldata using ABI-aware encoding (v0.8.0).
|
|
242
325
|
*
|
|
243
|
-
* The
|
|
326
|
+
* The sell_position_guarded function signature is:
|
|
244
327
|
* ```cairo
|
|
245
|
-
* fn
|
|
328
|
+
* fn sell_position_guarded(
|
|
246
329
|
* ref self: ContractState,
|
|
330
|
+
* candidate: NormalDistribution,
|
|
247
331
|
* x_star: SQ128x128,
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* ) ->
|
|
332
|
+
* candidate_hints: NormalSqrtHints,
|
|
333
|
+
* guards: SellExecutionGuards,
|
|
334
|
+
* ) -> PositionSellResult
|
|
251
335
|
* ```
|
|
252
336
|
*
|
|
337
|
+
* @param candidate - Target distribution for the sell (typically the original distribution)
|
|
253
338
|
* @param xStar - The x* value for collateral computation
|
|
254
|
-
* @param
|
|
255
|
-
* @param
|
|
339
|
+
* @param candidateHints - Hints for the candidate distribution
|
|
340
|
+
* @param guards - Execution guards for stale-state protection
|
|
256
341
|
* @returns Encoded calldata as string array
|
|
257
342
|
*/
|
|
343
|
+
encodeSellPosition(candidate, xStar, candidateHints, guards) {
|
|
344
|
+
return this.callData.compile('sell_position_guarded', {
|
|
345
|
+
candidate: toAbiDistribution(candidate),
|
|
346
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
347
|
+
x_star: toAbiSQ128x128(xStar),
|
|
348
|
+
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
|
349
|
+
candidate_hints: toAbiHints(candidateHints),
|
|
350
|
+
guards: toAbiSellGuards(guards),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* @deprecated Use `encodeSellPosition` instead. The `close_position` entrypoint
|
|
355
|
+
* does not exist in v0.8.0 contracts.
|
|
356
|
+
*/
|
|
258
357
|
encodeClosePosition(xStar, additionalCollateral, targetHints) {
|
|
259
358
|
return this.callData.compile('close_position', {
|
|
260
359
|
// biome-ignore lint/style/useNamingConvention: Cairo uses snake_case
|
package/dist/abi-encode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-encode.js","sourceRoot":"","sources":["../src/abi-encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAGL,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"abi-encode.js","sourceRoot":"","sources":["../src/abi-encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAGL,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AA0ClB;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,GAAiB;IAC9C,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,GAAG,EAAE,GAAG,CAAC,GAAG;KACb,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAA0B;IA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E,cAAc,CAAC,KAAK,CAAC;YAC7B,qEAAqE;YACrE,mBAAmB,EAAE,cAAc,CAAC,kBAAkB,CAAC;YACvD,qEAAqE;YACrE,eAAe,EAAE,UAAU,CAAC,KAAK,CAAC;SACnC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAChB,SAAgC,EAChC,KAAmB,EACnB,cAAkC,EAClC,MAA8B;QAE9B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,uBAAuB,EAAE;YACpD,SAAS,EAAE,iBAAiB,CAAC,SAAS,CAAC;YACvC,qEAAqE;YACrE,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC;YAC7B,qEAAqE;YACrE,eAAe,EAAE,UAAU,CAAC,cAAc,CAAC;YAC3C,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,mBAAmB,CACjB,KAAmB,EACnB,oBAAkC,EAClC,WAA+B;QAE/B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE;YAC7C,qEAAqE;YACrE,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC;YAC7B,qEAAqE;YACrE,qBAAqB,EAAE,cAAc,CAAC,oBAAoB,CAAC;YAC3D,qEAAqE;YACrE,YAAY,EAAE,UAAU,CAAC,WAAW,CAAC;SACtC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAQ;IACzC,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Categorical distribution hint computation.
|
|
3
|
+
*
|
|
4
|
+
* Computes the L2 norm hint for categorical distributions using full
|
|
5
|
+
* SQ128x128 precision. This is the sole hint computation path for
|
|
6
|
+
* multinoulli markets -- no on-chain compute_hints_view calls needed.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { CategoricalL2HintRaw, SQ128x128Raw } from '@the-situation/core';
|
|
11
|
+
/**
|
|
12
|
+
* Computes the L2 norm hint for a categorical distribution in SQ128x128 precision.
|
|
13
|
+
*
|
|
14
|
+
* L2 norm = sqrt(sum(pi^2))
|
|
15
|
+
*
|
|
16
|
+
* @param probs - Array of SQ128x128Raw probability values
|
|
17
|
+
* @returns The L2 norm hint, or null if computation fails
|
|
18
|
+
*/
|
|
19
|
+
export declare function computeCategoricalL2HintSQ128(probs: readonly SQ128x128Raw[]): CategoricalL2HintRaw | null;
|
|
20
|
+
/**
|
|
21
|
+
* Computes L2 norm hint from number probabilities.
|
|
22
|
+
*
|
|
23
|
+
* Convenience function that converts numbers to SQ128x128 first.
|
|
24
|
+
*
|
|
25
|
+
* @param probs - Array of probability values as numbers
|
|
26
|
+
* @returns The L2 norm hint, or null if conversion or computation fails
|
|
27
|
+
*/
|
|
28
|
+
export declare function computeCategoricalL2HintFromNumbers(probs: readonly number[]): CategoricalL2HintRaw | null;
|
|
29
|
+
//# sourceMappingURL=categorical-hints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categorical-hints.d.ts","sourceRoot":"","sources":["../src/categorical-hints.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG9E;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,GAAG,oBAAoB,GAAG,IAAI,CAuBzG;AAED;;;;;;;GAOG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,oBAAoB,GAAG,IAAI,CAQzG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Categorical distribution hint computation.
|
|
3
|
+
*
|
|
4
|
+
* Computes the L2 norm hint for categorical distributions using full
|
|
5
|
+
* SQ128x128 precision. This is the sole hint computation path for
|
|
6
|
+
* multinoulli markets -- no on-chain compute_hints_view calls needed.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { SQ128x128 } from '@the-situation/core';
|
|
11
|
+
import { sqrtSQ128x128 } from './math';
|
|
12
|
+
/**
|
|
13
|
+
* Computes the L2 norm hint for a categorical distribution in SQ128x128 precision.
|
|
14
|
+
*
|
|
15
|
+
* L2 norm = sqrt(sum(pi^2))
|
|
16
|
+
*
|
|
17
|
+
* @param probs - Array of SQ128x128Raw probability values
|
|
18
|
+
* @returns The L2 norm hint, or null if computation fails
|
|
19
|
+
*/
|
|
20
|
+
export function computeCategoricalL2HintSQ128(probs) {
|
|
21
|
+
if (probs.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
// Compute sum of squares: sum(pi^2)
|
|
24
|
+
let sumOfSquares = SQ128x128.fromNumber(0);
|
|
25
|
+
if (!sumOfSquares)
|
|
26
|
+
return null;
|
|
27
|
+
for (const rawP of probs) {
|
|
28
|
+
const p = SQ128x128.fromRaw(rawP);
|
|
29
|
+
if (!p)
|
|
30
|
+
return null;
|
|
31
|
+
const pSquared = p.mul(p);
|
|
32
|
+
if (!pSquared)
|
|
33
|
+
return null;
|
|
34
|
+
sumOfSquares = sumOfSquares.add(pSquared);
|
|
35
|
+
if (!sumOfSquares)
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
// Take square root
|
|
39
|
+
const l2Norm = sqrtSQ128x128(sumOfSquares);
|
|
40
|
+
if (!l2Norm)
|
|
41
|
+
return null;
|
|
42
|
+
return { l2NormHint: l2Norm.toRaw() };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Computes L2 norm hint from number probabilities.
|
|
46
|
+
*
|
|
47
|
+
* Convenience function that converts numbers to SQ128x128 first.
|
|
48
|
+
*
|
|
49
|
+
* @param probs - Array of probability values as numbers
|
|
50
|
+
* @returns The L2 norm hint, or null if conversion or computation fails
|
|
51
|
+
*/
|
|
52
|
+
export function computeCategoricalL2HintFromNumbers(probs) {
|
|
53
|
+
const rawProbs = [];
|
|
54
|
+
for (const p of probs) {
|
|
55
|
+
const sq = SQ128x128.fromNumber(p);
|
|
56
|
+
if (!sq)
|
|
57
|
+
return null;
|
|
58
|
+
rawProbs.push(sq.toRaw());
|
|
59
|
+
}
|
|
60
|
+
return computeCategoricalL2HintSQ128(rawProbs);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=categorical-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categorical-hints.js","sourceRoot":"","sources":["../src/categorical-hints.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAA8B;IAC1E,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpC,oCAAoC;IACpC,IAAI,YAAY,GAAqB,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpB,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE3B,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;IACjC,CAAC;IAED,mBAAmB;IACnB,MAAM,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;AACxC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CAAC,KAAwB;IAC1E,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,6BAA6B,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { type CallRpc, toRpcCall, toRpcCalls } from './call-format';
|
|
|
10
10
|
export { normalizeResponse, snakeToCamel } from './normalize';
|
|
11
11
|
export { SQRT_PI, SQRT_PI_SQ, sqrtSQ128x128 } from './math';
|
|
12
12
|
export { computeBackingDenomHint, computeBackingDenomHintNumber, computeHints, computeHintsFromNumber, computeL2NormDenomHint, computeL2NormDenomHintNumber, } from './hints';
|
|
13
|
-
export {
|
|
13
|
+
export { computeCategoricalL2HintFromNumbers, computeCategoricalL2HintSQ128, } from './categorical-hints';
|
|
14
|
+
export { type AbiCategoricalDistribution, type AbiCategoricalL2Hint, type AbiNormalDistribution, type AbiNormalSqrtHints, type AbiSQ128x128, createTradeEncoder, decodeAbiType, decodeCategoricalDistributionRawType, decodeCategoricalL2HintRawType, decodeNormalDistributionRawType, decodeNormalSqrtHintsRawType, decodeSQ128x128RawType, encodeAbiType, encodeCategoricalDistributionRawType, encodeCategoricalL2HintRawType, encodeNormalDistributionRawType, encodeNormalSqrtHintsRawType, encodeSQ128x128RawType, toAbiCategoricalDistribution, toAbiCategoricalL2Hint, toAbiDistribution, toAbiHints, toAbiSQ128x128, TradeCalldataEncoder, } from './abi-encode';
|
|
14
15
|
export { computeTwap, cumulative256ToNumber, cumulative256ToScaledBigInt, cumulativeDiff, formatCumulative256, } from './cumulative';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,KAAK,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,kBAAkB,EAClB,aAAa,EACb,+BAA+B,EAC/B,4BAA4B,EAC5B,sBAAsB,EACtB,aAAa,EACb,+BAA+B,EAC/B,4BAA4B,EAC5B,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,oBAAoB,GAC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B,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { toRpcCall, toRpcCalls } from './call-format';
|
|
|
10
10
|
export { normalizeResponse, snakeToCamel } from './normalize';
|
|
11
11
|
export { SQRT_PI, SQRT_PI_SQ, sqrtSQ128x128 } from './math';
|
|
12
12
|
export { computeBackingDenomHint, computeBackingDenomHintNumber, computeHints, computeHintsFromNumber, computeL2NormDenomHint, computeL2NormDenomHintNumber, } from './hints';
|
|
13
|
-
export {
|
|
13
|
+
export { computeCategoricalL2HintFromNumbers, computeCategoricalL2HintSQ128, } from './categorical-hints';
|
|
14
|
+
export { createTradeEncoder, decodeAbiType, decodeCategoricalDistributionRawType, decodeCategoricalL2HintRawType, decodeNormalDistributionRawType, decodeNormalSqrtHintsRawType, decodeSQ128x128RawType, encodeAbiType, encodeCategoricalDistributionRawType, encodeCategoricalL2HintRawType, encodeNormalDistributionRawType, encodeNormalSqrtHintsRawType, encodeSQ128x128RawType, toAbiCategoricalDistribution, toAbiCategoricalL2Hint, toAbiDistribution, toAbiHints, toAbiSQ128x128, TradeCalldataEncoder, } from './abi-encode';
|
|
14
15
|
export { computeTwap, cumulative256ToNumber, cumulative256ToScaledBigInt, cumulativeDiff, formatCumulative256, } from './cumulative';
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,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B,EACtB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-situation/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "Utility functions for The Situation SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
15
17
|
"scripts": {
|
|
16
18
|
"build": "tsc -b",
|
|
17
19
|
"typecheck": "tsc -b",
|
|
@@ -19,8 +21,8 @@
|
|
|
19
21
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@the-situation/core": "
|
|
23
|
-
"@the-situation/abi": "
|
|
24
|
+
"@the-situation/core": "workspace:*",
|
|
25
|
+
"@the-situation/abi": "workspace:*",
|
|
24
26
|
"starknet": "^9.2.1"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|