@lightconexyz/lightcone-sdk 0.5.2 → 0.7.1
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 +39 -5
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +2 -0
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +10 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +43 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +70 -9
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +7 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +60 -6
- package/dist/context.js.map +1 -1
- package/dist/domain/admin/client.d.ts +21 -2
- package/dist/domain/admin/client.d.ts.map +1 -1
- package/dist/domain/admin/client.js +90 -4
- package/dist/domain/admin/client.js.map +1 -1
- package/dist/domain/admin/wire.d.ts +292 -7
- package/dist/domain/admin/wire.d.ts.map +1 -1
- package/dist/domain/admin/wire.js.map +1 -1
- package/dist/domain/faucet.d.ts +25 -0
- package/dist/domain/faucet.d.ts.map +1 -0
- package/dist/domain/faucet.js +3 -0
- package/dist/domain/faucet.js.map +1 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +3 -1
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/market/client.d.ts +23 -2
- package/dist/domain/market/client.d.ts.map +1 -1
- package/dist/domain/market/client.js +31 -1
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/market/convert.d.ts +10 -0
- package/dist/domain/market/convert.d.ts.map +1 -1
- package/dist/domain/market/convert.js +44 -5
- package/dist/domain/market/convert.js.map +1 -1
- package/dist/domain/market/icon.d.ts +17 -0
- package/dist/domain/market/icon.d.ts.map +1 -0
- package/dist/domain/market/icon.js +25 -0
- package/dist/domain/market/icon.js.map +1 -0
- package/dist/domain/market/index.d.ts +21 -5
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js +15 -1
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/market/outcome.d.ts +4 -1
- package/dist/domain/market/outcome.d.ts.map +1 -1
- package/dist/domain/market/outcome.js +8 -7
- package/dist/domain/market/outcome.js.map +1 -1
- package/dist/domain/market/tokens.d.ts +55 -3
- package/dist/domain/market/tokens.d.ts.map +1 -1
- package/dist/domain/market/tokens.js +105 -9
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +69 -10
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js +5 -0
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/metrics/client.d.ts +66 -0
- package/dist/domain/metrics/client.d.ts.map +1 -0
- package/dist/domain/metrics/client.js +124 -0
- package/dist/domain/metrics/client.js.map +1 -0
- package/dist/domain/metrics/index.d.ts +3 -0
- package/dist/domain/metrics/index.d.ts.map +1 -0
- package/dist/domain/metrics/index.js +19 -0
- package/dist/domain/metrics/index.js.map +1 -0
- package/dist/domain/metrics/wire.d.ts +346 -0
- package/dist/domain/metrics/wire.d.ts.map +1 -0
- package/dist/domain/metrics/wire.js +3 -0
- package/dist/domain/metrics/wire.js.map +1 -0
- package/dist/domain/notification/client.d.ts +6 -0
- package/dist/domain/notification/client.d.ts.map +1 -1
- package/dist/domain/notification/client.js +10 -0
- package/dist/domain/notification/client.js.map +1 -1
- package/dist/domain/notification/index.d.ts +6 -2
- package/dist/domain/notification/index.d.ts.map +1 -1
- package/dist/domain/notification/index.js.map +1 -1
- package/dist/domain/order/client.d.ts +34 -6
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +88 -21
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/convert.d.ts +5 -5
- package/dist/domain/order/convert.d.ts.map +1 -1
- package/dist/domain/order/convert.js +3 -3
- package/dist/domain/order/convert.js.map +1 -1
- package/dist/domain/order/index.d.ts +3 -2
- package/dist/domain/order/index.d.ts.map +1 -1
- package/dist/domain/order/index.js +11 -3
- package/dist/domain/order/index.js.map +1 -1
- package/dist/domain/order/state.d.ts +9 -7
- package/dist/domain/order/state.d.ts.map +1 -1
- package/dist/domain/order/state.js +81 -28
- package/dist/domain/order/state.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts +6 -2
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +17 -0
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/orderbook/index.d.ts +1 -1
- package/dist/domain/orderbook/index.d.ts.map +1 -1
- package/dist/domain/orderbook/index.js +3 -8
- package/dist/domain/orderbook/index.js.map +1 -1
- package/dist/domain/orderbook/state.d.ts +30 -7
- package/dist/domain/orderbook/state.d.ts.map +1 -1
- package/dist/domain/orderbook/state.js +41 -12
- package/dist/domain/orderbook/state.js.map +1 -1
- package/dist/domain/position/builders.d.ts +11 -8
- package/dist/domain/position/builders.d.ts.map +1 -1
- package/dist/domain/position/builders.js +31 -25
- package/dist/domain/position/builders.js.map +1 -1
- package/dist/domain/position/client.d.ts +66 -5
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +101 -9
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/position/index.d.ts +3 -2
- package/dist/domain/position/index.d.ts.map +1 -1
- package/dist/domain/position/index.js.map +1 -1
- package/dist/domain/price_history/client.d.ts +12 -1
- package/dist/domain/price_history/client.d.ts.map +1 -1
- package/dist/domain/price_history/client.js +14 -0
- package/dist/domain/price_history/client.js.map +1 -1
- package/dist/domain/price_history/wire.d.ts +27 -0
- package/dist/domain/price_history/wire.d.ts.map +1 -1
- package/dist/domain/price_history/wire.js.map +1 -1
- package/dist/domain/referral/client.d.ts +6 -0
- package/dist/domain/referral/client.d.ts.map +1 -1
- package/dist/domain/referral/client.js +22 -9
- package/dist/domain/referral/client.js.map +1 -1
- package/dist/domain/trade/client.d.ts +1 -0
- package/dist/domain/trade/client.d.ts.map +1 -1
- package/dist/domain/trade/client.js +14 -0
- package/dist/domain/trade/client.js.map +1 -1
- package/dist/domain/trade/wire.d.ts +6 -0
- package/dist/domain/trade/wire.d.ts.map +1 -1
- package/dist/domain/trade/wire.js.map +1 -1
- package/dist/env.d.ts +6 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +19 -9
- package/dist/env.js.map +1 -1
- package/dist/http/client.d.ts +9 -0
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +29 -11
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +16 -7
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +10 -7
- package/dist/prelude.js.map +1 -1
- package/dist/privy/index.d.ts +1 -1
- package/dist/privy/index.js.map +1 -1
- package/dist/program/accounts.d.ts +12 -7
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +38 -16
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/builder.d.ts +0 -4
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +0 -8
- package/dist/program/builder.js.map +1 -1
- package/dist/program/constants.d.ts +20 -7
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +21 -8
- package/dist/program/constants.js.map +1 -1
- package/dist/program/error.d.ts +25 -1
- package/dist/program/error.d.ts.map +1 -1
- package/dist/program/error.js +72 -0
- package/dist/program/error.js.map +1 -1
- package/dist/program/index.d.ts +7 -7
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +36 -9
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +184 -71
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +573 -140
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.js +2 -2
- package/dist/program/orders.js.map +1 -1
- package/dist/program/pda.d.ts +21 -3
- package/dist/program/pda.d.ts.map +1 -1
- package/dist/program/pda.js +43 -6
- package/dist/program/pda.js.map +1 -1
- package/dist/program/types.d.ts +139 -21
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/program/utils.d.ts +31 -2
- package/dist/program/utils.d.ts.map +1 -1
- package/dist/program/utils.js +132 -5
- package/dist/program/utils.js.map +1 -1
- package/dist/rpc.d.ts +6 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +9 -7
- package/dist/rpc.js.map +1 -1
- package/dist/rpcFailover.d.ts +22 -0
- package/dist/rpcFailover.d.ts.map +1 -0
- package/dist/rpcFailover.js +71 -0
- package/dist/rpcFailover.js.map +1 -0
- package/dist/shared/fmt/constants.d.ts +5 -0
- package/dist/shared/fmt/constants.d.ts.map +1 -0
- package/dist/shared/fmt/constants.js +25 -0
- package/dist/shared/fmt/constants.js.map +1 -0
- package/dist/shared/fmt/decimal.d.ts +7 -0
- package/dist/shared/fmt/decimal.d.ts.map +1 -1
- package/dist/shared/fmt/decimal.js +32 -24
- package/dist/shared/fmt/decimal.js.map +1 -1
- package/dist/shared/fmt/num.d.ts +7 -0
- package/dist/shared/fmt/num.d.ts.map +1 -1
- package/dist/shared/fmt/num.js +27 -15
- package/dist/shared/fmt/num.js.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +2 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +19 -0
- package/dist/shared/types.js.map +1 -1
- package/dist/ws/client.node.js +1 -1
- package/dist/ws/client.node.js.map +1 -1
- package/dist/ws/index.d.ts +12 -1
- package/dist/ws/index.d.ts.map +1 -1
- package/dist/ws/index.js +20 -0
- package/dist/ws/index.js.map +1 -1
- package/dist/ws/subscriptions.d.ts +6 -0
- package/dist/ws/subscriptions.d.ts.map +1 -1
- package/dist/ws/subscriptions.js +4 -0
- package/dist/ws/subscriptions.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenValidationError = void 0;
|
|
4
|
+
exports.tokenDisplayPriority = tokenDisplayPriority;
|
|
5
|
+
exports.sortByDisplayPriority = sortByDisplayPriority;
|
|
4
6
|
exports.isUsdStablecoin = isUsdStablecoin;
|
|
5
7
|
exports.currencySymbol = currencySymbol;
|
|
6
8
|
exports.validatedTokensFromWire = validatedTokensFromWire;
|
|
9
|
+
exports.globalDepositAssetFromWire = globalDepositAssetFromWire;
|
|
7
10
|
const shared_1 = require("../../shared");
|
|
11
|
+
const icon_1 = require("./icon");
|
|
12
|
+
/**
|
|
13
|
+
* Display priority for sorting: lower values come first. BTC/WBTC tie at 0,
|
|
14
|
+
* ETH/WETH tie at 1, SOL at 2; everything else falls to the alphabetical tail.
|
|
15
|
+
*/
|
|
16
|
+
function tokenDisplayPriority(token) {
|
|
17
|
+
switch (token.symbol) {
|
|
18
|
+
case "BTC":
|
|
19
|
+
case "WBTC":
|
|
20
|
+
return 0;
|
|
21
|
+
case "ETH":
|
|
22
|
+
case "WETH":
|
|
23
|
+
return 1;
|
|
24
|
+
case "SOL":
|
|
25
|
+
return 2;
|
|
26
|
+
default:
|
|
27
|
+
return 255;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function displaySymbol(item) {
|
|
31
|
+
return "symbol" in item ? item.symbol : item.base.symbol;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a new array ordered for display: priority groups first
|
|
35
|
+
* (BTC/WBTC → ETH/WETH → SOL), then all remaining items alphabetically by the
|
|
36
|
+
* display token's symbol.
|
|
37
|
+
*
|
|
38
|
+
* Accepts both pure tokens and composite types whose display token lives on
|
|
39
|
+
* `base` (e.g. `DepositAssetPair`, `OrderBookPair`).
|
|
40
|
+
*/
|
|
41
|
+
function sortByDisplayPriority(items) {
|
|
42
|
+
const copy = [...items];
|
|
43
|
+
copy.sort((left, right) => {
|
|
44
|
+
const leftSymbol = displaySymbol(left);
|
|
45
|
+
const rightSymbol = displaySymbol(right);
|
|
46
|
+
const priorityDelta = tokenDisplayPriority({ symbol: leftSymbol }) -
|
|
47
|
+
tokenDisplayPriority({ symbol: rightSymbol });
|
|
48
|
+
if (priorityDelta !== 0)
|
|
49
|
+
return priorityDelta;
|
|
50
|
+
return leftSymbol.localeCompare(rightSymbol);
|
|
51
|
+
});
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
8
54
|
class TokenValidationError extends Error {
|
|
9
55
|
details;
|
|
10
56
|
constructor(mint, details) {
|
|
@@ -27,11 +73,11 @@ function validatedTokensFromWire(source) {
|
|
|
27
73
|
const errors = [];
|
|
28
74
|
const metadata = {};
|
|
29
75
|
const depositPubkey = (0, shared_1.asPubkeyStr)(source.deposit_asset);
|
|
30
|
-
const
|
|
76
|
+
const iconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
31
77
|
const name = source.display_name;
|
|
32
78
|
const symbol = source.symbol;
|
|
33
79
|
const decimals = source.decimals;
|
|
34
|
-
if (!
|
|
80
|
+
if (!iconUrls)
|
|
35
81
|
errors.push("Missing icon URL");
|
|
36
82
|
if (!name)
|
|
37
83
|
errors.push("Missing display name");
|
|
@@ -45,17 +91,23 @@ function validatedTokensFromWire(source) {
|
|
|
45
91
|
metadata[source.deposit_asset] = {
|
|
46
92
|
pubkey: depositPubkey,
|
|
47
93
|
symbol: symbol ?? "",
|
|
94
|
+
shortSymbol: name ?? "",
|
|
48
95
|
decimals: decimals ?? 0,
|
|
49
|
-
|
|
96
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
97
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
98
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
50
99
|
name: name ?? "",
|
|
51
100
|
};
|
|
52
|
-
const conditionals = source.conditional_mints.map((conditional) => conditionalFromWire(conditional, source.deposit_asset, symbol ?? "",
|
|
101
|
+
const conditionals = source.conditional_mints.map((conditional) => conditionalFromWire(conditional, source.deposit_asset, symbol ?? "", iconUrls?.low ?? "", iconUrls?.medium ?? "", iconUrls?.high ?? ""));
|
|
53
102
|
for (const conditional of conditionals) {
|
|
54
103
|
metadata[conditional.pubkey] = {
|
|
55
104
|
pubkey: conditional.pubkey,
|
|
56
105
|
symbol: conditional.symbol,
|
|
106
|
+
shortSymbol: conditional.shortSymbol,
|
|
57
107
|
decimals: conditional.decimals,
|
|
58
|
-
|
|
108
|
+
iconUrlLow: conditional.iconUrlLow,
|
|
109
|
+
iconUrlMedium: conditional.iconUrlMedium,
|
|
110
|
+
iconUrlHigh: conditional.iconUrlHigh,
|
|
59
111
|
name: conditional.name,
|
|
60
112
|
};
|
|
61
113
|
}
|
|
@@ -68,15 +120,52 @@ function validatedTokensFromWire(source) {
|
|
|
68
120
|
pubkey: depositPubkey,
|
|
69
121
|
name: name ?? "",
|
|
70
122
|
symbol: symbol ?? "",
|
|
123
|
+
shortSymbol: name ?? "",
|
|
71
124
|
description: source.description,
|
|
72
125
|
decimals: decimals ?? 0,
|
|
73
|
-
|
|
126
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
127
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
128
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
74
129
|
},
|
|
75
130
|
conditionals,
|
|
76
131
|
metadata,
|
|
77
132
|
};
|
|
78
133
|
}
|
|
79
|
-
function
|
|
134
|
+
function globalDepositAssetFromWire(source) {
|
|
135
|
+
const errors = [];
|
|
136
|
+
const name = source.display_name;
|
|
137
|
+
const symbol = source.symbol;
|
|
138
|
+
const iconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
139
|
+
const decimals = source.decimals;
|
|
140
|
+
if (!name)
|
|
141
|
+
errors.push("Missing display name");
|
|
142
|
+
if (!symbol)
|
|
143
|
+
errors.push("Missing symbol");
|
|
144
|
+
if (!iconUrls)
|
|
145
|
+
errors.push("Missing icon URL");
|
|
146
|
+
if (decimals === undefined || decimals === null)
|
|
147
|
+
errors.push("Missing decimals");
|
|
148
|
+
if (errors.length > 0) {
|
|
149
|
+
throw new TokenValidationError(source.mint, errors);
|
|
150
|
+
}
|
|
151
|
+
const depositAsset = (0, shared_1.asPubkeyStr)(source.mint);
|
|
152
|
+
return {
|
|
153
|
+
id: source.id,
|
|
154
|
+
pubkey: depositAsset,
|
|
155
|
+
depositAsset,
|
|
156
|
+
name: name ?? "",
|
|
157
|
+
symbol: symbol ?? "",
|
|
158
|
+
shortSymbol: name ?? "",
|
|
159
|
+
description: source.description,
|
|
160
|
+
decimals: decimals ?? 0,
|
|
161
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
162
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
163
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
164
|
+
whitelistIndex: source.whitelist_index,
|
|
165
|
+
active: source.active,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function conditionalFromWire(source, depositAsset, depositSymbol, parentIconUrlLow, parentIconUrlMedium, parentIconUrlHigh) {
|
|
80
169
|
const errors = [];
|
|
81
170
|
if (source.decimals === undefined)
|
|
82
171
|
errors.push("Missing decimals");
|
|
@@ -87,6 +176,10 @@ function conditionalFromWire(source, depositAsset, depositSymbol, iconUrl) {
|
|
|
87
176
|
if (errors.length > 0) {
|
|
88
177
|
throw new TokenValidationError(source.token_address, errors);
|
|
89
178
|
}
|
|
179
|
+
const ownIconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
180
|
+
const resolvedIconUrlLow = ownIconUrls?.low ?? parentIconUrlLow;
|
|
181
|
+
const resolvedIconUrlMedium = ownIconUrls?.medium ?? parentIconUrlMedium;
|
|
182
|
+
const resolvedIconUrlHigh = ownIconUrls?.high ?? parentIconUrlHigh;
|
|
90
183
|
return {
|
|
91
184
|
id: source.id,
|
|
92
185
|
outcomeIndex: source.outcome_index,
|
|
@@ -95,10 +188,13 @@ function conditionalFromWire(source, depositAsset, depositSymbol, iconUrl) {
|
|
|
95
188
|
depositSymbol,
|
|
96
189
|
pubkey: (0, shared_1.asPubkeyStr)(source.token_address),
|
|
97
190
|
name: source.outcome ?? "",
|
|
98
|
-
symbol: source.short_symbol ?? "",
|
|
191
|
+
symbol: source.symbol ?? source.short_symbol ?? "",
|
|
192
|
+
shortSymbol: source.short_symbol ?? source.symbol ?? "",
|
|
99
193
|
description: source.description,
|
|
100
194
|
decimals: source.decimals ?? 0,
|
|
101
|
-
|
|
195
|
+
iconUrlLow: resolvedIconUrlLow,
|
|
196
|
+
iconUrlMedium: resolvedIconUrlMedium,
|
|
197
|
+
iconUrlHigh: resolvedIconUrlHigh,
|
|
102
198
|
};
|
|
103
199
|
}
|
|
104
200
|
//# sourceMappingURL=tokens.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../src/domain/market/tokens.ts"],"names":[],"mappings":";;;AAuDA,0CAEC;AAED,wCAEC;AAED,0DAyDC;AAvHD,yCAA2C;AAwC3C,MAAa,oBAAqB,SAAQ,KAAK;IACpC,OAAO,CAAW;IAE3B,YAAY,IAAY,EAAE,OAAiB;QACzC,KAAK,CAAC,4BAA4B,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AARD,oDAQC;AAED,MAAM,YAAY,GAAG,8CAA8C,CAAC;AACpE,MAAM,YAAY,GAAG,8CAA8C,CAAC;AACpE,MAAM,cAAc,GAAG,8CAA8C,CAAC;AAEtE,SAAgB,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AkB,CAAC,CAAC;IACnE,IAAI,CAAC,MAAM,CAAC,YAAY;QAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9D,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAEpD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,oBAAoB,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;QAC7B,YAAY,EAAE,IAAA,oBAAW,EAAC,YAAY,CAAC;QACvC,aAAa;QACb,MAAM,EAAE,IAAA,oBAAW,EAAC,MAAM,CAAC,aAAa,CAAC;QACzC,IAAI,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;QAC1B,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC;QAC9B,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import type { PubkeyStr } from \"../../shared\";\nimport { asPubkeyStr } from \"../../shared\";\nimport type { ConditionalTokenResponse, DepositAssetResponse } from \"./wire\";\n\nexport interface Token {\n id: number;\n pubkey: PubkeyStr;\n name: string;\n symbol: string;\n description?: string;\n decimals: number;\n iconUrl: string;\n}\n\nexport interface ConditionalToken extends Token {\n outcomeIndex: number;\n outcome: string;\n depositAsset: PubkeyStr;\n depositSymbol: string;\n}\n\nexport interface DepositAsset extends Token {\n marketPda: PubkeyStr;\n depositAsset: PubkeyStr;\n numOutcomes: number;\n}\n\nexport interface TokenMetadata {\n pubkey: PubkeyStr;\n symbol: string;\n decimals: number;\n iconUrl: string;\n name: string;\n}\n\nexport interface ValidatedTokens {\n token: DepositAsset;\n conditionals: ConditionalToken[];\n metadata: Record<string, TokenMetadata>;\n}\n\nexport class TokenValidationError extends Error {\n readonly details: string[];\n\n constructor(mint: string, details: string[]) {\n super(`Token validation errors (${mint}): ${details.join(\"; \")}`);\n this.name = \"TokenValidationError\";\n this.details = details;\n }\n}\n\nconst USDC_MAINNET = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\";\nconst USDT_MAINNET = \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\";\nconst USDC_DEVNET_LC = \"7SrxsoXjNR7Y8T3koJCt1yV4FrNUumoAUrJExDt6tQez\";\n\nexport function isUsdStablecoin(pubkey: string): boolean {\n return pubkey === USDC_MAINNET || pubkey === USDT_MAINNET || pubkey === USDC_DEVNET_LC;\n}\n\nexport function currencySymbol(pubkey: string): \"\" | \"$\" {\n return isUsdStablecoin(pubkey) ? \"$\" : \"\";\n}\n\nexport function validatedTokensFromWire(source: DepositAssetResponse): ValidatedTokens {\n const errors: string[] = [];\n const metadata: Record<string, TokenMetadata> = {};\n\n const depositPubkey = asPubkeyStr(source.deposit_asset);\n const iconUrl = source.icon_url;\n const name = source.display_name;\n const symbol = source.symbol;\n const decimals = source.decimals;\n\n if (!iconUrl) errors.push(\"Missing icon URL\");\n if (!name) errors.push(\"Missing display name\");\n if (!symbol) errors.push(\"Missing symbol\");\n if (decimals === undefined) errors.push(\"Missing decimals\");\n\n if (errors.length > 0) {\n throw new TokenValidationError(source.deposit_asset, errors);\n }\n\n metadata[source.deposit_asset] = {\n pubkey: depositPubkey,\n symbol: symbol ?? \"\",\n decimals: decimals ?? 0,\n iconUrl: iconUrl ?? \"\",\n name: name ?? \"\",\n };\n\n const conditionals = source.conditional_mints.map((conditional) =>\n conditionalFromWire(conditional, source.deposit_asset, symbol ?? \"\", iconUrl ?? \"\")\n );\n\n for (const conditional of conditionals) {\n metadata[conditional.pubkey] = {\n pubkey: conditional.pubkey,\n symbol: conditional.symbol,\n decimals: conditional.decimals,\n iconUrl: conditional.iconUrl,\n name: conditional.name,\n };\n }\n\n return {\n token: {\n id: source.id,\n marketPda: asPubkeyStr(source.market_pubkey),\n depositAsset: depositPubkey,\n numOutcomes: source.num_outcomes,\n pubkey: depositPubkey,\n name: name ?? \"\",\n symbol: symbol ?? \"\",\n description: source.description,\n decimals: decimals ?? 0,\n iconUrl: iconUrl ?? \"\",\n },\n conditionals,\n metadata,\n };\n}\n\nfunction conditionalFromWire(\n source: ConditionalTokenResponse,\n depositAsset: string,\n depositSymbol: string,\n iconUrl: string\n): ConditionalToken {\n const errors: string[] = [];\n if (source.decimals === undefined) errors.push(\"Missing decimals\");\n if (!source.short_symbol) errors.push(\"Missing short_symbol\");\n if (!source.outcome) errors.push(\"Missing outcome\");\n\n if (errors.length > 0) {\n throw new TokenValidationError(source.token_address, errors);\n }\n\n return {\n id: source.id,\n outcomeIndex: source.outcome_index,\n outcome: source.outcome ?? \"\",\n depositAsset: asPubkeyStr(depositAsset),\n depositSymbol,\n pubkey: asPubkeyStr(source.token_address),\n name: source.outcome ?? \"\",\n symbol: source.short_symbol ?? \"\",\n description: source.description,\n decimals: source.decimals ?? 0,\n iconUrl,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../src/domain/market/tokens.ts"],"names":[],"mappings":";;;AA0BA,oDAaC;AAuBD,sDAYC;AAuED,0CAEC;AAED,wCAEC;AAED,0DAkEC;AAED,gEAmCC;AA/PD,yCAA2C;AAC3C,iCAAyC;AAoBzC;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,KAA4B;IAC/D,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,CAAC,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,CAAC,CAAC;QACX,KAAK,KAAK;YACR,OA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C,CAAC;IACvG,MAAM,kBAAkB,GAAG,WAAW,EAAE,GAAG,IAAI,gBAAgB,CAAC;IAChE,MAAM,qBAAqB,GAAG,WAAW,EAAE,MAAM,IAAI,mBAAmB,CAAC;IACzE,MAAM,mBAAmB,GAAG,WAAW,EAAE,IAAI,IAAI,iBAAiB,CAAC;IAEnE,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;QAC7B,YAAY,EAAE,IAAA,oBAAW,EAAC,YAAY,CAAC;QACvC,aAAa;QACb,MAAM,EAAE,IAAA,oBAAW,EAAC,MAAM,CAAC,aAAa,CAAC;QACzC,IAAI,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;QAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,YAAY,IAAI,EAAE;QAClD,WAAW,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE;QACvD,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC;QAC9B,UAAU,EAAE,kBAAkB;QAC9B,aAAa,EAAE,qBAAqB;QACpC,WAAW,EAAE,mBAAmB;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import type { PubkeyStr } from \"../../shared\";\nimport { asPubkeyStr } from \"../../shared\";\nimport { resolveIconUrls } from \"./icon\";\nimport type {\n ConditionalTokenResponse,\n DepositAssetResponse,\n GlobalDepositAssetResponse,\n} from \"./wire\";\n\nexport interface Token {\n id: number;\n pubkey: PubkeyStr;\n name: string;\n symbol: string;\n shortSymbol: string;\n description?: string;\n decimals: number;\n iconUrlLow: string;\n iconUrlMedium: string;\n iconUrlHigh: string;\n}\n\n/**\n * Display priority for sorting: lower values come first. BTC/WBTC tie at 0,\n * ETH/WETH tie at 1, SOL at 2; everything else falls to the alphabetical tail.\n */\nexport function tokenDisplayPriority(token: Pick<Token, \"symbol\">): number {\n switch (token.symbol) {\n case \"BTC\":\n case \"WBTC\":\n return 0;\n case \"ETH\":\n case \"WETH\":\n return 1;\n case \"SOL\":\n return 2;\n default:\n return 255;\n }\n}\n\n/**\n * Shape accepted by {@link sortByDisplayPriority}. Either a token with a\n * top-level `symbol`, or a composite (e.g. `DepositAssetPair`, `OrderBookPair`)\n * that carries its display token on `base`.\n */\nexport type DisplaySortable =\n | Pick<Token, \"symbol\">\n | { readonly base: Pick<Token, \"symbol\"> };\n\nfunction displaySymbol(item: DisplaySortable): string {\n return \"symbol\" in item ? item.symbol : item.base.symbol;\n}\n\n/**\n * Returns a new array ordered for display: priority groups first\n * (BTC/WBTC → ETH/WETH → SOL), then all remaining items alphabetically by the\n * display token's symbol.\n *\n * Accepts both pure tokens and composite types whose display token lives on\n * `base` (e.g. `DepositAssetPair`, `OrderBookPair`).\n */\nexport function sortByDisplayPriority<T extends DisplaySortable>(items: readonly T[]): T[] {\n const copy = [...items];\n copy.sort((left, right) => {\n const leftSymbol = displaySymbol(left);\n const rightSymbol = displaySymbol(right);\n const priorityDelta =\n tokenDisplayPriority({ symbol: leftSymbol }) -\n tokenDisplayPriority({ symbol: rightSymbol });\n if (priorityDelta !== 0) return priorityDelta;\n return leftSymbol.localeCompare(rightSymbol);\n });\n return copy;\n}\n\nexport interface ConditionalToken extends Token {\n outcomeIndex: number;\n outcome: string;\n depositAsset: PubkeyStr;\n depositSymbol: string;\n}\n\nexport interface DepositAsset extends Token {\n marketPda: PubkeyStr;\n depositAsset: PubkeyStr;\n numOutcomes: number;\n}\n\n/**\n * A base/quote pairing of two `DepositAsset`s.\n *\n * Populated on `Market.depositAssetPairs` during wire→domain conversion —\n * one entry per unique base/quote combination across the market's orderbook\n * pairs.\n */\nexport interface DepositAssetPair {\n /** Stable identifier of the form `\"{basePubkey}-{quotePubkey}\"`. */\n id: string;\n base: DepositAsset;\n quote: DepositAsset;\n}\n\n/**\n * A globally whitelisted deposit asset (platform-scoped, not market-bound).\n *\n * Distinct from `DepositAsset`, which is bound to a specific market.\n */\nexport interface GlobalDepositAsset extends Token {\n depositAsset: PubkeyStr;\n whitelistIndex: number;\n active: boolean;\n}\n\nexport interface TokenMetadata {\n pubkey: PubkeyStr;\n symbol: string;\n shortSymbol: string;\n decimals: number;\n iconUrlLow: string;\n iconUrlMedium: string;\n iconUrlHigh: string;\n name: string;\n}\n\nexport interface ValidatedTokens {\n token: DepositAsset;\n conditionals: ConditionalToken[];\n metadata: Record<string, TokenMetadata>;\n}\n\nexport class TokenValidationError extends Error {\n readonly details: string[];\n\n constructor(mint: string, details: string[]) {\n super(`Token validation errors (${mint}): ${details.join(\"; \")}`);\n this.name = \"TokenValidationError\";\n this.details = details;\n }\n}\n\nconst USDC_MAINNET = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\";\nconst USDT_MAINNET = \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\";\nconst USDC_DEVNET_LC = \"7SrxsoXjNR7Y8T3koJCt1yV4FrNUumoAUrJExDt6tQez\";\n\nexport function isUsdStablecoin(pubkey: string): boolean {\n return pubkey === USDC_MAINNET || pubkey === USDT_MAINNET || pubkey === USDC_DEVNET_LC;\n}\n\nexport function currencySymbol(pubkey: string): \"\" | \"$\" {\n return isUsdStablecoin(pubkey) ? \"$\" : \"\";\n}\n\nexport function validatedTokensFromWire(source: DepositAssetResponse): ValidatedTokens {\n const errors: string[] = [];\n const metadata: Record<string, TokenMetadata> = {};\n\n const depositPubkey = asPubkeyStr(source.deposit_asset);\n const iconUrls = resolveIconUrls(source.icon_url_low, source.icon_url_medium, source.icon_url_high);\n const name = source.display_name;\n const symbol = source.symbol;\n const decimals = source.decimals;\n\n if (!iconUrls) errors.push(\"Missing icon URL\");\n if (!name) errors.push(\"Missing display name\");\n if (!symbol) errors.push(\"Missing symbol\");\n if (decimals === undefined) errors.push(\"Missing decimals\");\n\n if (errors.length > 0) {\n throw new TokenValidationError(source.deposit_asset, errors);\n }\n\n metadata[source.deposit_asset] = {\n pubkey: depositPubkey,\n symbol: symbol ?? \"\",\n shortSymbol: name ?? \"\",\n decimals: decimals ?? 0,\n iconUrlLow: iconUrls?.low ?? \"\",\n iconUrlMedium: iconUrls?.medium ?? \"\",\n iconUrlHigh: iconUrls?.high ?? \"\",\n name: name ?? \"\",\n };\n\n const conditionals = source.conditional_mints.map((conditional) =>\n conditionalFromWire(conditional, source.deposit_asset, symbol ?? \"\", iconUrls?.low ?? \"\", iconUrls?.medium ?? \"\", iconUrls?.high ?? \"\")\n );\n\n for (const conditional of conditionals) {\n metadata[conditional.pubkey] = {\n pubkey: conditional.pubkey,\n symbol: conditional.symbol,\n shortSymbol: conditional.shortSymbol,\n decimals: conditional.decimals,\n iconUrlLow: conditional.iconUrlLow,\n iconUrlMedium: conditional.iconUrlMedium,\n iconUrlHigh: conditional.iconUrlHigh,\n name: conditional.name,\n };\n }\n\n return {\n token: {\n id: source.id,\n marketPda: asPubkeyStr(source.market_pubkey),\n depositAsset: depositPubkey,\n numOutcomes: source.num_outcomes,\n pubkey: depositPubkey,\n name: name ?? \"\",\n symbol: symbol ?? \"\",\n shortSymbol: name ?? \"\",\n description: source.description,\n decimals: decimals ?? 0,\n iconUrlLow: iconUrls?.low ?? \"\",\n iconUrlMedium: iconUrls?.medium ?? \"\",\n iconUrlHigh: iconUrls?.high ?? \"\",\n },\n conditionals,\n metadata,\n };\n}\n\nexport function globalDepositAssetFromWire(\n source: GlobalDepositAssetResponse\n): GlobalDepositAsset {\n const errors: string[] = [];\n\n const name = source.display_name;\n const symbol = source.symbol;\n const iconUrls = resolveIconUrls(source.icon_url_low, source.icon_url_medium, source.icon_url_high);\n const decimals = source.decimals;\n\n if (!name) errors.push(\"Missing display name\");\n if (!symbol) errors.push(\"Missing symbol\");\n if (!iconUrls) errors.push(\"Missing icon URL\");\n if (decimals === undefined || decimals === null) errors.push(\"Missing decimals\");\n\n if (errors.length > 0) {\n throw new TokenValidationError(source.mint, errors);\n }\n\n const depositAsset = asPubkeyStr(source.mint);\n return {\n id: source.id,\n pubkey: depositAsset,\n depositAsset,\n name: name ?? \"\",\n symbol: symbol ?? \"\",\n shortSymbol: name ?? \"\",\n description: source.description,\n decimals: decimals ?? 0,\n iconUrlLow: iconUrls?.low ?? \"\",\n iconUrlMedium: iconUrls?.medium ?? \"\",\n iconUrlHigh: iconUrls?.high ?? \"\",\n whitelistIndex: source.whitelist_index,\n active: source.active,\n };\n}\n\nfunction conditionalFromWire(\n source: ConditionalTokenResponse,\n depositAsset: string,\n depositSymbol: string,\n parentIconUrlLow: string,\n parentIconUrlMedium: string,\n parentIconUrlHigh: string\n): ConditionalToken {\n const errors: string[] = [];\n if (source.decimals === undefined) errors.push(\"Missing decimals\");\n if (!source.short_symbol) errors.push(\"Missing short_symbol\");\n if (!source.outcome) errors.push(\"Missing outcome\");\n\n if (errors.length > 0) {\n throw new TokenValidationError(source.token_address, errors);\n }\n\n const ownIconUrls = resolveIconUrls(source.icon_url_low, source.icon_url_medium, source.icon_url_high);\n const resolvedIconUrlLow = ownIconUrls?.low ?? parentIconUrlLow;\n const resolvedIconUrlMedium = ownIconUrls?.medium ?? parentIconUrlMedium;\n const resolvedIconUrlHigh = ownIconUrls?.high ?? parentIconUrlHigh;\n\n return {\n id: source.id,\n outcomeIndex: source.outcome_index,\n outcome: source.outcome ?? \"\",\n depositAsset: asPubkeyStr(depositAsset),\n depositSymbol,\n pubkey: asPubkeyStr(source.token_address),\n name: source.outcome ?? \"\",\n symbol: source.symbol ?? source.short_symbol ?? \"\",\n shortSymbol: source.short_symbol ?? source.symbol ?? \"\",\n description: source.description,\n decimals: source.decimals ?? 0,\n iconUrlLow: resolvedIconUrlLow,\n iconUrlMedium: resolvedIconUrlMedium,\n iconUrlHigh: resolvedIconUrlHigh,\n };\n}\n"]}
|
|
@@ -3,7 +3,10 @@ import type { Status } from "./index";
|
|
|
3
3
|
export interface OutcomeResponse {
|
|
4
4
|
index: number;
|
|
5
5
|
name: string;
|
|
6
|
-
|
|
6
|
+
name_long?: string;
|
|
7
|
+
icon_url_low?: string;
|
|
8
|
+
icon_url_medium?: string;
|
|
9
|
+
icon_url_high?: string;
|
|
7
10
|
}
|
|
8
11
|
export interface ConditionalTokenResponse {
|
|
9
12
|
id: number;
|
|
@@ -15,7 +18,9 @@ export interface ConditionalTokenResponse {
|
|
|
15
18
|
deposit_symbol?: string;
|
|
16
19
|
short_symbol?: string;
|
|
17
20
|
description?: string;
|
|
18
|
-
|
|
21
|
+
icon_url_low?: string;
|
|
22
|
+
icon_url_medium?: string;
|
|
23
|
+
icon_url_high?: string;
|
|
19
24
|
metadata_uri?: string;
|
|
20
25
|
decimals?: number;
|
|
21
26
|
created_at: string;
|
|
@@ -30,20 +35,41 @@ export interface DepositAssetResponse {
|
|
|
30
35
|
vault: string;
|
|
31
36
|
num_outcomes: number;
|
|
32
37
|
description?: string;
|
|
33
|
-
|
|
38
|
+
icon_url_low?: string;
|
|
39
|
+
icon_url_medium?: string;
|
|
40
|
+
icon_url_high?: string;
|
|
34
41
|
metadata_uri?: string;
|
|
35
42
|
decimals?: number;
|
|
36
43
|
conditional_mints: ConditionalTokenResponse[];
|
|
37
44
|
created_at: string;
|
|
38
45
|
}
|
|
46
|
+
export declare const MarketResolutionKind: {
|
|
47
|
+
readonly SingleWinner: "single_winner";
|
|
48
|
+
readonly Scalar: "scalar";
|
|
49
|
+
};
|
|
50
|
+
export type MarketResolutionKind = (typeof MarketResolutionKind)[keyof typeof MarketResolutionKind];
|
|
51
|
+
export interface MarketResolutionPayout {
|
|
52
|
+
outcome_index: number;
|
|
53
|
+
payout_numerator: number;
|
|
54
|
+
}
|
|
55
|
+
export interface MarketResolutionResponse {
|
|
56
|
+
kind: MarketResolutionKind;
|
|
57
|
+
payout_denominator: number;
|
|
58
|
+
payouts: MarketResolutionPayout[];
|
|
59
|
+
single_winning_outcome: number | null;
|
|
60
|
+
}
|
|
39
61
|
export interface MarketResponse {
|
|
40
62
|
market_name?: string;
|
|
41
63
|
slug?: string;
|
|
42
64
|
description?: string;
|
|
43
65
|
definition?: string;
|
|
44
66
|
outcomes: OutcomeResponse[];
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
banner_image_url_low?: string;
|
|
68
|
+
banner_image_url_medium?: string;
|
|
69
|
+
banner_image_url_high?: string;
|
|
70
|
+
icon_url_low?: string;
|
|
71
|
+
icon_url_medium?: string;
|
|
72
|
+
icon_url_high?: string;
|
|
47
73
|
category?: string;
|
|
48
74
|
tags?: string[];
|
|
49
75
|
featured_rank?: number;
|
|
@@ -53,8 +79,7 @@ export interface MarketResponse {
|
|
|
53
79
|
question_id: string;
|
|
54
80
|
condition_id: string;
|
|
55
81
|
market_status: string;
|
|
56
|
-
|
|
57
|
-
has_winning_outcome: boolean;
|
|
82
|
+
resolution?: MarketResolutionResponse;
|
|
58
83
|
created_at: string;
|
|
59
84
|
activated_at?: string;
|
|
60
85
|
settled_at?: string;
|
|
@@ -72,15 +97,25 @@ export interface SingleMarketResponse {
|
|
|
72
97
|
export interface SearchOrderbook {
|
|
73
98
|
orderbook_id: OrderBookId;
|
|
74
99
|
outcome_name: string;
|
|
100
|
+
outcome_name_long?: string;
|
|
75
101
|
outcome_index: number;
|
|
76
102
|
deposit_base_asset: PubkeyStr;
|
|
77
103
|
deposit_quote_asset: PubkeyStr;
|
|
78
104
|
deposit_base_symbol: string;
|
|
79
105
|
deposit_quote_symbol: string;
|
|
80
|
-
|
|
81
|
-
|
|
106
|
+
base_icon_url_low?: string;
|
|
107
|
+
base_icon_url_medium?: string;
|
|
108
|
+
base_icon_url_high?: string;
|
|
109
|
+
quote_icon_url_low?: string;
|
|
110
|
+
quote_icon_url_medium?: string;
|
|
111
|
+
quote_icon_url_high?: string;
|
|
82
112
|
conditional_base_mint: PubkeyStr;
|
|
83
113
|
conditional_quote_mint: PubkeyStr;
|
|
114
|
+
outcome_icon_url_low?: string;
|
|
115
|
+
outcome_icon_url_medium?: string;
|
|
116
|
+
outcome_icon_url_high?: string;
|
|
117
|
+
conditional_base_symbol?: string;
|
|
118
|
+
conditional_quote_symbol?: string;
|
|
84
119
|
latest_mid_price?: string;
|
|
85
120
|
}
|
|
86
121
|
export interface MarketSearchResult {
|
|
@@ -91,7 +126,9 @@ export interface MarketSearchResult {
|
|
|
91
126
|
tags: string[];
|
|
92
127
|
featured_rank: number;
|
|
93
128
|
description?: string;
|
|
94
|
-
|
|
129
|
+
icon_url_low?: string;
|
|
130
|
+
icon_url_medium?: string;
|
|
131
|
+
icon_url_high?: string;
|
|
95
132
|
orderbooks: SearchOrderbook[];
|
|
96
133
|
}
|
|
97
134
|
export type MarketEvent = {
|
|
@@ -111,4 +148,26 @@ export type MarketEvent = {
|
|
|
111
148
|
market_pubkey: string;
|
|
112
149
|
orderbook_id: string;
|
|
113
150
|
};
|
|
151
|
+
export interface DepositMintsResponse {
|
|
152
|
+
market_pubkey: string;
|
|
153
|
+
deposit_assets: DepositAssetResponse[];
|
|
154
|
+
total: number;
|
|
155
|
+
}
|
|
156
|
+
export interface GlobalDepositAssetResponse {
|
|
157
|
+
id: number;
|
|
158
|
+
mint: string;
|
|
159
|
+
display_name?: string;
|
|
160
|
+
symbol?: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
icon_url_low?: string;
|
|
163
|
+
icon_url_medium?: string;
|
|
164
|
+
icon_url_high?: string;
|
|
165
|
+
decimals: number | null;
|
|
166
|
+
whitelist_index: number;
|
|
167
|
+
active: boolean;
|
|
168
|
+
}
|
|
169
|
+
export interface GlobalDepositAssetsListResponse {
|
|
170
|
+
assets: GlobalDepositAssetResponse[];
|
|
171
|
+
total: number;
|
|
172
|
+
}
|
|
114
173
|
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/domain/market/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE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IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,oBAAoB,EAAE,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/market/wire.ts"],"names":[],"mappings":"","sourcesContent":["import type { OrderBookId, PubkeyStr } from \"../../shared\";\nimport type { Status } from \"./index\";\n\nexport interface OutcomeResponse {\n index: number;\n name: string;\n
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../src/domain/market/wire.ts"],"names":[],"mappings":";;;AAiDa,QAAA,oBAAoB,GAAG;IAClC,YAAY,EAAE,eAAe;IAC7B,MAAM,EAAE,QAAQ;CACR,CAAC","sourcesContent":["import type { OrderBookId, PubkeyStr } from \"../../shared\";\nimport type { Status } from \"./index\";\n\nexport interface OutcomeResponse {\n index: number;\n name: string;\n name_long?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n}\n\nexport interface ConditionalTokenResponse {\n id: number;\n outcome_index: number;\n token_address: string;\n symbol?: string;\n uri?: string;\n outcome?: string;\n deposit_symbol?: string;\n short_symbol?: string;\n description?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n metadata_uri?: string;\n decimals?: number;\n created_at: string;\n}\n\nexport interface DepositAssetResponse {\n display_name?: string;\n token_symbol?: string;\n symbol?: string;\n deposit_asset: string;\n id: number;\n market_pubkey: string;\n vault: string;\n num_outcomes: number;\n description?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n metadata_uri?: string;\n decimals?: number;\n conditional_mints: ConditionalTokenResponse[];\n created_at: string;\n}\n\nexport const MarketResolutionKind = {\n SingleWinner: \"single_winner\",\n Scalar: \"scalar\",\n} as const;\n\nexport type MarketResolutionKind =\n (typeof MarketResolutionKind)[keyof typeof MarketResolutionKind];\n\nexport interface MarketResolutionPayout {\n outcome_index: number;\n payout_numerator: number;\n}\n\nexport interface MarketResolutionResponse {\n kind: MarketResolutionKind;\n payout_denominator: number;\n payouts: MarketResolutionPayout[];\n single_winning_outcome: number | null;\n}\n\nexport interface MarketResponse {\n market_name?: string;\n slug?: string;\n description?: string;\n definition?: string;\n outcomes: OutcomeResponse[];\n banner_image_url_low?: string;\n banner_image_url_medium?: string;\n banner_image_url_high?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n category?: string;\n tags?: string[];\n featured_rank?: number;\n market_pubkey: string;\n market_id: number;\n oracle: string;\n question_id: string;\n condition_id: string;\n market_status: string;\n resolution?: MarketResolutionResponse;\n created_at: string;\n activated_at?: string;\n settled_at?: string;\n deposit_assets: DepositAssetResponse[];\n orderbooks: import(\"../orderbook/wire\").OrderbookResponse[];\n}\n\nexport interface MarketsResponse {\n markets: MarketResponse[];\n next_cursor?: number;\n has_more?: boolean;\n}\n\nexport interface SingleMarketResponse {\n market: MarketResponse;\n}\n\nexport interface SearchOrderbook {\n orderbook_id: OrderBookId;\n outcome_name: string;\n outcome_name_long?: string;\n outcome_index: number;\n deposit_base_asset: PubkeyStr;\n deposit_quote_asset: PubkeyStr;\n deposit_base_symbol: string;\n deposit_quote_symbol: string;\n base_icon_url_low?: string;\n base_icon_url_medium?: string;\n base_icon_url_high?: string;\n quote_icon_url_low?: string;\n quote_icon_url_medium?: string;\n quote_icon_url_high?: string;\n conditional_base_mint: PubkeyStr;\n conditional_quote_mint: PubkeyStr;\n outcome_icon_url_low?: string;\n outcome_icon_url_medium?: string;\n outcome_icon_url_high?: string;\n conditional_base_symbol?: string;\n conditional_quote_symbol?: string;\n latest_mid_price?: string;\n}\n\nexport interface MarketSearchResult {\n slug: string;\n market_name: string;\n market_status: Status;\n category?: string;\n tags: string[];\n featured_rank: number;\n description?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n orderbooks: SearchOrderbook[];\n}\n\nexport type MarketEvent =\n | { event_type: \"settled\"; market_pubkey: string }\n | { event_type: \"created\"; market_pubkey: string }\n | { event_type: \"opened\"; market_pubkey: string }\n | { event_type: \"paused\"; market_pubkey: string }\n | { event_type: \"orderbook_created\"; market_pubkey: string; orderbook_id: string };\n\nexport interface DepositMintsResponse {\n market_pubkey: string;\n deposit_assets: DepositAssetResponse[];\n total: number;\n}\n\nexport interface GlobalDepositAssetResponse {\n id: number;\n mint: string;\n display_name?: string;\n symbol?: string;\n description?: string;\n icon_url_low?: string;\n icon_url_medium?: string;\n icon_url_high?: string;\n decimals: number | null;\n whitelist_index: number;\n active: boolean;\n}\n\nexport interface GlobalDepositAssetsListResponse {\n assets: GlobalDepositAssetResponse[];\n total: number;\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ClientContext } from "../../context";
|
|
2
|
+
import type { OrderBookId, PubkeyStr } from "../../shared";
|
|
3
|
+
import type { CategoriesMetrics, CategoryVolumeMetrics, DepositTokensMetrics, Leaderboard, MarketDetailMetrics, MarketsMetrics, MetricsHistory, MetricsHistoryQuery, OrderbookTickersResponse, OrderbookVolumeMetrics, PlatformMetrics, UserMetrics } from "./wire";
|
|
4
|
+
/**
|
|
5
|
+
* Metrics sub-client — platform / market / orderbook / category / deposit-token
|
|
6
|
+
* volume metrics, market leaderboard, and time-series history.
|
|
7
|
+
*
|
|
8
|
+
* Obtain via `client.metrics()`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Metrics {
|
|
11
|
+
private readonly client;
|
|
12
|
+
constructor(client: ClientContext);
|
|
13
|
+
/** `GET /api/metrics/platform` */
|
|
14
|
+
platform(): Promise<PlatformMetrics>;
|
|
15
|
+
/** `GET /api/metrics/markets` */
|
|
16
|
+
markets(): Promise<MarketsMetrics>;
|
|
17
|
+
/** `GET /api/metrics/markets/{market_pubkey}` */
|
|
18
|
+
market(marketPubkey: PubkeyStr): Promise<MarketDetailMetrics>;
|
|
19
|
+
/**
|
|
20
|
+
* Batch BBO + midpoint per active orderbook (same shape as the WS
|
|
21
|
+
* `Ticker` stream, delivered in one REST call). Optionally filter to
|
|
22
|
+
* orderbooks whose base conditional-token is backed by `depositAsset`.
|
|
23
|
+
* Prices per orderbook are scaled using that orderbook's own decimals.
|
|
24
|
+
*
|
|
25
|
+
* `GET /api/metrics/orderbooks/tickers[?deposit_asset=<mint>]`
|
|
26
|
+
*/
|
|
27
|
+
orderbookTickers(depositAsset?: string): Promise<OrderbookTickersResponse>;
|
|
28
|
+
/** `GET /api/metrics/orderbooks/{orderbook_id}` */
|
|
29
|
+
orderbook(orderbookId: OrderBookId): Promise<OrderbookVolumeMetrics>;
|
|
30
|
+
/** `GET /api/metrics/categories` */
|
|
31
|
+
categories(): Promise<CategoriesMetrics>;
|
|
32
|
+
/** `GET /api/metrics/categories/{category}` */
|
|
33
|
+
category(category: string): Promise<CategoryVolumeMetrics>;
|
|
34
|
+
/** `GET /api/metrics/deposit-tokens` */
|
|
35
|
+
depositTokens(): Promise<DepositTokensMetrics>;
|
|
36
|
+
/** `GET /api/metrics/leaderboard/markets` */
|
|
37
|
+
leaderboard(limit?: number): Promise<Leaderboard>;
|
|
38
|
+
/**
|
|
39
|
+
* `GET /api/metrics/history/{scope}/{scope_key}`
|
|
40
|
+
*
|
|
41
|
+
* `scope` is one of `"orderbook" | "market" | "category" | "deposit_token" | "platform"`.
|
|
42
|
+
*/
|
|
43
|
+
history(scope: string, scopeKey: string, query?: MetricsHistoryQuery): Promise<MetricsHistory>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetch per-wallet trading + referral aggregates for the authenticated
|
|
46
|
+
* user: distinct outcomes traded, total USD volume across all the
|
|
47
|
+
* wallet's trades, and the number of times the wallet's referral codes
|
|
48
|
+
* have been redeemed. The wallet is resolved server-side from the
|
|
49
|
+
* auth cookie.
|
|
50
|
+
*
|
|
51
|
+
* `GET /api/metrics/user`
|
|
52
|
+
*/
|
|
53
|
+
user(): Promise<UserMetrics>;
|
|
54
|
+
/**
|
|
55
|
+
* Same as {@link user} but uses the supplied `cookieHeader` for this call
|
|
56
|
+
* instead of the SDK's process-wide cookie store. For server-side cookie
|
|
57
|
+
* forwarding (SSR / route handlers).
|
|
58
|
+
*/
|
|
59
|
+
userWithCookies(cookieHeader: string): Promise<UserMetrics>;
|
|
60
|
+
/**
|
|
61
|
+
* Public variant of {@link user}. Takes the user's wallet via the URL
|
|
62
|
+
* path (`GET /api/metrics/user/{wallet_address}`) and requires no auth.
|
|
63
|
+
*/
|
|
64
|
+
userByWallet(walletAddress: string): Promise<UserMetrics>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/domain/metrics/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EACV,i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E;;;OAGG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAIhE"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Metrics = void 0;
|
|
4
|
+
const http_1 = require("../../http");
|
|
5
|
+
/**
|
|
6
|
+
* Metrics sub-client — platform / market / orderbook / category / deposit-token
|
|
7
|
+
* volume metrics, market leaderboard, and time-series history.
|
|
8
|
+
*
|
|
9
|
+
* Obtain via `client.metrics()`.
|
|
10
|
+
*/
|
|
11
|
+
class Metrics {
|
|
12
|
+
client;
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
/** `GET /api/metrics/platform` */
|
|
17
|
+
async platform() {
|
|
18
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/platform`;
|
|
19
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
20
|
+
}
|
|
21
|
+
/** `GET /api/metrics/markets` */
|
|
22
|
+
async markets() {
|
|
23
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/markets`;
|
|
24
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
25
|
+
}
|
|
26
|
+
/** `GET /api/metrics/markets/{market_pubkey}` */
|
|
27
|
+
async market(marketPubkey) {
|
|
28
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/markets/${encodeURIComponent(marketPubkey)}`;
|
|
29
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Batch BBO + midpoint per active orderbook (same shape as the WS
|
|
33
|
+
* `Ticker` stream, delivered in one REST call). Optionally filter to
|
|
34
|
+
* orderbooks whose base conditional-token is backed by `depositAsset`.
|
|
35
|
+
* Prices per orderbook are scaled using that orderbook's own decimals.
|
|
36
|
+
*
|
|
37
|
+
* `GET /api/metrics/orderbooks/tickers[?deposit_asset=<mint>]`
|
|
38
|
+
*/
|
|
39
|
+
async orderbookTickers(depositAsset) {
|
|
40
|
+
let url = `${this.client.http.baseUrl()}/api/metrics/orderbooks/tickers`;
|
|
41
|
+
const trimmed = depositAsset?.trim();
|
|
42
|
+
if (trimmed) {
|
|
43
|
+
url += `?deposit_asset=${encodeURIComponent(trimmed)}`;
|
|
44
|
+
}
|
|
45
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
46
|
+
}
|
|
47
|
+
/** `GET /api/metrics/orderbooks/{orderbook_id}` */
|
|
48
|
+
async orderbook(orderbookId) {
|
|
49
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/orderbooks/${encodeURIComponent(orderbookId)}`;
|
|
50
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
51
|
+
}
|
|
52
|
+
/** `GET /api/metrics/categories` */
|
|
53
|
+
async categories() {
|
|
54
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/categories`;
|
|
55
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
56
|
+
}
|
|
57
|
+
/** `GET /api/metrics/categories/{category}` */
|
|
58
|
+
async category(category) {
|
|
59
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/categories/${encodeURIComponent(category)}`;
|
|
60
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
61
|
+
}
|
|
62
|
+
/** `GET /api/metrics/deposit-tokens` */
|
|
63
|
+
async depositTokens() {
|
|
64
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/deposit-tokens`;
|
|
65
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
66
|
+
}
|
|
67
|
+
/** `GET /api/metrics/leaderboard/markets` */
|
|
68
|
+
async leaderboard(limit) {
|
|
69
|
+
let url = `${this.client.http.baseUrl()}/api/metrics/leaderboard/markets`;
|
|
70
|
+
if (limit !== undefined) {
|
|
71
|
+
url += `?limit=${limit}`;
|
|
72
|
+
}
|
|
73
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `GET /api/metrics/history/{scope}/{scope_key}`
|
|
77
|
+
*
|
|
78
|
+
* `scope` is one of `"orderbook" | "market" | "category" | "deposit_token" | "platform"`.
|
|
79
|
+
*/
|
|
80
|
+
async history(scope, scopeKey, query = {}) {
|
|
81
|
+
const search = new URLSearchParams();
|
|
82
|
+
search.set("resolution", query.resolution ?? "1h");
|
|
83
|
+
if (query.from !== undefined)
|
|
84
|
+
search.set("from", String(query.from));
|
|
85
|
+
if (query.to !== undefined)
|
|
86
|
+
search.set("to", String(query.to));
|
|
87
|
+
if (query.limit !== undefined)
|
|
88
|
+
search.set("limit", String(query.limit));
|
|
89
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/history/${encodeURIComponent(scope)}/${encodeURIComponent(scopeKey)}?${search.toString()}`;
|
|
90
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Fetch per-wallet trading + referral aggregates for the authenticated
|
|
94
|
+
* user: distinct outcomes traded, total USD volume across all the
|
|
95
|
+
* wallet's trades, and the number of times the wallet's referral codes
|
|
96
|
+
* have been redeemed. The wallet is resolved server-side from the
|
|
97
|
+
* auth cookie.
|
|
98
|
+
*
|
|
99
|
+
* `GET /api/metrics/user`
|
|
100
|
+
*/
|
|
101
|
+
async user() {
|
|
102
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/user`;
|
|
103
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Same as {@link user} but uses the supplied `cookieHeader` for this call
|
|
107
|
+
* instead of the SDK's process-wide cookie store. For server-side cookie
|
|
108
|
+
* forwarding (SSR / route handlers).
|
|
109
|
+
*/
|
|
110
|
+
async userWithCookies(cookieHeader) {
|
|
111
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/user`;
|
|
112
|
+
return this.client.http.getWithCookies(url, http_1.RetryPolicy.Idempotent, cookieHeader);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Public variant of {@link user}. Takes the user's wallet via the URL
|
|
116
|
+
* path (`GET /api/metrics/user/{wallet_address}`) and requires no auth.
|
|
117
|
+
*/
|
|
118
|
+
async userByWallet(walletAddress) {
|
|
119
|
+
const url = `${this.client.http.baseUrl()}/api/metrics/user/${encodeURIComponent(walletAddress)}`;
|
|
120
|
+
return this.client.http.get(url, http_1.RetryPolicy.Idempotent);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.Metrics = Metrics;
|
|
124
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/domain/metrics/client.ts"],"names":[],"mappings":";;;AACA,qCAAyC;AAiBzC;;;;;GAKG;AACH,MAAa,OAAO;IACW;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,kCAAkC;IAClC,KAAK,CAAC,QAAQ;QACZ,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC;QACjE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAkB,GAAG,EAAE,kBAAW,CAAC,UAAU,CAAC,CAAC;IAC5E,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,OAAO;QACX,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAsB,CAAC;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAiB,GAAG,EAAE,kBAAW,CAAC,UAAU,CAAC,CAAC;IAC3E,CAAC;IAED,iDAAiD;IACjD,KAAK,CAAC,M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BAAqB,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC;QAClG,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAc,GAAG,EAAE,kBAAW,CAAC,UAAU,CAAC,CAAC;IACxE,CAAC;CACF;AA/HD,0BA+HC","sourcesContent":["import type { ClientContext } from \"../../context\";\nimport { RetryPolicy } from \"../../http\";\nimport type { OrderBookId, PubkeyStr } from \"../../shared\";\nimport type {\n CategoriesMetrics,\n CategoryVolumeMetrics,\n DepositTokensMetrics,\n Leaderboard,\n MarketDetailMetrics,\n MarketsMetrics,\n MetricsHistory,\n MetricsHistoryQuery,\n OrderbookTickersResponse,\n OrderbookVolumeMetrics,\n PlatformMetrics,\n UserMetrics,\n} from \"./wire\";\n\n/**\n * Metrics sub-client — platform / market / orderbook / category / deposit-token\n * volume metrics, market leaderboard, and time-series history.\n *\n * Obtain via `client.metrics()`.\n */\nexport class Metrics {\n constructor(private readonly client: ClientContext) {}\n\n /** `GET /api/metrics/platform` */\n async platform(): Promise<PlatformMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/platform`;\n return this.client.http.get<PlatformMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/markets` */\n async markets(): Promise<MarketsMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/markets`;\n return this.client.http.get<MarketsMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/markets/{market_pubkey}` */\n async market(marketPubkey: PubkeyStr): Promise<MarketDetailMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/markets/${encodeURIComponent(marketPubkey)}`;\n return this.client.http.get<MarketDetailMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /**\n * Batch BBO + midpoint per active orderbook (same shape as the WS\n * `Ticker` stream, delivered in one REST call). Optionally filter to\n * orderbooks whose base conditional-token is backed by `depositAsset`.\n * Prices per orderbook are scaled using that orderbook's own decimals.\n *\n * `GET /api/metrics/orderbooks/tickers[?deposit_asset=<mint>]`\n */\n async orderbookTickers(depositAsset?: string): Promise<OrderbookTickersResponse> {\n let url = `${this.client.http.baseUrl()}/api/metrics/orderbooks/tickers`;\n const trimmed = depositAsset?.trim();\n if (trimmed) {\n url += `?deposit_asset=${encodeURIComponent(trimmed)}`;\n }\n return this.client.http.get<OrderbookTickersResponse>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/orderbooks/{orderbook_id}` */\n async orderbook(orderbookId: OrderBookId): Promise<OrderbookVolumeMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/orderbooks/${encodeURIComponent(orderbookId)}`;\n return this.client.http.get<OrderbookVolumeMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/categories` */\n async categories(): Promise<CategoriesMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/categories`;\n return this.client.http.get<CategoriesMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/categories/{category}` */\n async category(category: string): Promise<CategoryVolumeMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/categories/${encodeURIComponent(category)}`;\n return this.client.http.get<CategoryVolumeMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/deposit-tokens` */\n async depositTokens(): Promise<DepositTokensMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/deposit-tokens`;\n return this.client.http.get<DepositTokensMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /** `GET /api/metrics/leaderboard/markets` */\n async leaderboard(limit?: number): Promise<Leaderboard> {\n let url = `${this.client.http.baseUrl()}/api/metrics/leaderboard/markets`;\n if (limit !== undefined) {\n url += `?limit=${limit}`;\n }\n return this.client.http.get<Leaderboard>(url, RetryPolicy.Idempotent);\n }\n\n /**\n * `GET /api/metrics/history/{scope}/{scope_key}`\n *\n * `scope` is one of `\"orderbook\" | \"market\" | \"category\" | \"deposit_token\" | \"platform\"`.\n */\n async history(\n scope: string,\n scopeKey: string,\n query: MetricsHistoryQuery = {}\n ): Promise<MetricsHistory> {\n const search = new URLSearchParams();\n search.set(\"resolution\", query.resolution ?? \"1h\");\n if (query.from !== undefined) search.set(\"from\", String(query.from));\n if (query.to !== undefined) search.set(\"to\", String(query.to));\n if (query.limit !== undefined) search.set(\"limit\", String(query.limit));\n\n const url = `${this.client.http.baseUrl()}/api/metrics/history/${encodeURIComponent(scope)}/${encodeURIComponent(scopeKey)}?${search.toString()}`;\n return this.client.http.get<MetricsHistory>(url, RetryPolicy.Idempotent);\n }\n\n /**\n * Fetch per-wallet trading + referral aggregates for the authenticated\n * user: distinct outcomes traded, total USD volume across all the\n * wallet's trades, and the number of times the wallet's referral codes\n * have been redeemed. The wallet is resolved server-side from the\n * auth cookie.\n *\n * `GET /api/metrics/user`\n */\n async user(): Promise<UserMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/user`;\n return this.client.http.get<UserMetrics>(url, RetryPolicy.Idempotent);\n }\n\n /**\n * Same as {@link user} but uses the supplied `cookieHeader` for this call\n * instead of the SDK's process-wide cookie store. For server-side cookie\n * forwarding (SSR / route handlers).\n */\n async userWithCookies(cookieHeader: string): Promise<UserMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/user`;\n return this.client.http.getWithCookies<UserMetrics>(\n url,\n RetryPolicy.Idempotent,\n cookieHeader,\n );\n }\n\n /**\n * Public variant of {@link user}. Takes the user's wallet via the URL\n * path (`GET /api/metrics/user/{wallet_address}`) and requires no auth.\n */\n async userByWallet(walletAddress: string): Promise<UserMetrics> {\n const url = `${this.client.http.baseUrl()}/api/metrics/user/${encodeURIComponent(walletAddress)}`;\n return this.client.http.get<UserMetrics>(url, RetryPolicy.Idempotent);\n }\n}\n"]}
|