@reyaxyz/strategy-format 0.3.0 → 0.3.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/dist/en.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
- "state.ref": "state {n}",
3
- "state.named": "\"{name}\" (state {n})",
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/lines.json CHANGED
@@ -52,6 +52,7 @@
52
52
  "pin-answer.none": "None of these.",
53
53
  "pin-left-out": "Left out: \"{question}\". {reason}",
54
54
  "pin-label": "Reads Polymarket: \"{question}\" · {outcome} · listed end {date}",
55
+ "pin-label.no-end": "Reads Polymarket: \"{question}\" · {outcome} · no listed end",
55
56
  "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
57
  "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
58
  "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.js CHANGED
@@ -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
- this.lines[id] = this.f('pin.line', {
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(pin.label.ends),
57
+ ...(ends !== undefined && { ends: this.time(ends) }),
56
58
  });
57
59
  }
58
60
  for (const list of doc.lists ?? []) {
@@ -88,11 +90,50 @@ 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
- return name === undefined
94
- ? this.f('state.ref', { n: num(id) })
95
- : this.f('state.named', { name: quoted(name), n: num(id) });
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
139
  return market ?? this.f('market.row');
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: number;
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.0",
3
+ "version": "0.3.1",
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": "a9ea58ff44b41c862a7ce23bc69fa9d977242f0d"
44
+ "gitHead": "004e1bb86cf7d4258a6750e139c7f35bc8fd3b1b"
45
45
  }