@lightconexyz/lightcone-sdk 0.1.0 → 0.2.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/README.md +33 -206
- package/dist/auth/client.d.ts +25 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +120 -0
- package/dist/auth/client.js.map +1 -0
- package/dist/auth/index.d.ts +73 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +42 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/native.d.ts +8 -0
- package/dist/auth/native.d.ts.map +1 -0
- package/dist/auth/native.js +19 -0
- package/dist/auth/native.js.map +1 -0
- package/dist/auth.d.ts +1 -79
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +15 -145
- package/dist/auth.js.map +1 -1
- package/dist/client.d.ts +69 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +158 -0
- package/dist/client.js.map +1 -0
- package/dist/domain/admin/client.d.ts +17 -0
- package/dist/domain/admin/client.d.ts.map +1 -0
- package/dist/domain/admin/client.js +32 -0
- package/dist/domain/admin/client.js.map +1 -0
- package/dist/domain/admin/index.d.ts +7 -0
- package/dist/domain/admin/index.d.ts.map +1 -0
- package/dist/domain/admin/index.js +19 -0
- package/dist/domain/admin/index.js.map +1 -0
- package/dist/domain/admin/wire.d.ts +117 -0
- package/dist/domain/admin/wire.d.ts.map +1 -0
- package/dist/domain/admin/wire.js +3 -0
- package/dist/domain/admin/wire.js.map +1 -0
- package/dist/domain/index.d.ts +9 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +45 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/market/client.d.ts +21 -0
- package/dist/domain/market/client.d.ts.map +1 -0
- package/dist/domain/market/client.js +70 -0
- package/dist/domain/market/client.js.map +1 -0
- package/dist/domain/market/convert.d.ts +8 -0
- package/dist/domain/market/convert.d.ts.map +1 -0
- package/dist/domain/market/convert.js +96 -0
- package/dist/domain/market/convert.js.map +1 -0
- package/dist/domain/market/index.d.ts +47 -0
- package/dist/domain/market/index.d.ts.map +1 -0
- package/dist/domain/market/index.js +58 -0
- package/dist/domain/market/index.js.map +1 -0
- package/dist/domain/market/outcome.d.ts +12 -0
- package/dist/domain/market/outcome.d.ts.map +1 -0
- package/dist/domain/market/outcome.js +28 -0
- package/dist/domain/market/outcome.js.map +1 -0
- package/dist/domain/market/tokens.d.ts +42 -0
- package/dist/domain/market/tokens.d.ts.map +1 -0
- package/dist/domain/market/tokens.js +106 -0
- package/dist/domain/market/tokens.js.map +1 -0
- package/dist/domain/market/wire.d.ts +116 -0
- package/dist/domain/market/wire.d.ts.map +1 -0
- package/dist/domain/market/wire.js +3 -0
- package/dist/domain/market/wire.js.map +1 -0
- package/dist/domain/order/client.d.ts +187 -0
- package/dist/domain/order/client.d.ts.map +1 -0
- package/dist/domain/order/client.js +122 -0
- package/dist/domain/order/client.js.map +1 -0
- package/dist/domain/order/convert.d.ts +8 -0
- package/dist/domain/order/convert.d.ts.map +1 -0
- package/dist/domain/order/convert.js +80 -0
- package/dist/domain/order/convert.js.map +1 -0
- package/dist/domain/order/index.d.ts +48 -0
- package/dist/domain/order/index.d.ts.map +1 -0
- package/dist/domain/order/index.js +41 -0
- package/dist/domain/order/index.js.map +1 -0
- package/dist/domain/order/state.d.ts +26 -0
- package/dist/domain/order/state.d.ts.map +1 -0
- package/dist/domain/order/state.js +85 -0
- package/dist/domain/order/state.js.map +1 -0
- package/dist/domain/order/wire.d.ts +123 -0
- package/dist/domain/order/wire.d.ts.map +1 -0
- package/dist/domain/order/wire.js +3 -0
- package/dist/domain/order/wire.js.map +1 -0
- package/dist/domain/orderbook/client.d.ts +20 -0
- package/dist/domain/orderbook/client.d.ts.map +1 -0
- package/dist/domain/orderbook/client.js +30 -0
- package/dist/domain/orderbook/client.js.map +1 -0
- package/dist/domain/orderbook/convert.d.ts +5 -0
- package/dist/domain/orderbook/convert.d.ts.map +1 -0
- package/dist/domain/orderbook/convert.js +34 -0
- package/dist/domain/orderbook/convert.js.map +1 -0
- package/dist/domain/orderbook/index.d.ts +36 -0
- package/dist/domain/orderbook/index.d.ts.map +1 -0
- package/dist/domain/orderbook/index.js +63 -0
- package/dist/domain/orderbook/index.js.map +1 -0
- package/dist/domain/orderbook/state.d.ts +19 -0
- package/dist/domain/orderbook/state.d.ts.map +1 -0
- package/dist/domain/orderbook/state.js +86 -0
- package/dist/domain/orderbook/state.js.map +1 -0
- package/dist/domain/orderbook/ticker.d.ts +8 -0
- package/dist/domain/orderbook/ticker.d.ts.map +1 -0
- package/dist/domain/orderbook/ticker.js +3 -0
- package/dist/domain/orderbook/ticker.js.map +1 -0
- package/dist/domain/orderbook/wire.d.ts +61 -0
- package/dist/domain/orderbook/wire.d.ts.map +1 -0
- package/dist/domain/orderbook/wire.js +3 -0
- package/dist/domain/orderbook/wire.js.map +1 -0
- package/dist/domain/position/client.d.ts +13 -0
- package/dist/domain/position/client.d.ts.map +1 -0
- package/dist/domain/position/client.js +20 -0
- package/dist/domain/position/client.js.map +1 -0
- package/dist/domain/position/index.d.ts +66 -0
- package/dist/domain/position/index.d.ts.map +1 -0
- package/dist/domain/position/index.js +19 -0
- package/dist/domain/position/index.js.map +1 -0
- package/dist/domain/position/wire.d.ts +29 -0
- package/dist/domain/position/wire.d.ts.map +1 -0
- package/dist/domain/position/wire.js +3 -0
- package/dist/domain/position/wire.js.map +1 -0
- package/dist/domain/price_history/client.d.ts +12 -0
- package/dist/domain/price_history/client.d.ts.map +1 -0
- package/dist/domain/price_history/client.js +24 -0
- package/dist/domain/price_history/client.js.map +1 -0
- package/dist/domain/price_history/index.d.ts +14 -0
- package/dist/domain/price_history/index.d.ts.map +1 -0
- package/dist/domain/price_history/index.js +27 -0
- package/dist/domain/price_history/index.js.map +1 -0
- package/dist/domain/price_history/state.d.ts +11 -0
- package/dist/domain/price_history/state.d.ts.map +1 -0
- package/dist/domain/price_history/state.js +35 -0
- package/dist/domain/price_history/state.js.map +1 -0
- package/dist/domain/price_history/wire.d.ts +47 -0
- package/dist/domain/price_history/wire.d.ts.map +1 -0
- package/dist/domain/price_history/wire.js +3 -0
- package/dist/domain/price_history/wire.js.map +1 -0
- package/dist/domain/referral/client.d.ts +13 -0
- package/dist/domain/referral/client.d.ts.map +1 -0
- package/dist/domain/referral/client.js +34 -0
- package/dist/domain/referral/client.js.map +1 -0
- package/dist/domain/referral/index.d.ts +17 -0
- package/dist/domain/referral/index.d.ts.map +1 -0
- package/dist/domain/referral/index.js +19 -0
- package/dist/domain/referral/index.js.map +1 -0
- package/dist/domain/referral/wire.d.ts +22 -0
- package/dist/domain/referral/wire.d.ts.map +1 -0
- package/dist/domain/referral/wire.js +3 -0
- package/dist/domain/referral/wire.js.map +1 -0
- package/dist/domain/trade/client.d.ts +12 -0
- package/dist/domain/trade/client.d.ts.map +1 -0
- package/dist/domain/trade/client.js +27 -0
- package/dist/domain/trade/client.js.map +1 -0
- package/dist/domain/trade/convert.d.ts +5 -0
- package/dist/domain/trade/convert.d.ts.map +1 -0
- package/dist/domain/trade/convert.js +25 -0
- package/dist/domain/trade/convert.js.map +1 -0
- package/dist/domain/trade/index.d.ts +19 -0
- package/dist/domain/trade/index.d.ts.map +1 -0
- package/dist/domain/trade/index.js +24 -0
- package/dist/domain/trade/index.js.map +1 -0
- package/dist/domain/trade/state.d.ts +16 -0
- package/dist/domain/trade/state.d.ts.map +1 -0
- package/dist/domain/trade/state.js +40 -0
- package/dist/domain/trade/state.js.map +1 -0
- package/dist/domain/trade/wire.d.ts +34 -0
- package/dist/domain/trade/wire.d.ts.map +1 -0
- package/dist/domain/trade/wire.js +3 -0
- package/dist/domain/trade/wire.js.map +1 -0
- package/dist/error.d.ts +44 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +126 -0
- package/dist/error.js.map +1 -0
- package/dist/http/client.d.ts +16 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +146 -0
- package/dist/http/client.js.map +1 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +12 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/retry.d.ts +30 -0
- package/dist/http/retry.d.ts.map +1 -0
- package/dist/http/retry.js +48 -0
- package/dist/http/retry.js.map +1 -0
- package/dist/index.d.ts +13 -51
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -68
- package/dist/index.js.map +1 -1
- package/dist/network.d.ts +4 -4
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +4 -4
- package/dist/network.js.map +1 -1
- package/dist/prelude.d.ts +41 -0
- package/dist/prelude.d.ts.map +1 -0
- package/dist/prelude.js +55 -0
- package/dist/prelude.js.map +1 -0
- package/dist/privy/client.d.ts +17 -0
- package/dist/privy/client.d.ts.map +1 -0
- package/dist/privy/client.js +66 -0
- package/dist/privy/client.js.map +1 -0
- package/dist/privy/index.d.ts +57 -0
- package/dist/privy/index.d.ts.map +1 -0
- package/dist/privy/index.js +80 -0
- package/dist/privy/index.js.map +1 -0
- package/dist/program/accounts.d.ts +19 -2
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +52 -2
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/builder.d.ts +15 -11
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +30 -22
- package/dist/program/builder.js.map +1 -1
- package/dist/program/client.d.ts +40 -1
- package/dist/program/client.d.ts.map +1 -1
- package/dist/program/client.js +87 -2
- package/dist/program/client.js.map +1 -1
- package/dist/program/constants.d.ts +10 -1
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +11 -2
- package/dist/program/constants.js.map +1 -1
- package/dist/program/envelope.d.ts +94 -0
- package/dist/program/envelope.d.ts.map +1 -0
- package/dist/program/envelope.js +258 -0
- package/dist/program/envelope.js.map +1 -0
- package/dist/program/error.d.ts +8 -0
- package/dist/program/error.d.ts.map +1 -0
- package/dist/program/error.js +20 -0
- package/dist/program/error.js.map +1 -0
- package/dist/program/index.d.ts +8 -5
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +29 -3
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +124 -1
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +439 -4
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.d.ts +26 -8
- package/dist/program/orders.d.ts.map +1 -1
- package/dist/program/orders.js +58 -31
- package/dist/program/orders.js.map +1 -1
- package/dist/program/pda.d.ts +19 -0
- package/dist/program/pda.d.ts.map +1 -1
- package/dist/program/pda.js +28 -0
- package/dist/program/pda.js.map +1 -1
- package/dist/program/types.d.ts +93 -9
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/shared/fmt/decimal.d.ts +5 -0
- package/dist/shared/fmt/decimal.d.ts.map +1 -0
- package/dist/shared/fmt/decimal.js +54 -0
- package/dist/shared/fmt/decimal.js.map +1 -0
- package/dist/shared/fmt/index.d.ts +3 -0
- package/dist/shared/fmt/index.d.ts.map +1 -0
- package/dist/shared/fmt/index.js +39 -0
- package/dist/shared/fmt/index.js.map +1 -0
- package/dist/shared/fmt/num.d.ts +6 -0
- package/dist/shared/fmt/num.d.ts.map +1 -0
- package/dist/shared/fmt/num.js +44 -0
- package/dist/shared/fmt/num.js.map +1 -0
- package/dist/shared/index.d.ts +4 -7
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +19 -7
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/price.d.ts +5 -33
- package/dist/shared/price.d.ts.map +1 -1
- package/dist/shared/price.js +11 -39
- package/dist/shared/price.js.map +1 -1
- package/dist/shared/scaling.d.ts +17 -30
- package/dist/shared/scaling.d.ts.map +1 -1
- package/dist/shared/scaling.js +88 -57
- package/dist/shared/scaling.js.map +1 -1
- package/dist/shared/types.d.ts +66 -16
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +81 -17
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/client.d.ts +35 -0
- package/dist/ws/client.d.ts.map +1 -0
- package/dist/ws/client.js +226 -0
- package/dist/ws/client.js.map +1 -0
- package/dist/ws/index.d.ts +109 -0
- package/dist/ws/index.d.ts.map +1 -0
- package/dist/ws/index.js +181 -0
- package/dist/ws/index.js.map +1 -0
- package/dist/ws/subscriptions.d.ts +51 -0
- package/dist/ws/subscriptions.d.ts.map +1 -0
- package/dist/ws/subscriptions.js +44 -0
- package/dist/ws/subscriptions.js.map +1 -0
- package/package.json +3 -11
- package/dist/api/client.d.ts +0 -225
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/client.js +0 -452
- package/dist/api/client.js.map +0 -1
- package/dist/api/error.d.ts +0 -58
- package/dist/api/error.d.ts.map +0 -1
- package/dist/api/error.js +0 -98
- package/dist/api/error.js.map +0 -1
- package/dist/api/index.d.ts +0 -23
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -51
- package/dist/api/index.js.map +0 -1
- package/dist/api/types/admin.d.ts +0 -49
- package/dist/api/types/admin.d.ts.map +0 -1
- package/dist/api/types/admin.js +0 -13
- package/dist/api/types/admin.js.map +0 -1
- package/dist/api/types/index.d.ts +0 -14
- package/dist/api/types/index.d.ts.map +0 -1
- package/dist/api/types/index.js +0 -13
- package/dist/api/types/index.js.map +0 -1
- package/dist/api/types/market.d.ts +0 -186
- package/dist/api/types/market.d.ts.map +0 -1
- package/dist/api/types/market.js +0 -6
- package/dist/api/types/market.js.map +0 -1
- package/dist/api/types/order.d.ts +0 -190
- package/dist/api/types/order.d.ts.map +0 -1
- package/dist/api/types/order.js +0 -6
- package/dist/api/types/order.js.map +0 -1
- package/dist/api/types/orderbook.d.ts +0 -36
- package/dist/api/types/orderbook.d.ts.map +0 -1
- package/dist/api/types/orderbook.js +0 -6
- package/dist/api/types/orderbook.js.map +0 -1
- package/dist/api/types/position.d.ts +0 -60
- package/dist/api/types/position.d.ts.map +0 -1
- package/dist/api/types/position.js +0 -6
- package/dist/api/types/position.js.map +0 -1
- package/dist/api/types/price_history.d.ts +0 -68
- package/dist/api/types/price_history.d.ts.map +0 -1
- package/dist/api/types/price_history.js +0 -13
- package/dist/api/types/price_history.js.map +0 -1
- package/dist/api/types/trade.d.ts +0 -67
- package/dist/api/types/trade.d.ts.map +0 -1
- package/dist/api/types/trade.js +0 -13
- package/dist/api/types/trade.js.map +0 -1
- package/dist/api/validation.d.ts +0 -24
- package/dist/api/validation.d.ts.map +0 -1
- package/dist/api/validation.js +0 -53
- package/dist/api/validation.js.map +0 -1
- package/dist/websocket/client.d.ts +0 -238
- package/dist/websocket/client.d.ts.map +0 -1
- package/dist/websocket/client.js +0 -580
- package/dist/websocket/client.js.map +0 -1
- package/dist/websocket/error.d.ts +0 -47
- package/dist/websocket/error.d.ts.map +0 -1
- package/dist/websocket/error.js +0 -83
- package/dist/websocket/error.js.map +0 -1
- package/dist/websocket/handlers.d.ts +0 -97
- package/dist/websocket/handlers.d.ts.map +0 -1
- package/dist/websocket/handlers.js +0 -277
- package/dist/websocket/handlers.js.map +0 -1
- package/dist/websocket/index.d.ts +0 -38
- package/dist/websocket/index.d.ts.map +0 -1
- package/dist/websocket/index.js +0 -75
- package/dist/websocket/index.js.map +0 -1
- package/dist/websocket/state/index.d.ts +0 -7
- package/dist/websocket/state/index.d.ts.map +0 -1
- package/dist/websocket/state/index.js +0 -14
- package/dist/websocket/state/index.js.map +0 -1
- package/dist/websocket/state/orderbook.d.ts +0 -107
- package/dist/websocket/state/orderbook.d.ts.map +0 -1
- package/dist/websocket/state/orderbook.js +0 -293
- package/dist/websocket/state/orderbook.js.map +0 -1
- package/dist/websocket/state/price.d.ts +0 -108
- package/dist/websocket/state/price.d.ts.map +0 -1
- package/dist/websocket/state/price.js +0 -243
- package/dist/websocket/state/price.js.map +0 -1
- package/dist/websocket/state/user.d.ts +0 -83
- package/dist/websocket/state/user.d.ts.map +0 -1
- package/dist/websocket/state/user.js +0 -228
- package/dist/websocket/state/user.js.map +0 -1
- package/dist/websocket/subscriptions.d.ts +0 -143
- package/dist/websocket/subscriptions.d.ts.map +0 -1
- package/dist/websocket/subscriptions.js +0 -244
- package/dist/websocket/subscriptions.js.map +0 -1
- package/dist/websocket/types.d.ts +0 -417
- package/dist/websocket/types.d.ts.map +0 -1
- package/dist/websocket/types.js +0 -195
- package/dist/websocket/types.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.num = exports.decimal = void 0;
|
|
37
|
+
exports.decimal = __importStar(require("./decimal"));
|
|
38
|
+
exports.num = __importStar(require("./num"));
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/fmt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqC;AACrC,6CAA6B","sourcesContent":["export * as decimal from \"./decimal\";\nexport * as num from \"./num\";\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function displayFormattedString(input: string): string;
|
|
2
|
+
export declare function displayWithDecimals(value: number, decimals: number): string;
|
|
3
|
+
export declare function display(value: number): string;
|
|
4
|
+
export declare function toDecimalValue(value: bigint, decimals: number): number;
|
|
5
|
+
export declare function fromDecimalValue(value: number, decimals: number): bigint;
|
|
6
|
+
//# sourceMappingURL=num.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../../../src/shared/fmt/num.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAa5D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAe7C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.displayFormattedString = displayFormattedString;
|
|
4
|
+
exports.displayWithDecimals = displayWithDecimals;
|
|
5
|
+
exports.display = display;
|
|
6
|
+
exports.toDecimalValue = toDecimalValue;
|
|
7
|
+
exports.fromDecimalValue = fromDecimalValue;
|
|
8
|
+
function displayFormattedString(input) {
|
|
9
|
+
const [rawInteger, rawFraction] = input.split(".");
|
|
10
|
+
const negative = rawInteger.startsWith("-");
|
|
11
|
+
const integer = negative ? rawInteger.slice(1) : rawInteger;
|
|
12
|
+
const withCommas = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
13
|
+
const fraction = rawFraction?.replace(/0+$/, "");
|
|
14
|
+
const prefix = negative ? "-" : "";
|
|
15
|
+
if (!fraction) {
|
|
16
|
+
return `${prefix}${withCommas}`;
|
|
17
|
+
}
|
|
18
|
+
return `${prefix}${withCommas}.${fraction}`;
|
|
19
|
+
}
|
|
20
|
+
function displayWithDecimals(value, decimals) {
|
|
21
|
+
return displayFormattedString(value.toFixed(decimals));
|
|
22
|
+
}
|
|
23
|
+
function display(value) {
|
|
24
|
+
if (Math.abs(value) >= 100) {
|
|
25
|
+
return displayWithDecimals(value, 0);
|
|
26
|
+
}
|
|
27
|
+
if (Math.abs(value) >= 1) {
|
|
28
|
+
return displayWithDecimals(value, 2);
|
|
29
|
+
}
|
|
30
|
+
if (value === 0) {
|
|
31
|
+
return "0";
|
|
32
|
+
}
|
|
33
|
+
const abs = Math.abs(value);
|
|
34
|
+
const exponent = Math.floor(Math.log10(abs));
|
|
35
|
+
const decimals = Math.min(Math.max(Math.abs(exponent) + 2, 2), 8);
|
|
36
|
+
return displayWithDecimals(value, decimals);
|
|
37
|
+
}
|
|
38
|
+
function toDecimalValue(value, decimals) {
|
|
39
|
+
return Number(value) / 10 ** decimals;
|
|
40
|
+
}
|
|
41
|
+
function fromDecimalValue(value, decimals) {
|
|
42
|
+
return BigInt(Math.trunc(value * 10 ** decimals));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=num.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"num.js","sourceRoot":"","sources":["../../../src/shared/fmt/num.ts"],"names":[],"mappings":";;AAAA,wDAaC;AAED,kDAEC;AAED,0BAeC;AAED,wCAEC;AAED,4CAEC;AA1CD,SAAgB,sBAAsB,CAAC,KAAa;IAClD,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,GAAG,MAAM,GAAG,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAAa,EAAE,QAAgB;IACjE,OAAO,sBAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAgB,OAAO,CAAC,KAAa;IACnC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;QAC3B,OAAO,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,OAAO,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,cAAc,CAAC,KAAa,EAAE,QAAgB;IAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,QAAQ,CAAC;AACxC,CAAC;AAED,SAAgB,gBAAgB,CAAC,KAAa,EAAE,QAAgB;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["export function displayFormattedString(input: string): string {\n const [rawInteger, rawFraction] = input.split(\".\");\n const negative = rawInteger.startsWith(\"-\");\n const integer = negative ? rawInteger.slice(1) : rawInteger;\n const withCommas = integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n const fraction = rawFraction?.replace(/0+$/, \"\");\n const prefix = negative ? \"-\" : \"\";\n\n if (!fraction) {\n return `${prefix}${withCommas}`;\n }\n\n return `${prefix}${withCommas}.${fraction}`;\n}\n\nexport function displayWithDecimals(value: number, decimals: number): string {\n return displayFormattedString(value.toFixed(decimals));\n}\n\nexport function display(value: number): string {\n if (Math.abs(value) >= 100) {\n return displayWithDecimals(value, 0);\n }\n if (Math.abs(value) >= 1) {\n return displayWithDecimals(value, 2);\n }\n if (value === 0) {\n return \"0\";\n }\n\n const abs = Math.abs(value);\n const exponent = Math.floor(Math.log10(abs));\n const decimals = Math.min(Math.max(Math.abs(exponent) + 2, 2), 8);\n return displayWithDecimals(value, decimals);\n}\n\nexport function toDecimalValue(value: bigint, decimals: number): number {\n return Number(value) / 10 ** decimals;\n}\n\nexport function fromDecimalValue(value: number, decimals: number): bigint {\n return BigInt(Math.trunc(value * 10 ** decimals));\n}\n"]}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export { parseDecimal, formatDecimal, isZero } from "./price";
|
|
6
|
-
export { scalePriceSize, ScalingError, } from "./scaling";
|
|
7
|
-
export type { OrderbookDecimals, ScaledAmounts } from "./scaling";
|
|
1
|
+
export { asOrderBookId, asPubkeyStr, deriveOrderbookId, resolutionSeconds, sideLabel, OrderUpdateType, Resolution, Side, TimeInForce, TriggerResultStatus, TriggerStatus, TriggerType, TriggerUpdateType, type Branded, type OrderBookId, type PubkeyStr, type SubmitOrderRequest, } from "./types";
|
|
2
|
+
export { formatDecimal, isZero, parseDecimal } from "./price";
|
|
3
|
+
export { alignPriceToTick, scalePriceSize, scalePriceSizeLegacy, ScalingError, type LegacyScaledAmounts, type OrderbookDecimals, type ScaledAmounts, } from "./scaling";
|
|
4
|
+
export { scalePriceSizeLegacy as scalePriceSizeV1 } from "./scaling";
|
|
8
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,UAAU,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/shared/index.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared utilities used across API and WebSocket modules.
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ScalingError = exports.scalePriceSize = exports.isZero = exports.formatDecimal = exports.
|
|
3
|
+
exports.scalePriceSizeV1 = exports.ScalingError = exports.scalePriceSizeLegacy = exports.scalePriceSize = exports.alignPriceToTick = exports.parseDecimal = exports.isZero = exports.formatDecimal = exports.TriggerUpdateType = exports.TriggerType = exports.TriggerStatus = exports.TriggerResultStatus = exports.TimeInForce = exports.Side = exports.Resolution = exports.OrderUpdateType = exports.sideLabel = exports.resolutionSeconds = exports.deriveOrderbookId = exports.asPubkeyStr = exports.asOrderBookId = void 0;
|
|
7
4
|
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "asOrderBookId", { enumerable: true, get: function () { return types_1.asOrderBookId; } });
|
|
6
|
+
Object.defineProperty(exports, "asPubkeyStr", { enumerable: true, get: function () { return types_1.asPubkeyStr; } });
|
|
7
|
+
Object.defineProperty(exports, "deriveOrderbookId", { enumerable: true, get: function () { return types_1.deriveOrderbookId; } });
|
|
8
|
+
Object.defineProperty(exports, "resolutionSeconds", { enumerable: true, get: function () { return types_1.resolutionSeconds; } });
|
|
9
|
+
Object.defineProperty(exports, "sideLabel", { enumerable: true, get: function () { return types_1.sideLabel; } });
|
|
10
|
+
Object.defineProperty(exports, "OrderUpdateType", { enumerable: true, get: function () { return types_1.OrderUpdateType; } });
|
|
8
11
|
Object.defineProperty(exports, "Resolution", { enumerable: true, get: function () { return types_1.Resolution; } });
|
|
12
|
+
Object.defineProperty(exports, "Side", { enumerable: true, get: function () { return types_1.Side; } });
|
|
13
|
+
Object.defineProperty(exports, "TimeInForce", { enumerable: true, get: function () { return types_1.TimeInForce; } });
|
|
14
|
+
Object.defineProperty(exports, "TriggerResultStatus", { enumerable: true, get: function () { return types_1.TriggerResultStatus; } });
|
|
15
|
+
Object.defineProperty(exports, "TriggerStatus", { enumerable: true, get: function () { return types_1.TriggerStatus; } });
|
|
16
|
+
Object.defineProperty(exports, "TriggerType", { enumerable: true, get: function () { return types_1.TriggerType; } });
|
|
17
|
+
Object.defineProperty(exports, "TriggerUpdateType", { enumerable: true, get: function () { return types_1.TriggerUpdateType; } });
|
|
9
18
|
var price_1 = require("./price");
|
|
10
|
-
Object.defineProperty(exports, "parseDecimal", { enumerable: true, get: function () { return price_1.parseDecimal; } });
|
|
11
19
|
Object.defineProperty(exports, "formatDecimal", { enumerable: true, get: function () { return price_1.formatDecimal; } });
|
|
12
20
|
Object.defineProperty(exports, "isZero", { enumerable: true, get: function () { return price_1.isZero; } });
|
|
21
|
+
Object.defineProperty(exports, "parseDecimal", { enumerable: true, get: function () { return price_1.parseDecimal; } });
|
|
13
22
|
var scaling_1 = require("./scaling");
|
|
23
|
+
Object.defineProperty(exports, "alignPriceToTick", { enumerable: true, get: function () { return scaling_1.alignPriceToTick; } });
|
|
14
24
|
Object.defineProperty(exports, "scalePriceSize", { enumerable: true, get: function () { return scaling_1.scalePriceSize; } });
|
|
25
|
+
Object.defineProperty(exports, "scalePriceSizeLegacy", { enumerable: true, get: function () { return scaling_1.scalePriceSizeLegacy; } });
|
|
15
26
|
Object.defineProperty(exports, "ScalingError", { enumerable: true, get: function () { return scaling_1.ScalingError; } });
|
|
16
|
-
//
|
|
17
|
-
|
|
27
|
+
// Backward-compatible name from v1.
|
|
28
|
+
var scaling_2 = require("./scaling");
|
|
29
|
+
Object.defineProperty(exports, "scalePriceSizeV1", { enumerable: true, get: function () { return scaling_2.scalePriceSizeLegacy; } });
|
|
18
30
|
//# sourceMappingURL=index.js.map
|
package/dist/shared/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;AAAA,iCAkBiB;AAjBf,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AACjB,0GAAA,iBAAiB,OAAA;AACjB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,6FAAA,IAAI,OAAA;AACJ,oGAAA,WAAW,OAAA;AACX,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AAOnB,iCAA8D;AAArD,sGAAA,aAAa,OAAA;AAAE,+FAAA,MAAM,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE5C,qCAQmB;AAPjB,2GAAA,gBAAgB,OAAA;AAChB,yGAAA,cAAc,OAAA;AACd,+GAAA,oBAAoB,OAAA;AACpB,uGAAA,YAAY,OAAA;AAMd,oCAAoC;AACpC,qCAAqE;AAA5D,2GAAA,oBAAoB,OAAoB","sourcesContent":["export {\n asOrderBookId,\n asPubkeyStr,\n deriveOrderbookId,\n resolutionSeconds,\n sideLabel,\n OrderUpdateType,\n Resolution,\n Side,\n TimeInForce,\n TriggerResultStatus,\n TriggerStatus,\n TriggerType,\n TriggerUpdateType,\n type Branded,\n type OrderBookId,\n type PubkeyStr,\n type SubmitOrderRequest,\n} from \"./types\";\n\nexport { formatDecimal, isZero, parseDecimal } from \"./price\";\n\nexport {\n alignPriceToTick,\n scalePriceSize,\n scalePriceSizeLegacy,\n ScalingError,\n type LegacyScaledAmounts,\n type OrderbookDecimals,\n type ScaledAmounts,\n} from \"./scaling\";\n\n// Backward-compatible name from v1.\nexport { scalePriceSizeLegacy as scalePriceSizeV1 } from \"./scaling\";\n"]}
|
package/dist/shared/price.d.ts
CHANGED
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This module provides helper functions for working with decimal string prices.
|
|
5
|
-
* The SDK uses String types for price/size/balance fields to preserve
|
|
6
|
-
* the exact decimal representation from the server, as different tokens
|
|
7
|
-
* have different decimal places (USDC=6, SOL=9, BTC=8, etc.).
|
|
2
|
+
* Parse a decimal string to a number.
|
|
8
3
|
*/
|
|
4
|
+
export declare function parseDecimal(value: string): number;
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* parseDecimal("0.500000"); // returns 0.5
|
|
15
|
-
* parseDecimal("1.000000"); // returns 1.0
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseDecimal(s: string): number;
|
|
19
|
-
/**
|
|
20
|
-
* Format a number as a decimal string with specified precision.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* formatDecimal(0.5, 6); // returns "0.500000"
|
|
25
|
-
* formatDecimal(1.0, 6); // returns "1.000000"
|
|
26
|
-
* ```
|
|
6
|
+
* Format a number to a fixed decimal string.
|
|
27
7
|
*/
|
|
28
8
|
export declare function formatDecimal(value: number, precision: number): string;
|
|
29
9
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* isZero("0"); // true
|
|
35
|
-
* isZero("0.0"); // true
|
|
36
|
-
* isZero("0.000000"); // true
|
|
37
|
-
* isZero("0.001"); // false
|
|
38
|
-
* ```
|
|
10
|
+
* Whether a decimal string represents numeric zero.
|
|
39
11
|
*/
|
|
40
|
-
export declare function isZero(
|
|
12
|
+
export declare function isZero(value: string): boolean;
|
|
41
13
|
//# sourceMappingURL=price.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAG7C"}
|
package/dist/shared/price.js
CHANGED
|
@@ -1,57 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Price utilities for the Lightcone SDK.
|
|
4
|
-
*
|
|
5
|
-
* This module provides helper functions for working with decimal string prices.
|
|
6
|
-
* The SDK uses String types for price/size/balance fields to preserve
|
|
7
|
-
* the exact decimal representation from the server, as different tokens
|
|
8
|
-
* have different decimal places (USDC=6, SOL=9, BTC=8, etc.).
|
|
9
|
-
*/
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
exports.parseDecimal = parseDecimal;
|
|
12
4
|
exports.formatDecimal = formatDecimal;
|
|
13
5
|
exports.isZero = isZero;
|
|
14
6
|
/**
|
|
15
|
-
* Parse a decimal string to number
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* parseDecimal("0.500000"); // returns 0.5
|
|
20
|
-
* parseDecimal("1.000000"); // returns 1.0
|
|
21
|
-
* ```
|
|
7
|
+
* Parse a decimal string to a number.
|
|
22
8
|
*/
|
|
23
|
-
function parseDecimal(
|
|
24
|
-
const
|
|
25
|
-
if (isNaN(
|
|
26
|
-
throw new Error(`Invalid decimal string: ${
|
|
9
|
+
function parseDecimal(value) {
|
|
10
|
+
const parsed = Number.parseFloat(value);
|
|
11
|
+
if (Number.isNaN(parsed)) {
|
|
12
|
+
throw new Error(`Invalid decimal string: ${value}`);
|
|
27
13
|
}
|
|
28
|
-
return
|
|
14
|
+
return parsed;
|
|
29
15
|
}
|
|
30
16
|
/**
|
|
31
|
-
* Format a number
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* formatDecimal(0.5, 6); // returns "0.500000"
|
|
36
|
-
* formatDecimal(1.0, 6); // returns "1.000000"
|
|
37
|
-
* ```
|
|
17
|
+
* Format a number to a fixed decimal string.
|
|
38
18
|
*/
|
|
39
19
|
function formatDecimal(value, precision) {
|
|
40
20
|
return value.toFixed(precision);
|
|
41
21
|
}
|
|
42
22
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* isZero("0"); // true
|
|
48
|
-
* isZero("0.0"); // true
|
|
49
|
-
* isZero("0.000000"); // true
|
|
50
|
-
* isZero("0.001"); // false
|
|
51
|
-
* ```
|
|
23
|
+
* Whether a decimal string represents numeric zero.
|
|
52
24
|
*/
|
|
53
|
-
function isZero(
|
|
54
|
-
const parsed = parseFloat(
|
|
55
|
-
return !isNaN(parsed) && parsed === 0;
|
|
25
|
+
function isZero(value) {
|
|
26
|
+
const parsed = Number.parseFloat(value);
|
|
27
|
+
return !Number.isNaN(parsed) && parsed === 0;
|
|
56
28
|
}
|
|
57
29
|
//# sourceMappingURL=price.js.map
|
package/dist/shared/price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":";;AAGA,oCAMC;AAKD,sCAEC;AAKD,wBAGC;AAxBD;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAa,EAAE,SAAiB;IAC5D,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAC,KAAa;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * Parse a decimal string to a number.\n */\nexport function parseDecimal(value: string): number {\n const parsed = Number.parseFloat(value);\n if (Number.isNaN(parsed)) {\n throw new Error(`Invalid decimal string: ${value}`);\n }\n return parsed;\n}\n\n/**\n * Format a number to a fixed decimal string.\n */\nexport function formatDecimal(value: number, precision: number): string {\n return value.toFixed(precision);\n}\n\n/**\n * Whether a decimal string represents numeric zero.\n */\nexport function isZero(value: string): boolean {\n const parsed = Number.parseFloat(value);\n return !Number.isNaN(parsed) && parsed === 0;\n}\n"]}
|
package/dist/shared/scaling.d.ts
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
import { OrderSide } from "../program/types";
|
|
2
|
-
/**
|
|
3
|
-
* Orderbook decimal configuration
|
|
4
|
-
*/
|
|
5
3
|
export interface OrderbookDecimals {
|
|
6
4
|
orderbookId: string;
|
|
7
5
|
baseDecimals: number;
|
|
8
6
|
quoteDecimals: number;
|
|
9
7
|
priceDecimals: number;
|
|
8
|
+
tickSize?: bigint;
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Scaled amounts result
|
|
13
|
-
*/
|
|
14
10
|
export interface ScaledAmounts {
|
|
11
|
+
amountIn: bigint;
|
|
12
|
+
amountOut: bigint;
|
|
15
13
|
makerAmount: bigint;
|
|
16
14
|
takerAmount: bigint;
|
|
17
15
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Error thrown during price/size scaling
|
|
20
|
-
*/
|
|
21
16
|
export declare class ScalingError extends Error {
|
|
22
17
|
constructor(message: string);
|
|
23
|
-
static
|
|
24
|
-
static
|
|
25
|
-
static overflow(
|
|
18
|
+
static nonPositivePrice(value: string): ScalingError;
|
|
19
|
+
static nonPositiveSize(value: string): ScalingError;
|
|
20
|
+
static overflow(context: string): ScalingError;
|
|
21
|
+
static zeroAmount(): ScalingError;
|
|
22
|
+
static fractionalAmount(value: string): ScalingError;
|
|
23
|
+
static invalidDecimal(input: string, reason: string): ScalingError;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* For ASK orders (selling base for quote):
|
|
35
|
-
* - maker_amount = size * 10^baseDecimals (what maker gives in base tokens)
|
|
36
|
-
* - taker_amount = price * size * 10^quoteDecimals (what maker receives in quote tokens)
|
|
37
|
-
*
|
|
38
|
-
* @param priceStr - Price as a decimal string (e.g., "0.75")
|
|
39
|
-
* @param sizeStr - Size as a decimal string (e.g., "100")
|
|
40
|
-
* @param side - Order side (BID or ASK)
|
|
41
|
-
* @param decimals - Orderbook decimal configuration
|
|
42
|
-
* @returns Scaled maker_amount and taker_amount as bigints
|
|
43
|
-
*/
|
|
44
|
-
export declare function scalePriceSize(priceStr: string, sizeStr: string, side: OrderSide, decimals: OrderbookDecimals): ScaledAmounts;
|
|
25
|
+
export declare function alignPriceToTick(price: Decimal, decimals: OrderbookDecimals): Decimal;
|
|
26
|
+
export declare function scalePriceSize(priceInput: string | Decimal, sizeInput: string | Decimal, side: OrderSide, decimals: OrderbookDecimals): ScaledAmounts;
|
|
27
|
+
export interface LegacyScaledAmounts {
|
|
28
|
+
makerAmount: bigint;
|
|
29
|
+
takerAmount: bigint;
|
|
30
|
+
}
|
|
31
|
+
export declare function scalePriceSizeLegacy(price: string, size: string, side: OrderSide, decimals: OrderbookDecimals): LegacyScaledAmounts;
|
|
45
32
|
//# sourceMappingURL=scaling.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaling.d.ts","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scaling.d.ts","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,M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.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ScalingError = void 0;
|
|
7
|
+
exports.alignPriceToTick = alignPriceToTick;
|
|
7
8
|
exports.scalePriceSize = scalePriceSize;
|
|
9
|
+
exports.scalePriceSizeLegacy = scalePriceSizeLegacy;
|
|
8
10
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
11
|
const types_1 = require("../program/types");
|
|
10
|
-
|
|
11
|
-
* Error thrown during price/size scaling
|
|
12
|
-
*/
|
|
12
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
13
13
|
class ScalingError extends Error {
|
|
14
14
|
constructor(message) {
|
|
15
15
|
super(message);
|
|
16
16
|
this.name = "ScalingError";
|
|
17
17
|
}
|
|
18
|
-
static
|
|
19
|
-
return new ScalingError(
|
|
18
|
+
static nonPositivePrice(value) {
|
|
19
|
+
return new ScalingError(`Price must be positive, got ${value}`);
|
|
20
|
+
}
|
|
21
|
+
static nonPositiveSize(value) {
|
|
22
|
+
return new ScalingError(`Size must be positive, got ${value}`);
|
|
23
|
+
}
|
|
24
|
+
static overflow(context) {
|
|
25
|
+
return new ScalingError(`Overflow: ${context}`);
|
|
20
26
|
}
|
|
21
|
-
static
|
|
22
|
-
return new ScalingError(
|
|
27
|
+
static zeroAmount() {
|
|
28
|
+
return new ScalingError("Computed amount is zero");
|
|
23
29
|
}
|
|
24
|
-
static
|
|
25
|
-
return new ScalingError(
|
|
30
|
+
static fractionalAmount(value) {
|
|
31
|
+
return new ScalingError(`Fractional lamports not allowed: ${value}`);
|
|
32
|
+
}
|
|
33
|
+
static invalidDecimal(input, reason) {
|
|
34
|
+
return new ScalingError(`Invalid decimal '${input}': ${reason}`);
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
exports.ScalingError = ScalingError;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const baseScale = new decimal_js_1.default(10).pow(decimals.baseDecimals);
|
|
60
|
-
const quoteScale = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
|
|
61
|
-
const baseAmount = size.mul(baseScale).floor();
|
|
62
|
-
const quoteAmount = price.mul(size).mul(quoteScale).floor();
|
|
63
|
-
const baseAmountBigInt = BigInt(baseAmount.toFixed(0));
|
|
64
|
-
const quoteAmountBigInt = BigInt(quoteAmount.toFixed(0));
|
|
65
|
-
if (baseAmountBigInt > U64_MAX) {
|
|
66
|
-
throw ScalingError.overflow("base amount");
|
|
67
|
-
}
|
|
68
|
-
if (quoteAmountBigInt > U64_MAX) {
|
|
69
|
-
throw ScalingError.overflow("quote amount");
|
|
38
|
+
function alignPriceToTick(price, decimals) {
|
|
39
|
+
const tickSize = decimals.tickSize ?? 0n;
|
|
40
|
+
if (tickSize <= 1n) {
|
|
41
|
+
return price;
|
|
42
|
+
}
|
|
43
|
+
const quoteMultiplier = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
|
|
44
|
+
const tick = new decimal_js_1.default(tickSize.toString());
|
|
45
|
+
const lamports = price.mul(quoteMultiplier).trunc();
|
|
46
|
+
const aligned = lamports.div(tick).trunc().mul(tick);
|
|
47
|
+
return aligned.div(quoteMultiplier);
|
|
48
|
+
}
|
|
49
|
+
function scalePriceSize(priceInput, sizeInput, side, decimals) {
|
|
50
|
+
const price = normalizeDecimal(priceInput, "price");
|
|
51
|
+
const size = normalizeDecimal(sizeInput, "size");
|
|
52
|
+
if (price.lte(0)) {
|
|
53
|
+
throw ScalingError.nonPositivePrice(price.toString());
|
|
54
|
+
}
|
|
55
|
+
if (size.lte(0)) {
|
|
56
|
+
throw ScalingError.nonPositiveSize(size.toString());
|
|
57
|
+
}
|
|
58
|
+
const baseMultiplier = new decimal_js_1.default(10).pow(decimals.baseDecimals);
|
|
59
|
+
const quoteMultiplier = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
|
|
60
|
+
const baseLamports = size.mul(baseMultiplier);
|
|
61
|
+
const quoteLamports = price.mul(size).mul(quoteMultiplier);
|
|
62
|
+
assertWhole(baseLamports, "base_lamports");
|
|
63
|
+
assertWhole(quoteLamports, "quote_lamports");
|
|
64
|
+
const base = toU64(baseLamports, "base_lamports");
|
|
65
|
+
const quote = toU64(quoteLamports, "quote_lamports");
|
|
66
|
+
if (base === 0n || quote === 0n) {
|
|
67
|
+
throw ScalingError.zeroAmount();
|
|
70
68
|
}
|
|
71
69
|
if (side === types_1.OrderSide.BID) {
|
|
72
70
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
amountIn: quote,
|
|
72
|
+
amountOut: base,
|
|
73
|
+
makerAmount: quote,
|
|
74
|
+
takerAmount: base,
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
return {
|
|
78
|
+
amountIn: base,
|
|
79
|
+
amountOut: quote,
|
|
80
|
+
makerAmount: base,
|
|
81
|
+
takerAmount: quote,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function normalizeDecimal(value, field) {
|
|
85
|
+
if (value instanceof decimal_js_1.default) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return new decimal_js_1.default(value);
|
|
82
90
|
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
93
|
+
throw ScalingError.invalidDecimal(value, reason || field);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function assertWhole(value, label) {
|
|
97
|
+
if (!value.isInteger()) {
|
|
98
|
+
throw ScalingError.fractionalAmount(`${label} = ${value.toString()}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function toU64(value, label) {
|
|
102
|
+
const bigint = BigInt(value.toFixed(0));
|
|
103
|
+
if (bigint < 0n || bigint > U64_MAX) {
|
|
104
|
+
throw ScalingError.overflow(`${label} ${value.toString()} does not fit in u64`);
|
|
105
|
+
}
|
|
106
|
+
return bigint;
|
|
107
|
+
}
|
|
108
|
+
function scalePriceSizeLegacy(price, size, side, decimals) {
|
|
109
|
+
const scaled = scalePriceSize(price, size, side, decimals);
|
|
110
|
+
return {
|
|
111
|
+
makerAmount: scaled.amountIn,
|
|
112
|
+
takerAmount: scaled.amountOut,
|
|
113
|
+
};
|
|
83
114
|
}
|
|
84
115
|
//# sourceMappingURL=scaling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaling.js","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"scaling.js","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":";;;;;;AAoDA,4CAWC;AAED,wCA+CC;AAmCD,oDAWC;AA9JD,4DAAiC;AACjC,4CAA6C;AAkB7C,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEjC,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,KAAa;QACnC,OAAO,IAAI,YAAY,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,KAAa;QAClC,OAAO,IAAI,YAAY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O,MAAM,CAAC;AAChB,CAAC;AAQD,SAAgB,oBAAoB,CAClC,KAAa,EACb,IAAY,EACZ,IAAe,EACf,QAA2B;IAE3B,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC3D,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,QAAQ;QAC5B,WAAW,EAAE,MAAM,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import Decimal from \"decimal.js\";\nimport { OrderSide } from \"../program/types\";\n\nexport interface OrderbookDecimals {\n orderbookId: string;\n baseDecimals: number;\n quoteDecimals: number;\n priceDecimals: number;\n tickSize?: bigint;\n}\n\nexport interface ScaledAmounts {\n amountIn: bigint;\n amountOut: bigint;\n // Backward-compatible aliases used by v1 builder code.\n makerAmount: bigint;\n takerAmount: bigint;\n}\n\nconst U64_MAX = (1n << 64n) - 1n;\n\nexport class ScalingError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ScalingError\";\n }\n\n static nonPositivePrice(value: string): ScalingError {\n return new ScalingError(`Price must be positive, got ${value}`);\n }\n\n static nonPositiveSize(value: string): ScalingError {\n return new ScalingError(`Size must be positive, got ${value}`);\n }\n\n static overflow(context: string): ScalingError {\n return new ScalingError(`Overflow: ${context}`);\n }\n\n static zeroAmount(): ScalingError {\n return new ScalingError(\"Computed amount is zero\");\n }\n\n static fractionalAmount(value: string): ScalingError {\n return new ScalingError(`Fractional lamports not allowed: ${value}`);\n }\n\n static invalidDecimal(input: string, reason: string): ScalingError {\n return new ScalingError(`Invalid decimal '${input}': ${reason}`);\n }\n}\n\nexport function alignPriceToTick(price: Decimal, decimals: OrderbookDecimals): Decimal {\n const tickSize = decimals.tickSize ?? 0n;\n if (tickSize <= 1n) {\n return price;\n }\n\n const quoteMultiplier = new Decimal(10).pow(decimals.quoteDecimals);\n const tick = new Decimal(tickSize.toString());\n const lamports = price.mul(quoteMultiplier).trunc();\n const aligned = lamports.div(tick).trunc().mul(tick);\n return aligned.div(quoteMultiplier);\n}\n\nexport function scalePriceSize(\n priceInput: string | Decimal,\n sizeInput: string | Decimal,\n side: OrderSide,\n decimals: OrderbookDecimals\n): ScaledAmounts {\n const price = normalizeDecimal(priceInput, \"price\");\n const size = normalizeDecimal(sizeInput, \"size\");\n\n if (price.lte(0)) {\n throw ScalingError.nonPositivePrice(price.toString());\n }\n if (size.lte(0)) {\n throw ScalingError.nonPositiveSize(size.toString());\n }\n\n const baseMultiplier = new Decimal(10).pow(decimals.baseDecimals);\n const quoteMultiplier = new Decimal(10).pow(decimals.quoteDecimals);\n\n const baseLamports = size.mul(baseMultiplier);\n const quoteLamports = price.mul(size).mul(quoteMultiplier);\n\n assertWhole(baseLamports, \"base_lamports\");\n assertWhole(quoteLamports, \"quote_lamports\");\n\n const base = toU64(baseLamports, \"base_lamports\");\n const quote = toU64(quoteLamports, \"quote_lamports\");\n\n if (base === 0n || quote === 0n) {\n throw ScalingError.zeroAmount();\n }\n\n if (side === OrderSide.BID) {\n return {\n amountIn: quote,\n amountOut: base,\n makerAmount: quote,\n takerAmount: base,\n };\n }\n\n return {\n amountIn: base,\n amountOut: quote,\n makerAmount: base,\n takerAmount: quote,\n };\n}\n\nfunction normalizeDecimal(value: string | Decimal, field: string): Decimal {\n if (value instanceof Decimal) {\n return value;\n }\n\n try {\n return new Decimal(value);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw ScalingError.invalidDecimal(value, reason || field);\n }\n}\n\nfunction assertWhole(value: Decimal, label: string): void {\n if (!value.isInteger()) {\n throw ScalingError.fractionalAmount(`${label} = ${value.toString()}`);\n }\n}\n\nfunction toU64(value: Decimal, label: string): bigint {\n const bigint = BigInt(value.toFixed(0));\n if (bigint < 0n || bigint > U64_MAX) {\n throw ScalingError.overflow(`${label} ${value.toString()} does not fit in u64`);\n }\n return bigint;\n}\n\n// Legacy aliases kept for existing integrations.\nexport interface LegacyScaledAmounts {\n makerAmount: bigint;\n takerAmount: bigint;\n}\n\nexport function scalePriceSizeLegacy(\n price: string,\n size: string,\n side: OrderSide,\n decimals: OrderbookDecimals\n): LegacyScaledAmounts {\n const scaled = scalePriceSize(price, size, side, decimals);\n return {\n makerAmount: scaled.amountIn,\n takerAmount: scaled.amountOut,\n };\n}\n"]}
|