@lightconexyz/lightcone-sdk 0.5.2 → 0.6.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 +34 -4
- package/dist/client.d.ts +30 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -0
- package/dist/client.js.map +1 -1
- package/dist/domain/admin/client.d.ts +10 -1
- package/dist/domain/admin/client.d.ts.map +1 -1
- package/dist/domain/admin/client.js +51 -0
- package/dist/domain/admin/client.js.map +1 -1
- package/dist/domain/admin/wire.d.ts +267 -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 +30 -0
- 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 +43 -4
- 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 +13 -4
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js +3 -1
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/market/outcome.d.ts +3 -1
- package/dist/domain/market/outcome.d.ts.map +1 -1
- package/dist/domain/market/outcome.js +7 -7
- package/dist/domain/market/outcome.js.map +1 -1
- package/dist/domain/market/tokens.d.ts +53 -3
- package/dist/domain/market/tokens.d.ts.map +1 -1
- package/dist/domain/market/tokens.js +99 -8
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +46 -8
- package/dist/domain/market/wire.d.ts.map +1 -1
- 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 +342 -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 +3 -1
- 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 +28 -2
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +76 -16
- 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 +1 -1
- package/dist/domain/order/convert.js.map +1 -1
- package/dist/domain/order/index.d.ts +1 -1
- package/dist/domain/order/index.d.ts.map +1 -1
- 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/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/client.d.ts +55 -0
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +71 -0
- 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/http/client.d.ts +9 -0
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +24 -9
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +12 -4
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +4 -2
- package/dist/prelude.js.map +1 -1
- package/dist/shared/fmt/decimal.js +4 -4
- package/dist/shared/fmt/decimal.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/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,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveIconUrls = exports.globalDepositAssetFromWire = void 0;
|
|
3
4
|
exports.marketFromWire = marketFromWire;
|
|
5
|
+
exports.deriveDepositAssetPairs = deriveDepositAssetPairs;
|
|
4
6
|
exports.tryMarketFromWire = tryMarketFromWire;
|
|
5
7
|
const shared_1 = require("../../shared");
|
|
6
8
|
const convert_1 = require("../orderbook/convert");
|
|
9
|
+
const icon_1 = require("./icon");
|
|
10
|
+
Object.defineProperty(exports, "resolveIconUrls", { enumerable: true, get: function () { return icon_1.resolveIconUrls; } });
|
|
7
11
|
const outcome_1 = require("./outcome");
|
|
8
12
|
const index_1 = require("./index");
|
|
9
13
|
const tokens_1 = require("./tokens");
|
|
14
|
+
Object.defineProperty(exports, "globalDepositAssetFromWire", { enumerable: true, get: function () { return tokens_1.globalDepositAssetFromWire; } });
|
|
10
15
|
function marketFromWire(source) {
|
|
11
16
|
const errors = [];
|
|
12
17
|
const outcomes = source.outcomes.flatMap((outcome) => {
|
|
@@ -52,10 +57,16 @@ function marketFromWire(source) {
|
|
|
52
57
|
errors.push("Missing description");
|
|
53
58
|
if (!source.definition)
|
|
54
59
|
errors.push("Missing definition");
|
|
55
|
-
|
|
60
|
+
const iconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
61
|
+
if (!iconUrls)
|
|
56
62
|
errors.push("Missing icon URL");
|
|
57
|
-
|
|
63
|
+
const bannerUrls = (0, icon_1.resolveIconUrls)(source.banner_image_url_low, source.banner_image_url_medium, source.banner_image_url_high);
|
|
64
|
+
if (!bannerUrls)
|
|
58
65
|
errors.push("Missing banner image URL");
|
|
66
|
+
const depositAssetPairs = (0, tokens_1.sortByDisplayPriority)(deriveDepositAssetPairs(depositAssets, orderbookPairs));
|
|
67
|
+
if (depositAssetPairs.length === 0) {
|
|
68
|
+
errors.push("Missing deposit asset pairs");
|
|
69
|
+
}
|
|
59
70
|
if (errors.length > 0) {
|
|
60
71
|
throw new index_1.MarketValidationError(source.market_pubkey, errors);
|
|
61
72
|
}
|
|
@@ -63,8 +74,12 @@ function marketFromWire(source) {
|
|
|
63
74
|
id: source.market_id,
|
|
64
75
|
pubkey: (0, shared_1.asPubkeyStr)(source.market_pubkey),
|
|
65
76
|
name: source.market_name ?? "",
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
bannerImageUrlLow: bannerUrls?.low ?? "",
|
|
78
|
+
bannerImageUrlMedium: bannerUrls?.medium ?? "",
|
|
79
|
+
bannerImageUrlHigh: bannerUrls?.high ?? "",
|
|
80
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
81
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
82
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
68
83
|
featuredRank: source.featured_rank,
|
|
69
84
|
volume: "0",
|
|
70
85
|
slug: source.slug ?? "",
|
|
@@ -78,6 +93,7 @@ function marketFromWire(source) {
|
|
|
78
93
|
category: source.category,
|
|
79
94
|
tags: source.tags ?? [],
|
|
80
95
|
depositAssets,
|
|
96
|
+
depositAssetPairs,
|
|
81
97
|
conditionalTokens,
|
|
82
98
|
outcomes,
|
|
83
99
|
orderbookPairs,
|
|
@@ -85,6 +101,29 @@ function marketFromWire(source) {
|
|
|
85
101
|
tokenMetadata,
|
|
86
102
|
};
|
|
87
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Derive unique base/quote deposit-asset pairs across the market's orderbook
|
|
106
|
+
* pairs. Deduplicated by `(basePubkey, quotePubkey)`; orderbook pairs whose
|
|
107
|
+
* base or quote deposit asset is not present in `depositAssets` are skipped.
|
|
108
|
+
*/
|
|
109
|
+
function deriveDepositAssetPairs(depositAssets, orderbookPairs) {
|
|
110
|
+
const seen = new Map();
|
|
111
|
+
for (const pair of orderbookPairs) {
|
|
112
|
+
const base = depositAssets.find((asset) => asset.depositAsset === pair.base.depositAsset);
|
|
113
|
+
const quote = depositAssets.find((asset) => asset.depositAsset === pair.quote.depositAsset);
|
|
114
|
+
if (!base || !quote)
|
|
115
|
+
continue;
|
|
116
|
+
const key = `${base.depositAsset}|${quote.depositAsset}`;
|
|
117
|
+
if (!seen.has(key)) {
|
|
118
|
+
seen.set(key, {
|
|
119
|
+
id: `${base.depositAsset}-${quote.depositAsset}`,
|
|
120
|
+
base,
|
|
121
|
+
quote,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return Array.from(seen.values());
|
|
126
|
+
}
|
|
88
127
|
function tryMarketFromWire(source) {
|
|
89
128
|
try {
|
|
90
129
|
return { market: marketFromWire(source) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/domain/market/convert.ts"],"names":[],"mappings":";;AAOA,wCA0EC;AAED,8CAMC;AAzFD,yCAA2C;AAC3C,kDAA6D;AAC7D,uCAA4C;AAC5C,mCAAqF;AACrF,qCAAmD;AAGnD,SAAgB,cAAc,CAAC,MAAsB;IACnD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,OAAO,CAAC,IAAA,yBAAe,EAAC,OAAO,CAAC,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,C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C;QACtC,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5E,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;QACtE,cAAc,EAAE,MAAM,CAAC,eAAe;QACtC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;QACrC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,EAAE;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;QACvB,aAAa;QACb,iBAAiB;QACjB,QAAQ;QACR,cAAc;QACd,YAAY,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;QAC5D,aAAa;KACd,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAsB;IACtD,IAAI,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { asPubkeyStr } from \"../../shared\";\nimport { orderBookPairFromWire } from \"../orderbook/convert\";\nimport { outcomeFromWire } from \"./outcome\";\nimport { statusFromWire, type Market, MarketValidationError, Status } from \"./index\";\nimport { validatedTokensFromWire } from \"./tokens\";\nimport type { MarketResponse } from \"./wire\";\n\nexport function marketFromWire(source: MarketResponse): Market {\n const errors: string[] = [];\n\n const outcomes = source.outcomes.flatMap((outcome) => {\n try {\n return [outcomeFromWire(outcome)];\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n return [];\n }\n });\n\n const depositAssets = [] as Market[\"depositAssets\"];\n const conditionalTokens = [] as Market[\"conditionalTokens\"];\n const tokenMetadata: Market[\"tokenMetadata\"] = {};\n\n for (const depositAsset of source.deposit_assets) {\n try {\n const validated = validatedTokensFromWire(depositAsset);\n depositAssets.push(validated.token);\n conditionalTokens.push(...validated.conditionals);\n Object.assign(tokenMetadata, validated.metadata);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n const orderbookPairs = source.orderbooks.flatMap((orderbook) => {\n try {\n return [orderBookPairFromWire(orderbook, conditionalTokens)];\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n return [];\n }\n });\n\n const status = statusFromWire(source.market_status);\n if (!source.slug) errors.push(\"Missing slug\");\n if (!source.market_name) errors.push(\"Missing market name\");\n if (!status) errors.push(`Invalid status: ${source.market_status}`);\n if (!source.description) errors.push(\"Missing description\");\n if (!source.definition) errors.push(\"Missing definition\");\n if (!source.icon_url) errors.push(\"Missing icon URL\");\n if (!source.banner_image_url) errors.push(\"Missing banner image URL\");\n\n if (errors.length > 0) {\n throw new MarketValidationError(source.market_pubkey, errors);\n }\n\n return {\n id: source.market_id,\n pubkey: asPubkeyStr(source.market_pubkey),\n name: source.market_name ?? \"\",\n bannerImageUrl: source.banner_image_url ?? \"\",\n iconUrl: source.icon_url ?? \"\",\n featuredRank: source.featured_rank,\n volume: \"0\",\n slug: source.slug ?? \"\",\n status: status ?? Status.Pending,\n createdAt: new Date(source.created_at),\n activatedAt: source.activated_at ? new Date(source.activated_at) : undefined,\n settledAt: source.settled_at ? new Date(source.settled_at) : undefined,\n winningOutcome: source.winning_outcome,\n description: source.description ?? \"\",\n definition: source.definition ?? \"\",\n category: source.category,\n tags: source.tags ?? [],\n depositAssets,\n conditionalTokens,\n outcomes,\n orderbookPairs,\n orderbookIds: orderbookPairs.map((pair) => pair.orderbookId),\n tokenMetadata,\n };\n}\n\nexport function tryMarketFromWire(source: MarketResponse): { market?: Market; error?: string } {\n try {\n return { market: marketFromWire(source) };\n } catch (error) {\n return { error: error instanceof Error ? error.message : String(error) };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/domain/market/convert.ts"],"names":[],"mappings":";;;AAiBA,wCA2FC;AAOD,0DA2BC;AAED,8CAMC;AAtJD,yCAA2C;AAE3C,kDAA6D;AAC7D,iCAAyC;AAYJ,gGAZ5B,sBAAe,OAY4B;AAXpD,uCAA4C;AAC5C,mCAAqF;AACrF,qCAMkB;AAGT,2GARP,mCAA0B,OAQO;AAEnC,SAAgB,cAAc,CAAC,MAAsB;IACnD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,OAAO,CAAC,IAAA,yBAAe,EAAC,OAAO,CAAC,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACpE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,EAA6B,CAAC;IACpD,MAAM,iBAAiB,GAAG,EAAiC,CAAC;IAC5D,MAAM,aAAa,GAA4B,EAAE,CAAC;IAElD,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAA,gCAAuB,EAAC,YAAY,CAAC,CAAC;YACxD,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACpC,iB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AG,aAAa,CAAC,IAAI,CAC9B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,YAAY,CAC1D,CAAC;QAEF,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK;YAAE,SAAS;QAE9B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QACzD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;gBACZ,EAAE,EAAE,GAAG,IAAI,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,EAAE;gBAChD,IAAI;gBACJ,KAAK;aACN,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,iBAAiB,CAAC,MAAsB;IACtD,IAAI,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { asPubkeyStr } from \"../../shared\";\nimport type { OrderBookPair } from \"../orderbook\";\nimport { orderBookPairFromWire } from \"../orderbook/convert\";\nimport { resolveIconUrls } from \"./icon\";\nimport { outcomeFromWire } from \"./outcome\";\nimport { statusFromWire, type Market, MarketValidationError, Status } from \"./index\";\nimport {\n globalDepositAssetFromWire,\n sortByDisplayPriority,\n validatedTokensFromWire,\n type DepositAsset,\n type DepositAssetPair,\n} from \"./tokens\";\nimport type { MarketResponse } from \"./wire\";\n\nexport { globalDepositAssetFromWire, resolveIconUrls };\n\nexport function marketFromWire(source: MarketResponse): Market {\n const errors: string[] = [];\n\n const outcomes = source.outcomes.flatMap((outcome) => {\n try {\n return [outcomeFromWire(outcome)];\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n return [];\n }\n });\n\n const depositAssets = [] as Market[\"depositAssets\"];\n const conditionalTokens = [] as Market[\"conditionalTokens\"];\n const tokenMetadata: Market[\"tokenMetadata\"] = {};\n\n for (const depositAsset of source.deposit_assets) {\n try {\n const validated = validatedTokensFromWire(depositAsset);\n depositAssets.push(validated.token);\n conditionalTokens.push(...validated.conditionals);\n Object.assign(tokenMetadata, validated.metadata);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n const orderbookPairs = source.orderbooks.flatMap((orderbook) => {\n try {\n return [orderBookPairFromWire(orderbook, conditionalTokens)];\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n return [];\n }\n });\n\n const status = statusFromWire(source.market_status);\n if (!source.slug) errors.push(\"Missing slug\");\n if (!source.market_name) errors.push(\"Missing market name\");\n if (!status) errors.push(`Invalid status: ${source.market_status}`);\n if (!source.description) errors.push(\"Missing description\");\n if (!source.definition) errors.push(\"Missing definition\");\n\n const iconUrls = resolveIconUrls(source.icon_url_low, source.icon_url_medium, source.icon_url_high);\n if (!iconUrls) errors.push(\"Missing icon URL\");\n\n const bannerUrls = resolveIconUrls(source.banner_image_url_low, source.banner_image_url_medium, source.banner_image_url_high);\n if (!bannerUrls) errors.push(\"Missing banner image URL\");\n\n const depositAssetPairs = sortByDisplayPriority(\n deriveDepositAssetPairs(depositAssets, orderbookPairs),\n );\n\n if (depositAssetPairs.length === 0) {\n errors.push(\"Missing deposit asset pairs\");\n }\n\n if (errors.length > 0) {\n throw new MarketValidationError(source.market_pubkey, errors);\n }\n\n return {\n id: source.market_id,\n pubkey: asPubkeyStr(source.market_pubkey),\n name: source.market_name ?? \"\",\n bannerImageUrlLow: bannerUrls?.low ?? \"\",\n bannerImageUrlMedium: bannerUrls?.medium ?? \"\",\n bannerImageUrlHigh: bannerUrls?.high ?? \"\",\n iconUrlLow: iconUrls?.low ?? \"\",\n iconUrlMedium: iconUrls?.medium ?? \"\",\n iconUrlHigh: iconUrls?.high ?? \"\",\n featuredRank: source.featured_rank,\n volume: \"0\",\n slug: source.slug ?? \"\",\n status: status ?? Status.Pending,\n createdAt: new Date(source.created_at),\n activatedAt: source.activated_at ? new Date(source.activated_at) : undefined,\n settledAt: source.settled_at ? new Date(source.settled_at) : undefined,\n winningOutcome: source.winning_outcome,\n description: source.description ?? \"\",\n definition: source.definition ?? \"\",\n category: source.category,\n tags: source.tags ?? [],\n depositAssets,\n depositAssetPairs,\n conditionalTokens,\n outcomes,\n orderbookPairs,\n orderbookIds: orderbookPairs.map((pair) => pair.orderbookId),\n tokenMetadata,\n };\n}\n\n/**\n * Derive unique base/quote deposit-asset pairs across the market's orderbook\n * pairs. Deduplicated by `(basePubkey, quotePubkey)`; orderbook pairs whose\n * base or quote deposit asset is not present in `depositAssets` are skipped.\n */\nexport function deriveDepositAssetPairs(\n depositAssets: DepositAsset[],\n orderbookPairs: OrderBookPair[],\n): DepositAssetPair[] {\n const seen = new Map<string, DepositAssetPair>();\n\n for (const pair of orderbookPairs) {\n const base = depositAssets.find(\n (asset) => asset.depositAsset === pair.base.depositAsset,\n );\n const quote = depositAssets.find(\n (asset) => asset.depositAsset === pair.quote.depositAsset,\n );\n\n if (!base || !quote) continue;\n\n const key = `${base.depositAsset}|${quote.depositAsset}`;\n if (!seen.has(key)) {\n seen.set(key, {\n id: `${base.depositAsset}-${quote.depositAsset}`,\n base,\n quote,\n });\n }\n }\n\n return Array.from(seen.values());\n}\n\nexport function tryMarketFromWire(source: MarketResponse): { market?: Market; error?: string } {\n try {\n return { market: marketFromWire(source) };\n } catch (error) {\n return { error: error instanceof Error ? error.message : String(error) };\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve icon URL variants with fallback logic.
|
|
3
|
+
*
|
|
4
|
+
* Returns `null` when **all three** variants are missing (undefined/null/empty),
|
|
5
|
+
* which signals a validation error. When at least one variant is available the
|
|
6
|
+
* missing ones are filled in using a priority chain:
|
|
7
|
+
*
|
|
8
|
+
* - `low` : try medium, then high
|
|
9
|
+
* - `medium`: try low, then high
|
|
10
|
+
* - `high` : try medium, then low
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveIconUrls(low: string | undefined | null, medium: string | undefined | null, high: string | undefined | null): {
|
|
13
|
+
low: string;
|
|
14
|
+
medium: string;
|
|
15
|
+
high: string;
|
|
16
|
+
} | null;
|
|
17
|
+
//# sourceMappingURL=icon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../../src/domain/market/icon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC9B,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACjC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC9B;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQtD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveIconUrls = resolveIconUrls;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve icon URL variants with fallback logic.
|
|
6
|
+
*
|
|
7
|
+
* Returns `null` when **all three** variants are missing (undefined/null/empty),
|
|
8
|
+
* which signals a validation error. When at least one variant is available the
|
|
9
|
+
* missing ones are filled in using a priority chain:
|
|
10
|
+
*
|
|
11
|
+
* - `low` : try medium, then high
|
|
12
|
+
* - `medium`: try low, then high
|
|
13
|
+
* - `high` : try medium, then low
|
|
14
|
+
*/
|
|
15
|
+
function resolveIconUrls(low, medium, high) {
|
|
16
|
+
const any = low || medium || high;
|
|
17
|
+
if (!any)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
low: low || medium || high || any,
|
|
21
|
+
medium: medium || low || high || any,
|
|
22
|
+
high: high || medium || low || any,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../../src/domain/market/icon.ts"],"names":[],"mappings":";;AAWA,0CAYC;AAvBD;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAC7B,GAA8B,EAC9B,MAAiC,EACjC,IAA+B;IAE/B,MAAM,GAAG,GAAG,GAAG,IAAI,MAAM,IAAI,IAAI,CAAC;IAClC,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO;QACL,GAAG,EAAE,GAAG,IAAI,MAAM,IAAI,IAAI,IAAI,GAAG;QACjC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG;QACpC,IAAI,EAAE,IAAI,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG;KACnC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Resolve icon URL variants with fallback logic.\n *\n * Returns `null` when **all three** variants are missing (undefined/null/empty),\n * which signals a validation error. When at least one variant is available the\n * missing ones are filled in using a priority chain:\n *\n * - `low` : try medium, then high\n * - `medium`: try low, then high\n * - `high` : try medium, then low\n */\nexport function resolveIconUrls(\n low: string | undefined | null,\n medium: string | undefined | null,\n high: string | undefined | null,\n): { low: string; medium: string; high: string } | null {\n const any = low || medium || high;\n if (!any) return null;\n return {\n low: low || medium || high || any,\n medium: medium || low || high || any,\n high: high || medium || low || any,\n };\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { OrderBookId, PubkeyStr } from "../../shared";
|
|
2
2
|
import type { OrderBookPair } from "../orderbook";
|
|
3
3
|
import type { Outcome } from "./outcome";
|
|
4
|
-
import type { ConditionalToken, DepositAsset, TokenMetadata } from "./tokens";
|
|
4
|
+
import type { ConditionalToken, DepositAsset, DepositAssetPair, TokenMetadata } from "./tokens";
|
|
5
5
|
export * from "./client";
|
|
6
6
|
export * from "./wire";
|
|
7
7
|
export * from "./outcome";
|
|
8
8
|
export * from "./tokens";
|
|
9
|
-
export { marketFromWire, tryMarketFromWire } from "./convert";
|
|
9
|
+
export { globalDepositAssetFromWire, marketFromWire, tryMarketFromWire, resolveIconUrls } from "./convert";
|
|
10
10
|
export declare enum Status {
|
|
11
11
|
Pending = "Pending",
|
|
12
12
|
Active = "Active",
|
|
@@ -18,8 +18,12 @@ export interface Market {
|
|
|
18
18
|
id: number;
|
|
19
19
|
pubkey: PubkeyStr;
|
|
20
20
|
name: string;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
bannerImageUrlLow: string;
|
|
22
|
+
bannerImageUrlMedium: string;
|
|
23
|
+
bannerImageUrlHigh: string;
|
|
24
|
+
iconUrlLow: string;
|
|
25
|
+
iconUrlMedium: string;
|
|
26
|
+
iconUrlHigh: string;
|
|
23
27
|
featuredRank?: number;
|
|
24
28
|
volume: string;
|
|
25
29
|
slug: string;
|
|
@@ -33,6 +37,11 @@ export interface Market {
|
|
|
33
37
|
category?: string;
|
|
34
38
|
tags: string[];
|
|
35
39
|
depositAssets: DepositAsset[];
|
|
40
|
+
/**
|
|
41
|
+
* Unique base/quote deposit-asset pairs derived from `orderbookPairs`
|
|
42
|
+
* during wire→domain conversion. Deduplicated by `(base, quote)` pubkey.
|
|
43
|
+
*/
|
|
44
|
+
depositAssetPairs: DepositAssetPair[];
|
|
36
45
|
conditionalTokens: ConditionalToken[];
|
|
37
46
|
outcomes: Outcome[];
|
|
38
47
|
orderbookPairs: OrderBookPair[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/market/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACd,MAAM,UAAU,CAAC;AAElB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3G,oBAAY,MAAM;IAChB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,SAAS,cAAc;CACxB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAahE;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC9C;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEf,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAMpD"}
|
|
@@ -14,15 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MarketValidationError = exports.Status = exports.tryMarketFromWire = exports.marketFromWire = void 0;
|
|
17
|
+
exports.MarketValidationError = exports.Status = exports.resolveIconUrls = exports.tryMarketFromWire = exports.marketFromWire = exports.globalDepositAssetFromWire = void 0;
|
|
18
18
|
exports.statusFromWire = statusFromWire;
|
|
19
19
|
__exportStar(require("./client"), exports);
|
|
20
20
|
__exportStar(require("./wire"), exports);
|
|
21
21
|
__exportStar(require("./outcome"), exports);
|
|
22
22
|
__exportStar(require("./tokens"), exports);
|
|
23
23
|
var convert_1 = require("./convert");
|
|
24
|
+
Object.defineProperty(exports, "globalDepositAssetFromWire", { enumerable: true, get: function () { return convert_1.globalDepositAssetFromWire; } });
|
|
24
25
|
Object.defineProperty(exports, "marketFromWire", { enumerable: true, get: function () { return convert_1.marketFromWire; } });
|
|
25
26
|
Object.defineProperty(exports, "tryMarketFromWire", { enumerable: true, get: function () { return convert_1.tryMarketFromWire; } });
|
|
27
|
+
Object.defineProperty(exports, "resolveIconUrls", { enumerable: true, get: function () { return convert_1.resolveIconUrls; } });
|
|
26
28
|
var Status;
|
|
27
29
|
(function (Status) {
|
|
28
30
|
Status["Pending"] = "Pending";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/market/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/market/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuBA,wCAaC;AA1BD,2CAAyB;AACzB,yCAAuB;AACvB,4CAA0B;AAC1B,2CAAyB;AACzB,qCAA2G;AAAlG,qHAAA,0BAA0B,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,0GAAA,eAAe,OAAA;AAEvF,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,6BAAmB,CAAA;IACnB,2BAAiB,CAAA;IACjB,+BAAqB,CAAA;IACrB,iCAAuB,CAAA;AACzB,CAAC,EALW,MAAM,sBAAN,MAAM,QAKjB;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,MAAM,CAAC,OAAO;YACjB,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,KAAK,MAAM,CAAC,MAAM;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC;QACvB,KAAK,MAAM,CAAC,QAAQ;YAClB,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,KAAK,MAAM,CAAC,SAAS;YACnB,OAAO,MAAM,CAAC,SAAS,CAAC;QAC1B;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAqCD,MAAa,qBAAsB,SAAQ,KAAK;IACrC,YAAY,CAAS;IACrB,OAAO,CAAW;IAE3B,YAAY,YAAoB,EAAE,OAAiB;QACjD,KAAK,CAAC,6BAA6B,YAAY,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,sDAUC","sourcesContent":["import type { OrderBookId, PubkeyStr } from \"../../shared\";\nimport type { OrderBookPair } from \"../orderbook\";\nimport type { Outcome } from \"./outcome\";\nimport type {\n ConditionalToken,\n DepositAsset,\n DepositAssetPair,\n TokenMetadata,\n} from \"./tokens\";\n\nexport * from \"./client\";\nexport * from \"./wire\";\nexport * from \"./outcome\";\nexport * from \"./tokens\";\nexport { globalDepositAssetFromWire, marketFromWire, tryMarketFromWire, resolveIconUrls } from \"./convert\";\n\nexport enum Status {\n Pending = \"Pending\",\n Active = \"Active\",\n Resolved = \"Resolved\",\n Cancelled = \"Cancelled\",\n}\n\nexport function statusFromWire(value: string): Status | undefined {\n switch (value) {\n case Status.Pending:\n return Status.Pending;\n case Status.Active:\n return Status.Active;\n case Status.Resolved:\n return Status.Resolved;\n case Status.Cancelled:\n return Status.Cancelled;\n default:\n return undefined;\n }\n}\n\nexport interface Market {\n id: number;\n pubkey: PubkeyStr;\n name: string;\n bannerImageUrlLow: string;\n bannerImageUrlMedium: string;\n bannerImageUrlHigh: string;\n iconUrlLow: string;\n iconUrlMedium: string;\n iconUrlHigh: string;\n featuredRank?: number;\n volume: string;\n slug: string;\n status: Status;\n createdAt: Date;\n activatedAt?: Date;\n settledAt?: Date;\n winningOutcome?: number;\n description: string;\n definition: string;\n category?: string;\n tags: string[];\n depositAssets: DepositAsset[];\n /**\n * Unique base/quote deposit-asset pairs derived from `orderbookPairs`\n * during wire→domain conversion. Deduplicated by `(base, quote)` pubkey.\n */\n depositAssetPairs: DepositAssetPair[];\n conditionalTokens: ConditionalToken[];\n outcomes: Outcome[];\n orderbookPairs: OrderBookPair[];\n orderbookIds: OrderBookId[];\n tokenMetadata: Record<string, TokenMetadata>;\n}\n\nexport class MarketValidationError extends Error {\n readonly marketPubkey: string;\n readonly details: string[];\n\n constructor(marketPubkey: string, details: string[]) {\n super(`Market validation errors (${marketPubkey}): ${details.join(\"; \")}`);\n this.name = \"MarketValidationError\";\n this.marketPubkey = marketPubkey;\n this.details = details;\n }\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { OutcomeResponse } from "./wire";
|
|
2
2
|
export interface Outcome {
|
|
3
3
|
index: number;
|
|
4
|
-
|
|
4
|
+
iconUrlLow: string;
|
|
5
|
+
iconUrlMedium: string;
|
|
6
|
+
iconUrlHigh: string;
|
|
5
7
|
name: string;
|
|
6
8
|
}
|
|
7
9
|
export declare class OutcomeValidationError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../../../src/domain/market/outcome.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../../../src/domain/market/outcome.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAK5C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAahE"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutcomeValidationError = void 0;
|
|
4
4
|
exports.outcomeFromWire = outcomeFromWire;
|
|
5
|
+
const icon_1 = require("./icon");
|
|
5
6
|
class OutcomeValidationError extends Error {
|
|
6
7
|
details;
|
|
7
8
|
constructor(name, details) {
|
|
@@ -12,16 +13,15 @@ class OutcomeValidationError extends Error {
|
|
|
12
13
|
}
|
|
13
14
|
exports.OutcomeValidationError = OutcomeValidationError;
|
|
14
15
|
function outcomeFromWire(source) {
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
if (errors.length > 0) {
|
|
20
|
-
throw new OutcomeValidationError(source.name, errors);
|
|
16
|
+
const iconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
17
|
+
if (!iconUrls) {
|
|
18
|
+
throw new OutcomeValidationError(source.name, ["Missing icon URL"]);
|
|
21
19
|
}
|
|
22
20
|
return {
|
|
23
21
|
index: source.index,
|
|
24
|
-
|
|
22
|
+
iconUrlLow: iconUrls.low,
|
|
23
|
+
iconUrlMedium: iconUrls.medium,
|
|
24
|
+
iconUrlHigh: iconUrls.high,
|
|
25
25
|
name: source.name,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.js","sourceRoot":"","sources":["../../../src/domain/market/outcome.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"outcome.js","sourceRoot":"","sources":["../../../src/domain/market/outcome.ts"],"names":[],"mappings":";;;AAqBA,0CAaC;AAlCD,iCAAyC;AAWzC,MAAa,sBAAuB,SAAQ,KAAK;IACtC,OAAO,CAAW;IAE3B,YAAY,IAAY,EAAE,OAAiB;QACzC,KAAK,CAAC,8BAA8B,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AARD,wDAQC;AAED,SAAgB,eAAe,CAAC,MAAuB;IACrD,MAAM,QAAQ,GAAG,IAAA,sBAAe,EAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,QAAQ,CAAC,GAAG;QACxB,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,WAAW,EAAE,QAAQ,CAAC,IAAI;QAC1B,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC;AACJ,CAAC","sourcesContent":["import { resolveIconUrls } from \"./icon\";\nimport type { OutcomeResponse } from \"./wire\";\n\nexport interface Outcome {\n index: number;\n iconUrlLow: string;\n iconUrlMedium: string;\n iconUrlHigh: string;\n name: string;\n}\n\nexport class OutcomeValidationError extends Error {\n readonly details: string[];\n\n constructor(name: string, details: string[]) {\n super(`Outcome validation errors (${name}): ${details.join(\"; \")}`);\n this.name = \"OutcomeValidationError\";\n this.details = details;\n }\n}\n\nexport function outcomeFromWire(source: OutcomeResponse): Outcome {\n const iconUrls = resolveIconUrls(source.icon_url_low, source.icon_url_medium, source.icon_url_high);\n if (!iconUrls) {\n throw new OutcomeValidationError(source.name, [\"Missing icon URL\"]);\n }\n\n return {\n index: source.index,\n iconUrlLow: iconUrls.low,\n iconUrlMedium: iconUrls.medium,\n iconUrlHigh: iconUrls.high,\n name: source.name,\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PubkeyStr } from "../../shared";
|
|
2
|
-
import type { DepositAssetResponse } from "./wire";
|
|
2
|
+
import type { DepositAssetResponse, GlobalDepositAssetResponse } from "./wire";
|
|
3
3
|
export interface Token {
|
|
4
4
|
id: number;
|
|
5
5
|
pubkey: PubkeyStr;
|
|
@@ -7,8 +7,32 @@ export interface Token {
|
|
|
7
7
|
symbol: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
decimals: number;
|
|
10
|
-
|
|
10
|
+
iconUrlLow: string;
|
|
11
|
+
iconUrlMedium: string;
|
|
12
|
+
iconUrlHigh: string;
|
|
11
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Display priority for sorting: lower values come first. BTC/WBTC tie at 0,
|
|
16
|
+
* ETH/WETH tie at 1, SOL at 2; everything else falls to the alphabetical tail.
|
|
17
|
+
*/
|
|
18
|
+
export declare function tokenDisplayPriority(token: Pick<Token, "symbol">): number;
|
|
19
|
+
/**
|
|
20
|
+
* Shape accepted by {@link sortByDisplayPriority}. Either a token with a
|
|
21
|
+
* top-level `symbol`, or a composite (e.g. `DepositAssetPair`, `OrderBookPair`)
|
|
22
|
+
* that carries its display token on `base`.
|
|
23
|
+
*/
|
|
24
|
+
export type DisplaySortable = Pick<Token, "symbol"> | {
|
|
25
|
+
readonly base: Pick<Token, "symbol">;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns a new array ordered for display: priority groups first
|
|
29
|
+
* (BTC/WBTC → ETH/WETH → SOL), then all remaining items alphabetically by the
|
|
30
|
+
* display token's symbol.
|
|
31
|
+
*
|
|
32
|
+
* Accepts both pure tokens and composite types whose display token lives on
|
|
33
|
+
* `base` (e.g. `DepositAssetPair`, `OrderBookPair`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function sortByDisplayPriority<T extends DisplaySortable>(items: readonly T[]): T[];
|
|
12
36
|
export interface ConditionalToken extends Token {
|
|
13
37
|
outcomeIndex: number;
|
|
14
38
|
outcome: string;
|
|
@@ -20,11 +44,36 @@ export interface DepositAsset extends Token {
|
|
|
20
44
|
depositAsset: PubkeyStr;
|
|
21
45
|
numOutcomes: number;
|
|
22
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* A base/quote pairing of two `DepositAsset`s.
|
|
49
|
+
*
|
|
50
|
+
* Populated on `Market.depositAssetPairs` during wire→domain conversion —
|
|
51
|
+
* one entry per unique base/quote combination across the market's orderbook
|
|
52
|
+
* pairs.
|
|
53
|
+
*/
|
|
54
|
+
export interface DepositAssetPair {
|
|
55
|
+
/** Stable identifier of the form `"{basePubkey}-{quotePubkey}"`. */
|
|
56
|
+
id: string;
|
|
57
|
+
base: DepositAsset;
|
|
58
|
+
quote: DepositAsset;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A globally whitelisted deposit asset (platform-scoped, not market-bound).
|
|
62
|
+
*
|
|
63
|
+
* Distinct from `DepositAsset`, which is bound to a specific market.
|
|
64
|
+
*/
|
|
65
|
+
export interface GlobalDepositAsset extends Token {
|
|
66
|
+
depositAsset: PubkeyStr;
|
|
67
|
+
whitelistIndex: number;
|
|
68
|
+
active: boolean;
|
|
69
|
+
}
|
|
23
70
|
export interface TokenMetadata {
|
|
24
71
|
pubkey: PubkeyStr;
|
|
25
72
|
symbol: string;
|
|
26
73
|
decimals: number;
|
|
27
|
-
|
|
74
|
+
iconUrlLow: string;
|
|
75
|
+
iconUrlMedium: string;
|
|
76
|
+
iconUrlHigh: string;
|
|
28
77
|
name: string;
|
|
29
78
|
}
|
|
30
79
|
export interface ValidatedTokens {
|
|
@@ -39,4 +88,5 @@ export declare class TokenValidationError extends Error {
|
|
|
39
88
|
export declare function isUsdStablecoin(pubkey: string): boolean;
|
|
40
89
|
export declare function currencySymbol(pubkey: string): "" | "$";
|
|
41
90
|
export declare function validatedTokensFromWire(source: DepositAssetResponse): ValidatedTokens;
|
|
91
|
+
export declare function globalDepositAssetFromWire(source: GlobalDepositAssetResponse): GlobalDepositAsset;
|
|
42
92
|
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/domain/market/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/domain/market/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EAEV,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,QAAQ,CAAC;AAEhB,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,MAAM,CAazE;AAED;;;;G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AAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACzC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAK5C;AAMD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,GAAG,GAAG,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CA+DrF;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,0BAA0B,GACjC,kBAAkB,CAgCpB"}
|
|
@@ -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");
|
|
@@ -46,16 +92,20 @@ function validatedTokensFromWire(source) {
|
|
|
46
92
|
pubkey: depositPubkey,
|
|
47
93
|
symbol: symbol ?? "",
|
|
48
94
|
decimals: decimals ?? 0,
|
|
49
|
-
|
|
95
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
96
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
97
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
50
98
|
name: name ?? "",
|
|
51
99
|
};
|
|
52
|
-
const conditionals = source.conditional_mints.map((conditional) => conditionalFromWire(conditional, source.deposit_asset, symbol ?? "",
|
|
100
|
+
const conditionals = source.conditional_mints.map((conditional) => conditionalFromWire(conditional, source.deposit_asset, symbol ?? "", iconUrls?.low ?? "", iconUrls?.medium ?? "", iconUrls?.high ?? ""));
|
|
53
101
|
for (const conditional of conditionals) {
|
|
54
102
|
metadata[conditional.pubkey] = {
|
|
55
103
|
pubkey: conditional.pubkey,
|
|
56
104
|
symbol: conditional.symbol,
|
|
57
105
|
decimals: conditional.decimals,
|
|
58
|
-
|
|
106
|
+
iconUrlLow: conditional.iconUrlLow,
|
|
107
|
+
iconUrlMedium: conditional.iconUrlMedium,
|
|
108
|
+
iconUrlHigh: conditional.iconUrlHigh,
|
|
59
109
|
name: conditional.name,
|
|
60
110
|
};
|
|
61
111
|
}
|
|
@@ -70,13 +120,48 @@ function validatedTokensFromWire(source) {
|
|
|
70
120
|
symbol: symbol ?? "",
|
|
71
121
|
description: source.description,
|
|
72
122
|
decimals: decimals ?? 0,
|
|
73
|
-
|
|
123
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
124
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
125
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
74
126
|
},
|
|
75
127
|
conditionals,
|
|
76
128
|
metadata,
|
|
77
129
|
};
|
|
78
130
|
}
|
|
79
|
-
function
|
|
131
|
+
function globalDepositAssetFromWire(source) {
|
|
132
|
+
const errors = [];
|
|
133
|
+
const name = source.display_name;
|
|
134
|
+
const symbol = source.symbol;
|
|
135
|
+
const iconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
136
|
+
const decimals = source.decimals;
|
|
137
|
+
if (!name)
|
|
138
|
+
errors.push("Missing display name");
|
|
139
|
+
if (!symbol)
|
|
140
|
+
errors.push("Missing symbol");
|
|
141
|
+
if (!iconUrls)
|
|
142
|
+
errors.push("Missing icon URL");
|
|
143
|
+
if (decimals === undefined || decimals === null)
|
|
144
|
+
errors.push("Missing decimals");
|
|
145
|
+
if (errors.length > 0) {
|
|
146
|
+
throw new TokenValidationError(source.mint, errors);
|
|
147
|
+
}
|
|
148
|
+
const depositAsset = (0, shared_1.asPubkeyStr)(source.mint);
|
|
149
|
+
return {
|
|
150
|
+
id: source.id,
|
|
151
|
+
pubkey: depositAsset,
|
|
152
|
+
depositAsset,
|
|
153
|
+
name: name ?? "",
|
|
154
|
+
symbol: symbol ?? "",
|
|
155
|
+
description: source.description,
|
|
156
|
+
decimals: decimals ?? 0,
|
|
157
|
+
iconUrlLow: iconUrls?.low ?? "",
|
|
158
|
+
iconUrlMedium: iconUrls?.medium ?? "",
|
|
159
|
+
iconUrlHigh: iconUrls?.high ?? "",
|
|
160
|
+
whitelistIndex: source.whitelist_index,
|
|
161
|
+
active: source.active,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function conditionalFromWire(source, depositAsset, depositSymbol, parentIconUrlLow, parentIconUrlMedium, parentIconUrlHigh) {
|
|
80
165
|
const errors = [];
|
|
81
166
|
if (source.decimals === undefined)
|
|
82
167
|
errors.push("Missing decimals");
|
|
@@ -87,6 +172,10 @@ function conditionalFromWire(source, depositAsset, depositSymbol, iconUrl) {
|
|
|
87
172
|
if (errors.length > 0) {
|
|
88
173
|
throw new TokenValidationError(source.token_address, errors);
|
|
89
174
|
}
|
|
175
|
+
const ownIconUrls = (0, icon_1.resolveIconUrls)(source.icon_url_low, source.icon_url_medium, source.icon_url_high);
|
|
176
|
+
const resolvedIconUrlLow = ownIconUrls?.low ?? parentIconUrlLow;
|
|
177
|
+
const resolvedIconUrlMedium = ownIconUrls?.medium ?? parentIconUrlMedium;
|
|
178
|
+
const resolvedIconUrlHigh = ownIconUrls?.high ?? parentIconUrlHigh;
|
|
90
179
|
return {
|
|
91
180
|
id: source.id,
|
|
92
181
|
outcomeIndex: source.outcome_index,
|
|
@@ -98,7 +187,9 @@ function conditionalFromWire(source, depositAsset, depositSymbol, iconUrl) {
|
|
|
98
187
|
symbol: source.short_symbol ?? "",
|
|
99
188
|
description: source.description,
|
|
100
189
|
decimals: source.decimals ?? 0,
|
|
101
|
-
|
|
190
|
+
iconUrlLow: resolvedIconUrlLow,
|
|
191
|
+
iconUrlMedium: resolvedIconUrlMedium,
|
|
192
|
+
iconUrlHigh: resolvedIconUrlHigh,
|
|
102
193
|
};
|
|
103
194
|
}
|
|
104
195
|
//# sourceMappingURL=tokens.js.map
|