@reyaxyz/strategy-format 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/en.json +11 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/lines.json +3 -1
- package/dist/sentences.d.ts +2 -0
- package/dist/sentences.js +55 -9
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
package/dist/en.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"state.ref": "
|
|
3
|
-
"state.
|
|
2
|
+
"state.ref.buy": "the buy step",
|
|
3
|
+
"state.ref.sell": "the sell step",
|
|
4
|
+
"state.ref.order": "the order step",
|
|
5
|
+
"state.ref.close": "the closing step",
|
|
6
|
+
"state.ref.loop": "the loop",
|
|
7
|
+
"state.ref.wait": "the waiting step",
|
|
8
|
+
"state.ref.done": "the final step",
|
|
9
|
+
"state.ref.hold": "the holding step",
|
|
10
|
+
"state.ref.nth": "{ref} ({k})",
|
|
11
|
+
"state.named": "\"{name}\"",
|
|
4
12
|
"state.start": "Start: ",
|
|
5
13
|
"state.start.member": "Start for each member: ",
|
|
6
14
|
"state.in_list": " (for each member of list {list})",
|
|
@@ -98,6 +106,7 @@
|
|
|
98
106
|
"market.row": "the row's market",
|
|
99
107
|
"pin": "the chance of \"{outcome}\" on \"{question}\"",
|
|
100
108
|
"pin.line": "Reads Polymarket: \"{question}\" · {outcome} · listed end {ends}",
|
|
109
|
+
"pin.line.no_end": "Reads Polymarket: \"{question}\" · {outcome} · no listed end",
|
|
101
110
|
"list.fixed": "List {n}: {rows}. Each member starts at {start}.",
|
|
102
111
|
"list.filter": "List {n}: up to {max} markets from {from} where {where}. Each member starts at {start}.",
|
|
103
112
|
"list.rank": "List {n}: the {top} markets from {from} with the {order} {by}. Each member starts at {start}.",
|
package/dist/index.d.ts
CHANGED
|
@@ -1808,7 +1808,7 @@ export declare const schemaSource: {
|
|
|
1808
1808
|
"schema/workflow-v3.accepted-kinds.json": string;
|
|
1809
1809
|
};
|
|
1810
1810
|
};
|
|
1811
|
-
export { sentences } from './sentences';
|
|
1811
|
+
export { marketName, sentences } from './sentences';
|
|
1812
1812
|
export type { Mode, SentenceKey, Translations } from './sentences';
|
|
1813
1813
|
export { line, lineId, LINES, FOLLOW_ONS, needsYouLine, NEEDS_YOU_CODES, activityLine, ACTIVITY_CODES, ACTIVITY_NOT_LISTED, ENTRY_DROPPED, endedLine, PAPER_LINES, END_REASONS, READ_OUTS, gradedFigure, whatIfLine, WHAT_IF_RESPONSES, } from './lines';
|
|
1814
1814
|
export type { LineKey, LineTranslations, LineVars, SayLine, RunStatus, NeedsYouItem, ActivityEntry, Grade, WhatIfRow, } from './lines';
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.WHAT_IF_RESPONSES = exports.whatIfLine = exports.gradedFigure = exports.READ_OUTS = exports.END_REASONS = exports.PAPER_LINES = exports.endedLine = exports.ENTRY_DROPPED = exports.ACTIVITY_NOT_LISTED = exports.ACTIVITY_CODES = exports.activityLine = exports.NEEDS_YOU_CODES = exports.needsYouLine = exports.FOLLOW_ONS = exports.LINES = exports.lineId = exports.line = exports.sentences = exports.schemaSource = exports.acceptedKinds = exports.workflowV3Schema = exports.versionHash = exports.canonical = exports.MAX_DOCUMENT_BYTES = exports.readStrategy = void 0;
|
|
20
|
+
exports.WHAT_IF_RESPONSES = exports.whatIfLine = exports.gradedFigure = exports.READ_OUTS = exports.END_REASONS = exports.PAPER_LINES = exports.endedLine = exports.ENTRY_DROPPED = exports.ACTIVITY_NOT_LISTED = exports.ACTIVITY_CODES = exports.activityLine = exports.NEEDS_YOU_CODES = exports.needsYouLine = exports.FOLLOW_ONS = exports.LINES = exports.lineId = exports.line = exports.sentences = exports.marketName = exports.schemaSource = exports.acceptedKinds = exports.workflowV3Schema = exports.versionHash = exports.canonical = exports.MAX_DOCUMENT_BYTES = exports.readStrategy = void 0;
|
|
21
21
|
const workflow_v3_schema_json_1 = __importDefault(require("./schema/workflow-v3.schema.json"));
|
|
22
22
|
const workflow_v3_accepted_kinds_json_1 = __importDefault(require("./schema/workflow-v3.accepted-kinds.json"));
|
|
23
23
|
const source_json_1 = __importDefault(require("./schema/source.json"));
|
|
@@ -34,6 +34,7 @@ exports.workflowV3Schema = workflow_v3_schema_json_1.default;
|
|
|
34
34
|
exports.acceptedKinds = workflow_v3_accepted_kinds_json_1.default;
|
|
35
35
|
exports.schemaSource = source_json_1.default;
|
|
36
36
|
var sentences_1 = require("./sentences");
|
|
37
|
+
Object.defineProperty(exports, "marketName", { enumerable: true, get: function () { return sentences_1.marketName; } });
|
|
37
38
|
Object.defineProperty(exports, "sentences", { enumerable: true, get: function () { return sentences_1.sentences; } });
|
|
38
39
|
var lines_1 = require("./lines");
|
|
39
40
|
Object.defineProperty(exports, "line", { enumerable: true, get: function () { return lines_1.line; } });
|
package/dist/lines.json
CHANGED
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"why-nothing": "The strategy's record has no event that explains it. The stop is at {level}; the mark is {mark} as of {time}.",
|
|
43
43
|
"size-from-share": "{pct}% of your balance is {amount} USDC today, so each order is {amount} USDC.",
|
|
44
44
|
"feature-unavailable": "{asked} is not available in strategies.",
|
|
45
|
-
"pin-question": "
|
|
45
|
+
"pin-question": "I found {count} questions on Polymarket. Pick the one you mean.",
|
|
46
|
+
"pin-question.one": "I found the question on Polymarket. Check it is the one you mean.",
|
|
46
47
|
"pin-source": "Polymarket, as of {time} UTC",
|
|
47
48
|
"pin-option": "{outcome} · {pct}% now · listed end {date}",
|
|
48
49
|
"pin-thin": " · thin market: ${volume} traded in 24h, ${depth} near the price",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"pin-answer.none": "None of these.",
|
|
53
54
|
"pin-left-out": "Left out: \"{question}\". {reason}",
|
|
54
55
|
"pin-label": "Reads Polymarket: \"{question}\" · {outcome} · listed end {date}",
|
|
56
|
+
"pin-label.no-end": "Reads Polymarket: \"{question}\" · {outcome} · no listed end",
|
|
55
57
|
"pin-past-end": "This market is past its end date and waiting to be resolved. When Polymarket closes it, the rules that read it stop and you get a Needs-you.",
|
|
56
58
|
"pin-ends-early": "This market's listed end date is before your strategy's. When Polymarket closes it, the rules that read it stop and you get a Needs-you.",
|
|
57
59
|
"warn-thin": "\"{question}\" is thinly traded right now: ${depth} near the price. A small trade there can push the odds across your level for a moment, and your rule would fire on it.",
|
package/dist/sentences.d.ts
CHANGED
|
@@ -21,3 +21,5 @@ export type Translations = Record<SentenceKey, string> & Record<string, string>;
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function sentences(doc: StrategyV3, t?: Translations, locale?: string, mode?: Mode): Record<string, string>;
|
|
23
23
|
export type Mode = 'live' | 'paper';
|
|
24
|
+
/** A perp market as the app names it: `BTCRUSDPERP` is `BTC-PERP`; any other code as written. */
|
|
25
|
+
export declare const marketName: (market: string) => string;
|
package/dist/sentences.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sentences = void 0;
|
|
6
|
+
exports.marketName = exports.sentences = void 0;
|
|
7
7
|
const en_json_1 = __importDefault(require("./en.json"));
|
|
8
8
|
/**
|
|
9
9
|
* One line per block, keyed by block id: every state, rule, action, pin and list, and every block
|
|
@@ -48,11 +48,13 @@ class Builder {
|
|
|
48
48
|
this.lines[id] = this.capital(this.action(action));
|
|
49
49
|
}
|
|
50
50
|
for (const [id, pin] of Object.entries(doc.series ?? {})) {
|
|
51
|
-
|
|
51
|
+
const { ends } = pin.label;
|
|
52
|
+
// A market with no end date has no `ends` (reya-chain #488).
|
|
53
|
+
this.lines[id] = this.f(ends === undefined ? 'pin.line.no_end' : 'pin.line', {
|
|
52
54
|
// The question is in quotes, the outcome is not: only the question is escaped.
|
|
53
55
|
outcome: pin.label.outcome,
|
|
54
56
|
question: quoted(pin.label.question),
|
|
55
|
-
ends: this.time(
|
|
57
|
+
...(ends !== undefined && { ends: this.time(ends) }),
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
for (const list of doc.lists ?? []) {
|
|
@@ -88,14 +90,53 @@ class Builder {
|
|
|
88
90
|
return items.join(this.t[key]);
|
|
89
91
|
}
|
|
90
92
|
// ---- references ----
|
|
93
|
+
/**
|
|
94
|
+
* A state as the card names it (devnet1 QA F119): its name, or what it
|
|
95
|
+
* does ("the buy step", "the hold"), never "state 3". Two that do the same
|
|
96
|
+
* are told apart by their order: "the waiting step (2)".
|
|
97
|
+
*/
|
|
91
98
|
stateRef(id) {
|
|
92
99
|
const name = this.doc.states[id]?.name;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
const label = (sid) => {
|
|
101
|
+
const n = this.doc.states[sid]?.name;
|
|
102
|
+
return n === undefined ? this.stateKind(sid) : `"${n}`;
|
|
103
|
+
};
|
|
104
|
+
const ref = name === undefined
|
|
105
|
+
? this.f(`state.ref.${this.stateKind(id)}`)
|
|
106
|
+
: this.f('state.named', { name: quoted(name) });
|
|
107
|
+
const same = Object.keys(this.doc.states)
|
|
108
|
+
.filter((sid) => label(sid) === label(id))
|
|
109
|
+
.sort((a, b) => Number(num(a)) - Number(num(b)));
|
|
110
|
+
return same.length > 1
|
|
111
|
+
? this.f('state.ref.nth', { ref, k: same.indexOf(id) + 1 })
|
|
112
|
+
: ref;
|
|
113
|
+
}
|
|
114
|
+
/** What a state does, for its reference: the orders its rules place, else its kind. */
|
|
115
|
+
stateKind(id) {
|
|
116
|
+
const s = this.doc.states[id];
|
|
117
|
+
if (!s)
|
|
118
|
+
return 'wait';
|
|
119
|
+
if (s.kind === 'final')
|
|
120
|
+
return s.outcome;
|
|
121
|
+
const actions = (s.on ?? [])
|
|
122
|
+
.flatMap((r) => this.doc.rules?.[r]?.do ?? [])
|
|
123
|
+
.map((a) => this.doc.actions?.[a])
|
|
124
|
+
.filter((a) => a !== undefined);
|
|
125
|
+
const sides = new Set(actions.flatMap((a) => a.kind === 'order'
|
|
126
|
+
? [typeof a.side === 'string' ? a.side : 'order']
|
|
127
|
+
: a.kind === 'limit_orders'
|
|
128
|
+
? a.orders.map((o) => typeof o.side === 'string' ? o.side : 'order')
|
|
129
|
+
: []));
|
|
130
|
+
if (sides.size === 1)
|
|
131
|
+
return [...sides][0];
|
|
132
|
+
if (sides.size > 1)
|
|
133
|
+
return 'order';
|
|
134
|
+
if (actions.some((a) => a.kind === 'close' || a.kind === 'reduce'))
|
|
135
|
+
return 'close';
|
|
136
|
+
return s.kind === 'loop_head' ? 'loop' : 'wait';
|
|
96
137
|
}
|
|
97
138
|
market(market) {
|
|
98
|
-
return market
|
|
139
|
+
return market === undefined ? this.f('market.row') : (0, exports.marketName)(market);
|
|
99
140
|
}
|
|
100
141
|
pinById(id) {
|
|
101
142
|
const pin = this.doc.series?.[id];
|
|
@@ -361,7 +402,7 @@ class Builder {
|
|
|
361
402
|
if (l.kind === 'fixed') {
|
|
362
403
|
const rows = l.members.map((m) => {
|
|
363
404
|
const line = this.f('row', {
|
|
364
|
-
market: m.market,
|
|
405
|
+
market: (0, exports.marketName)(m.market),
|
|
365
406
|
side: m.side ? this.f('row.side', { side: this.side(m.side) }) : '',
|
|
366
407
|
size: m.size ? this.f('row.size', { size: this.size(m.size) }) : '',
|
|
367
408
|
reads: m.reads
|
|
@@ -378,7 +419,9 @@ class Builder {
|
|
|
378
419
|
rows: this.join(rows, 'rows.join'),
|
|
379
420
|
});
|
|
380
421
|
}
|
|
381
|
-
const from = l.from
|
|
422
|
+
const from = l.from
|
|
423
|
+
? this.join(l.from.map(exports.marketName))
|
|
424
|
+
: this.f('list.from.all');
|
|
382
425
|
return l.kind === 'filter'
|
|
383
426
|
? this.f('list.filter', {
|
|
384
427
|
...base,
|
|
@@ -545,6 +588,9 @@ const WINDOWED = new Set([
|
|
|
545
588
|
]); // prettier-ignore
|
|
546
589
|
/** The window functions that take an `anchor` (the engine's `WindowFn`); others ignore it. */
|
|
547
590
|
const ANCHORED = new Set(['sma', 'ema', 'high', 'low', 'stdev', 'pct_change']);
|
|
591
|
+
/** A perp market as the app names it: `BTCRUSDPERP` is `BTC-PERP`; any other code as written. */
|
|
592
|
+
const marketName = (market) => market.replace(/^([A-Z0-9]+)RUSDPERP$/, '$1-PERP');
|
|
593
|
+
exports.marketName = marketName;
|
|
548
594
|
/** User text shown inside quotes: a quote in it cannot end the quote early. */
|
|
549
595
|
const quoted = (text) => text.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
550
596
|
const COMPARISONS = new Set(['gt', 'ge', 'lt', 'le', 'eq', 'ne']);
|
package/dist/types.d.ts
CHANGED
|
@@ -221,10 +221,11 @@ export interface SeriesPin {
|
|
|
221
221
|
source: 'polymarket';
|
|
222
222
|
market: string;
|
|
223
223
|
outcome: string;
|
|
224
|
+
/** `ends` absent for a market with no end date (reya-chain #488); never null. */
|
|
224
225
|
label: {
|
|
225
226
|
question: string;
|
|
226
227
|
outcome: string;
|
|
227
|
-
ends
|
|
228
|
+
ends?: number;
|
|
228
229
|
};
|
|
229
230
|
}
|
|
230
231
|
export interface StrategyV3 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/strategy-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The v3 strategy format for TypeScript: reya-chain's schema and accepted kinds, the reader, the version hash, the block sentences and the line table",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"typescript": "5.3.3"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "074c2ae1d2a37acf60104771b7c22904a959e37b"
|
|
45
45
|
}
|