@signals-protocol/v1-sdk 1.0.0

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/fees.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { BigNumberish } from "ethers";
2
+ export type TradeSide = "BUY" | "SELL";
3
+ export type Bytes32Like = `0x${string}`;
4
+ interface FeeQuoteParams {
5
+ trader: string;
6
+ marketId: bigint;
7
+ lowerTick: bigint;
8
+ upperTick: bigint;
9
+ quantity6: bigint;
10
+ baseAmount6: bigint;
11
+ side: TradeSide;
12
+ context: Bytes32Like;
13
+ }
14
+ export interface FeePolicy {
15
+ quote(params: FeeQuoteParams): bigint;
16
+ name?: string;
17
+ }
18
+ export declare const NullFeePolicy: FeePolicy;
19
+ export interface PercentageFeePolicyConfig {
20
+ bps: BigNumberish;
21
+ name?: string;
22
+ }
23
+ export interface CustomFeePolicyConfig {
24
+ bps: BigNumberish;
25
+ name?: string;
26
+ }
27
+ export declare function createPercentageFeePolicy(config: PercentageFeePolicyConfig): FeePolicy;
28
+ export declare function createCustomFeePolicy(config: CustomFeePolicyConfig): FeePolicy;
29
+ export type FeePolicyName = "Null" | "Percentage" | "Custom";
30
+ export declare function getFeePolicy(name: "Null"): FeePolicy;
31
+ export declare function getFeePolicy(name: "Percentage", config: PercentageFeePolicyConfig): FeePolicy;
32
+ export declare function getFeePolicy(name: "Custom", config: CustomFeePolicyConfig): FeePolicy;
33
+ export interface PreviewOpenFeeArgs {
34
+ trader: string;
35
+ marketId: BigNumberish;
36
+ lowerTick: BigNumberish;
37
+ upperTick: BigNumberish;
38
+ quantity6: BigNumberish;
39
+ cost6: BigNumberish;
40
+ context?: Bytes32Like;
41
+ }
42
+ export interface PreviewSellFeeArgs {
43
+ trader: string;
44
+ marketId: BigNumberish;
45
+ lowerTick: BigNumberish;
46
+ upperTick: BigNumberish;
47
+ sellQuantity6: BigNumberish;
48
+ proceeds6: BigNumberish;
49
+ context?: Bytes32Like;
50
+ }
51
+ interface ParsedFeePolicyDescriptor {
52
+ policy: "null" | "percentage" | "custom";
53
+ name?: string;
54
+ bps?: bigint;
55
+ descriptor: string;
56
+ }
57
+ export interface EncodePercentageFeePolicyDescriptorParams {
58
+ bps: BigNumberish;
59
+ name?: string;
60
+ }
61
+ export interface ResolvedFeePolicy {
62
+ policy: FeePolicy;
63
+ descriptor?: ParsedFeePolicyDescriptor;
64
+ }
65
+ export declare function resolveFeePolicyWithMetadata(input: FeePolicy | string): ResolvedFeePolicy;
66
+ declare function quoteOpenFee(policyInput: FeePolicy | string, args: PreviewOpenFeeArgs): bigint;
67
+ declare function quoteSellFee(policyInput: FeePolicy | string, args: PreviewSellFeeArgs): bigint;
68
+ export declare function encodePercentageFeePolicyDescriptor(params: EncodePercentageFeePolicyDescriptorParams): string;
69
+ export { quoteOpenFee, quoteSellFee };
package/dist/fees.js ADDED
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullFeePolicy = void 0;
4
+ exports.createPercentageFeePolicy = createPercentageFeePolicy;
5
+ exports.createCustomFeePolicy = createCustomFeePolicy;
6
+ exports.getFeePolicy = getFeePolicy;
7
+ exports.resolveFeePolicyWithMetadata = resolveFeePolicyWithMetadata;
8
+ exports.encodePercentageFeePolicyDescriptor = encodePercentageFeePolicyDescriptor;
9
+ exports.quoteOpenFee = quoteOpenFee;
10
+ exports.quoteSellFee = quoteSellFee;
11
+ const ethers_1 = require("ethers");
12
+ const ZERO_CONTEXT = `0x${"00".repeat(32)}`;
13
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
14
+ function toBigInt(value) {
15
+ return (0, ethers_1.toBigInt)(value);
16
+ }
17
+ function normalizeContext(context) {
18
+ return (context ?? ZERO_CONTEXT);
19
+ }
20
+ function normalizeTrader(trader) {
21
+ if (!trader) {
22
+ return ZERO_ADDRESS;
23
+ }
24
+ return trader;
25
+ }
26
+ function normalizeMarketId(marketId) {
27
+ if (marketId === undefined || marketId === null) {
28
+ return 0n;
29
+ }
30
+ return toBigInt(marketId);
31
+ }
32
+ exports.NullFeePolicy = Object.freeze({
33
+ quote: () => 0n,
34
+ name: "NullFeePolicy",
35
+ });
36
+ function createPercentageFeePolicy(config) {
37
+ const bps = toBigInt(config.bps);
38
+ const policyName = config.name ?? "PercentageFeePolicy";
39
+ return {
40
+ name: policyName,
41
+ quote: ({ baseAmount6 }) => {
42
+ return (baseAmount6 * bps) / 10000n;
43
+ },
44
+ };
45
+ }
46
+ function createCustomFeePolicy(config) {
47
+ const bps = toBigInt(config.bps);
48
+ const policyName = config.name ?? "CustomFeePolicy";
49
+ return {
50
+ name: policyName,
51
+ quote: ({ baseAmount6 }) => {
52
+ return (baseAmount6 * bps) / 10000n;
53
+ },
54
+ };
55
+ }
56
+ const FeePolicies = Object.freeze({
57
+ Null: exports.NullFeePolicy,
58
+ Percentage: (config) => createPercentageFeePolicy(config),
59
+ Custom: (config) => createCustomFeePolicy(config),
60
+ });
61
+ function getFeePolicy(name, config) {
62
+ if (name === "Null") {
63
+ return FeePolicies.Null;
64
+ }
65
+ if (name === "Percentage") {
66
+ if (!config) {
67
+ throw new Error("Percentage fee policy requires configuration");
68
+ }
69
+ return createPercentageFeePolicy(config);
70
+ }
71
+ if (name === "Custom") {
72
+ if (!config) {
73
+ throw new Error("Custom fee policy requires configuration");
74
+ }
75
+ return createCustomFeePolicy(config);
76
+ }
77
+ throw new Error(`Unsupported fee policy: ${name}`);
78
+ }
79
+ function buildQuoteParams(side, args) {
80
+ return {
81
+ trader: normalizeTrader(args.trader),
82
+ marketId: normalizeMarketId(args.marketId),
83
+ lowerTick: toBigInt(args.lowerTick),
84
+ upperTick: toBigInt(args.upperTick),
85
+ quantity6: side === "BUY"
86
+ ? toBigInt(args.quantity6)
87
+ : toBigInt(args.sellQuantity6),
88
+ baseAmount6: side === "BUY"
89
+ ? toBigInt(args.cost6)
90
+ : toBigInt(args.proceeds6),
91
+ side,
92
+ context: normalizeContext(args.context),
93
+ };
94
+ }
95
+ function parseBigIntParam(value, field, options) {
96
+ if (value === undefined || value === null) {
97
+ if (options?.required) {
98
+ throw new Error(`Missing required parameter '${field}' in fee policy descriptor`);
99
+ }
100
+ return undefined;
101
+ }
102
+ try {
103
+ return toBigInt(value);
104
+ }
105
+ catch {
106
+ throw new Error(`Invalid value for '${field}' in fee policy descriptor: ${value}`);
107
+ }
108
+ }
109
+ function parseFeePolicyDescriptor(descriptor) {
110
+ let parsed;
111
+ try {
112
+ parsed = JSON.parse(descriptor);
113
+ }
114
+ catch (error) {
115
+ throw new Error(`Invalid fee policy descriptor: ${descriptor}. ${String(error)}`);
116
+ }
117
+ if (typeof parsed !== "object" || parsed === null) {
118
+ throw new Error("Fee policy descriptor must be a JSON object");
119
+ }
120
+ const { policy, params } = parsed;
121
+ if (!policy || typeof policy !== "string") {
122
+ throw new Error("Fee policy descriptor must include a string 'policy' field");
123
+ }
124
+ const normalizedPolicy = policy.toLowerCase();
125
+ const paramBag = params ?? {};
126
+ if (normalizedPolicy === "null") {
127
+ return {
128
+ policy: "null",
129
+ name: typeof paramBag.name === "string"
130
+ ? paramBag.name
131
+ : parsed && typeof parsed.name === "string"
132
+ ? parsed.name
133
+ : undefined,
134
+ descriptor,
135
+ };
136
+ }
137
+ if (normalizedPolicy === "percentage") {
138
+ const bps = parseBigIntParam(paramBag.bps, "bps", {
139
+ required: true,
140
+ });
141
+ const name = typeof paramBag.name === "string"
142
+ ? paramBag.name
143
+ : typeof parsed.name === "string"
144
+ ? parsed.name
145
+ : undefined;
146
+ return {
147
+ policy: "percentage",
148
+ name,
149
+ bps,
150
+ descriptor,
151
+ };
152
+ }
153
+ if (normalizedPolicy === "custom") {
154
+ const bps = parseBigIntParam(paramBag.bps, "bps", {
155
+ required: true,
156
+ });
157
+ const name = typeof paramBag.name === "string"
158
+ ? paramBag.name
159
+ : typeof parsed.name === "string"
160
+ ? parsed.name
161
+ : undefined;
162
+ return {
163
+ policy: "custom",
164
+ name,
165
+ bps,
166
+ descriptor,
167
+ };
168
+ }
169
+ throw new Error(`Unsupported fee policy '${policy}' in descriptor`);
170
+ }
171
+ function resolveFeePolicyWithMetadata(input) {
172
+ if (typeof input !== "string") {
173
+ return { policy: input };
174
+ }
175
+ const parsed = parseFeePolicyDescriptor(input);
176
+ if (parsed.policy === "null") {
177
+ if (parsed.name && parsed.name !== exports.NullFeePolicy.name) {
178
+ return {
179
+ policy: {
180
+ quote: exports.NullFeePolicy.quote,
181
+ name: parsed.name,
182
+ },
183
+ descriptor: parsed,
184
+ };
185
+ }
186
+ return { policy: exports.NullFeePolicy, descriptor: parsed };
187
+ }
188
+ if (parsed.policy === "custom") {
189
+ const customPolicy = createCustomFeePolicy({
190
+ bps: parsed.bps,
191
+ name: parsed.name,
192
+ });
193
+ return {
194
+ policy: customPolicy,
195
+ descriptor: parsed,
196
+ };
197
+ }
198
+ const percentagePolicy = createPercentageFeePolicy({
199
+ bps: parsed.bps,
200
+ name: parsed.name,
201
+ });
202
+ return {
203
+ policy: percentagePolicy,
204
+ descriptor: parsed,
205
+ };
206
+ }
207
+ function quoteOpenFee(policyInput, args) {
208
+ const { policy } = resolveFeePolicyWithMetadata(policyInput);
209
+ return policy.quote(buildQuoteParams("BUY", args));
210
+ }
211
+ function quoteSellFee(policyInput, args) {
212
+ const { policy } = resolveFeePolicyWithMetadata(policyInput);
213
+ return policy.quote(buildQuoteParams("SELL", args));
214
+ }
215
+ function encodePercentageFeePolicyDescriptor(params) {
216
+ const bps = toBigInt(params.bps);
217
+ if (bps < 0n) {
218
+ throw new Error("Fee bps must be non-negative");
219
+ }
220
+ const descriptor = {
221
+ policy: "percentage",
222
+ params: {
223
+ bps: bps.toString(),
224
+ ...(params.name ? { name: params.name } : {}),
225
+ },
226
+ ...(params.name ? { name: params.name } : {}),
227
+ };
228
+ return JSON.stringify(descriptor);
229
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Signals v1 SDK for TypeScript
3
+ *
4
+ * 컨트랙트 뷰함수들과 역함수 제공
5
+ */
6
+ export { CLMSRSDK } from "./clmsr-sdk";
7
+ export { CLMSRSDK as SignalsSDK } from "./clmsr-sdk";
8
+ export { WADAmount, USDCAmount, Quantity, Tick, MarketDistributionRaw, MarketRaw, Market, MarketDistribution, Position, mapMarket, mapDistribution, OpenCostResult, IncreaseCostResult, DecreaseProceedsResult, CloseProceedsResult, ClaimResult, QuantityFromCostResult, QuantityFromProceedsResult, PositionValueResult, FeeInfo, ValidationError, CalculationError, } from "./types";
9
+ export * as MathUtils from "./utils/math";
10
+ export { toWAD, toMicroUSDC } from "./clmsr-sdk";
11
+ export { createCLMSRSDK, createSignalsSDK } from "./clmsr-sdk";
12
+ export declare const VERSION = "1.0.0";
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Signals v1 SDK for TypeScript
4
+ *
5
+ * 컨트랙트 뷰함수들과 역함수 제공
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.VERSION = exports.createSignalsSDK = exports.createCLMSRSDK = exports.toMicroUSDC = exports.toWAD = exports.MathUtils = exports.CalculationError = exports.ValidationError = exports.mapDistribution = exports.mapMarket = exports.SignalsSDK = exports.CLMSRSDK = void 0;
42
+ // Export main SDK class
43
+ var clmsr_sdk_1 = require("./clmsr-sdk");
44
+ Object.defineProperty(exports, "CLMSRSDK", { enumerable: true, get: function () { return clmsr_sdk_1.CLMSRSDK; } });
45
+ var clmsr_sdk_2 = require("./clmsr-sdk");
46
+ Object.defineProperty(exports, "SignalsSDK", { enumerable: true, get: function () { return clmsr_sdk_2.CLMSRSDK; } });
47
+ // Export types
48
+ var types_1 = require("./types");
49
+ // Data adapters
50
+ Object.defineProperty(exports, "mapMarket", { enumerable: true, get: function () { return types_1.mapMarket; } });
51
+ Object.defineProperty(exports, "mapDistribution", { enumerable: true, get: function () { return types_1.mapDistribution; } });
52
+ // Errors
53
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
54
+ Object.defineProperty(exports, "CalculationError", { enumerable: true, get: function () { return types_1.CalculationError; } });
55
+ // Export utility functions
56
+ exports.MathUtils = __importStar(require("./utils/math"));
57
+ // Convenience functions
58
+ var clmsr_sdk_3 = require("./clmsr-sdk");
59
+ Object.defineProperty(exports, "toWAD", { enumerable: true, get: function () { return clmsr_sdk_3.toWAD; } });
60
+ Object.defineProperty(exports, "toMicroUSDC", { enumerable: true, get: function () { return clmsr_sdk_3.toMicroUSDC; } });
61
+ var clmsr_sdk_4 = require("./clmsr-sdk");
62
+ Object.defineProperty(exports, "createCLMSRSDK", { enumerable: true, get: function () { return clmsr_sdk_4.createCLMSRSDK; } });
63
+ Object.defineProperty(exports, "createSignalsSDK", { enumerable: true, get: function () { return clmsr_sdk_4.createSignalsSDK; } });
64
+ // Version (keep in sync with package.json)
65
+ exports.VERSION = "1.0.0";
@@ -0,0 +1,161 @@
1
+ import Big from "big.js";
2
+ /** WAD format amount (18 decimals) */
3
+ export type WADAmount = Big;
4
+ /** USDC amount (6 decimals) */
5
+ export type USDCAmount = Big;
6
+ /** Trade quantity (also 6 decimals like USDC) */
7
+ export type Quantity = Big;
8
+ /** Tick value (int256) */
9
+ export type Tick = number;
10
+ /** Raw market distribution data from GraphQL (문자열 형태) */
11
+ export interface MarketDistributionRaw {
12
+ totalSum: string;
13
+ binFactors: string[];
14
+ minFactor?: string;
15
+ maxFactor?: string;
16
+ avgFactor?: string;
17
+ totalVolume?: string;
18
+ binVolumes?: string[];
19
+ tickRanges?: string[];
20
+ }
21
+ /** Raw market data from GraphQL */
22
+ export interface MarketRaw {
23
+ liquidityParameter: string;
24
+ minTick: number;
25
+ maxTick: number;
26
+ tickSpacing: number;
27
+ feePolicyDescriptor?: string;
28
+ isSettled?: boolean;
29
+ settlementValue?: string;
30
+ settlementTick?: number;
31
+ }
32
+ /** Market data for SDK calculations (숫자 객체만) */
33
+ export interface Market {
34
+ liquidityParameter: WADAmount;
35
+ minTick: Tick;
36
+ maxTick: Tick;
37
+ tickSpacing: Tick;
38
+ feePolicyDescriptor?: string;
39
+ isSettled?: boolean;
40
+ settlementValue?: USDCAmount;
41
+ settlementTick?: Tick;
42
+ }
43
+ /** Market distribution data for SDK calculations (WAD 기반) */
44
+ export interface MarketDistribution {
45
+ totalSum: WADAmount;
46
+ binFactors: WADAmount[];
47
+ minFactor?: WADAmount;
48
+ maxFactor?: WADAmount;
49
+ avgFactor?: WADAmount;
50
+ totalVolume?: USDCAmount;
51
+ binVolumes?: USDCAmount[];
52
+ tickRanges?: string[];
53
+ }
54
+ /** Position data */
55
+ export interface Position {
56
+ lowerTick: Tick;
57
+ upperTick: Tick;
58
+ quantity: Quantity;
59
+ }
60
+ export declare const FeePolicyKind: {
61
+ readonly Null: "null";
62
+ readonly Percentage: "percentage";
63
+ readonly Custom: "custom";
64
+ };
65
+ export type FeePolicyKind = (typeof FeePolicyKind)[keyof typeof FeePolicyKind];
66
+ interface BaseFeeInfo {
67
+ policy: FeePolicyKind;
68
+ descriptor?: string;
69
+ name?: string;
70
+ }
71
+ interface NullFeeInfo extends BaseFeeInfo {
72
+ policy: typeof FeePolicyKind.Null;
73
+ }
74
+ interface PercentageFeeInfo extends BaseFeeInfo {
75
+ policy: typeof FeePolicyKind.Percentage;
76
+ bps: Big;
77
+ }
78
+ interface CustomFeeInfo extends BaseFeeInfo {
79
+ policy: typeof FeePolicyKind.Custom;
80
+ }
81
+ export type FeeInfo = NullFeeInfo | PercentageFeeInfo | CustomFeeInfo;
82
+ /**
83
+ * Convert raw GraphQL market data to SDK calculation format
84
+ * @param raw Raw market data from GraphQL
85
+ * @returns Market data for SDK calculations
86
+ */
87
+ export declare function mapMarket(raw: MarketRaw): Market;
88
+ /**
89
+ * Convert raw GraphQL distribution data to SDK calculation format
90
+ * @param raw Raw distribution data from GraphQL
91
+ * @returns Distribution data for SDK calculations
92
+ */
93
+ export declare function mapDistribution(raw: MarketDistributionRaw): MarketDistribution;
94
+ /** calculateOpenCost 결과 */
95
+ export interface OpenCostResult {
96
+ cost: USDCAmount;
97
+ averagePrice: USDCAmount;
98
+ feeAmount: USDCAmount;
99
+ feeRate: Big;
100
+ feeInfo: FeeInfo;
101
+ }
102
+ /** calculateIncreaseCost 결과 */
103
+ export interface IncreaseCostResult {
104
+ additionalCost: USDCAmount;
105
+ averagePrice: USDCAmount;
106
+ feeAmount: USDCAmount;
107
+ feeRate: Big;
108
+ feeInfo: FeeInfo;
109
+ }
110
+ /** calculateDecreaseProceeds 결과 */
111
+ export interface DecreaseProceedsResult {
112
+ proceeds: USDCAmount;
113
+ averagePrice: USDCAmount;
114
+ feeAmount: USDCAmount;
115
+ feeRate: Big;
116
+ feeInfo: FeeInfo;
117
+ }
118
+ /** calculateCloseProceeds 결과 */
119
+ export interface CloseProceedsResult {
120
+ proceeds: USDCAmount;
121
+ averagePrice: USDCAmount;
122
+ feeAmount: USDCAmount;
123
+ feeRate: Big;
124
+ feeInfo: FeeInfo;
125
+ }
126
+ /** calculateClaim 결과 */
127
+ export interface ClaimResult {
128
+ payout: USDCAmount;
129
+ }
130
+ /** calculateQuantityFromCost 결과 */
131
+ export interface QuantityFromCostResult {
132
+ quantity: Quantity;
133
+ actualCost: USDCAmount;
134
+ feeAmount: USDCAmount;
135
+ feeRate: Big;
136
+ feeInfo: FeeInfo;
137
+ }
138
+ /** calculateQuantityFromProceeds 결과 (매도용 역함수) */
139
+ export interface QuantityFromProceedsResult {
140
+ quantity: Quantity;
141
+ actualProceeds: USDCAmount;
142
+ feeAmount: USDCAmount;
143
+ feeRate: Big;
144
+ feeInfo: FeeInfo;
145
+ }
146
+ /** calculatePositionValue 결과 (포지션 현재 가치 계산) */
147
+ export interface PositionValueResult {
148
+ currentValue: USDCAmount;
149
+ unrealizedPnL: USDCAmount;
150
+ averagePrice: USDCAmount;
151
+ feeAmount: USDCAmount;
152
+ feeRate: Big;
153
+ feeInfo: FeeInfo;
154
+ }
155
+ export declare class ValidationError extends Error {
156
+ constructor(message: string);
157
+ }
158
+ export declare class CalculationError extends Error {
159
+ constructor(message: string);
160
+ }
161
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CalculationError = exports.ValidationError = exports.FeePolicyKind = void 0;
7
+ exports.mapMarket = mapMarket;
8
+ exports.mapDistribution = mapDistribution;
9
+ const big_js_1 = __importDefault(require("big.js"));
10
+ // ============================================================================
11
+ // FEE DETAILS
12
+ // ============================================================================
13
+ exports.FeePolicyKind = {
14
+ Null: "null",
15
+ Percentage: "percentage",
16
+ Custom: "custom",
17
+ };
18
+ // ============================================================================
19
+ // DATA ADAPTERS (GraphQL ↔ SDK 타입 변환)
20
+ // ============================================================================
21
+ /**
22
+ * Convert raw GraphQL market data to SDK calculation format
23
+ * @param raw Raw market data from GraphQL
24
+ * @returns Market data for SDK calculations
25
+ */
26
+ function mapMarket(raw) {
27
+ return {
28
+ liquidityParameter: new big_js_1.default(raw.liquidityParameter),
29
+ minTick: raw.minTick,
30
+ maxTick: raw.maxTick,
31
+ tickSpacing: raw.tickSpacing,
32
+ ...(raw.feePolicyDescriptor !== undefined && {
33
+ feePolicyDescriptor: raw.feePolicyDescriptor,
34
+ }),
35
+ ...(raw.isSettled !== undefined && { isSettled: raw.isSettled }),
36
+ ...(raw.settlementValue !== undefined && {
37
+ settlementValue: new big_js_1.default(raw.settlementValue),
38
+ }),
39
+ ...(raw.settlementTick !== undefined && {
40
+ settlementTick: raw.settlementTick,
41
+ }),
42
+ };
43
+ }
44
+ /**
45
+ * Convert raw GraphQL distribution data to SDK calculation format
46
+ * @param raw Raw distribution data from GraphQL
47
+ * @returns Distribution data for SDK calculations
48
+ */
49
+ function mapDistribution(raw) {
50
+ return {
51
+ // 필수 필드들
52
+ totalSum: new big_js_1.default(raw.totalSum),
53
+ binFactors: raw.binFactors.map((s) => new big_js_1.default(s)),
54
+ // 선택적 필드들 (정보성, 계산에 사용되지 않음)
55
+ ...(raw.minFactor !== undefined && { minFactor: new big_js_1.default(raw.minFactor) }),
56
+ ...(raw.maxFactor !== undefined && { maxFactor: new big_js_1.default(raw.maxFactor) }),
57
+ ...(raw.avgFactor !== undefined && { avgFactor: new big_js_1.default(raw.avgFactor) }),
58
+ ...(raw.totalVolume !== undefined && {
59
+ totalVolume: new big_js_1.default(raw.totalVolume),
60
+ }),
61
+ ...(raw.binVolumes !== undefined && {
62
+ binVolumes: raw.binVolumes.map((s) => new big_js_1.default(s)),
63
+ }),
64
+ ...(raw.tickRanges !== undefined && { tickRanges: raw.tickRanges }),
65
+ };
66
+ }
67
+ // ============================================================================
68
+ // ERRORS
69
+ // ============================================================================
70
+ class ValidationError extends Error {
71
+ constructor(message) {
72
+ super(message);
73
+ this.name = "ValidationError";
74
+ }
75
+ }
76
+ exports.ValidationError = ValidationError;
77
+ class CalculationError extends Error {
78
+ constructor(message) {
79
+ super(message);
80
+ this.name = "CalculationError";
81
+ }
82
+ }
83
+ exports.CalculationError = CalculationError;