@pulsepairs/sdk 0.5.0 → 0.5.2
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.js +11 -0
- package/dist/ws.js +31 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { readOnChainHolderShares, reconcileFills, reportedFromPositions, type On
|
|
|
7
7
|
export { UpDownAccountKitSigner, bareErc1271Signer, stripErc6492Wrapper, isErc6492Signature, type UpDownAccountKitConfig, type Eip1193Provider, type GrantSessionResult, type RawTypedDataSigner, } from "./accountKit.js";
|
|
8
8
|
export { buildApproveSettlementTx, buildInstallOrderSessionTx, signWithOrderSession, type RawTransaction, type OrderSessionRecord, } from "./accountKit.js";
|
|
9
9
|
export { PRICE_BPS_SCALE, WIN_MARK_BPS, LOSE_MARK_BPS, DEFAULT_USDT_DECIMALS, atomicToUsdt, markValueAtomic, midBps, markForOption, isResolvedWinner, positionPnl, feesPaidByWallet, portfolioPnl, computePortfolioPnl, type MarkSource, type PositionPnl, type PortfolioPnl, type PositionPnlOptions, } from "./pnl.js";
|
|
10
|
-
export { OrderType, OrderSide, Option, type ApiConfig, type Balance, type CancelOrderBody, type Eip712Domain, type MarketDetail, type MarketListItem, type OptionValue, type OrderBookFull, type OrderBookLevel, type OrderBookSide, type OrderRow, type OrderSideKey, type OrderSideValue, type OrderStatus, type OrderTypeKey, type OrderTypeValue, type OrdersResponse, type PairConfig, type PairSymbol, type PostOrderBody, type Position, type Stats, type Trade, type Version, } from "./types.js";
|
|
10
|
+
export { OrderType, OrderSide, Option, takerPriceBps, type ApiConfig, type Balance, type CancelOrderBody, type Eip712Domain, type MarketDetail, type MarketListItem, type OptionValue, type OrderBookFull, type OrderBookLevel, type OrderBookSide, type OrderRow, type OrderSideKey, type OrderSideValue, type OrderStatus, type OrderTypeKey, type OrderTypeValue, type OrdersResponse, type PairConfig, type PairSymbol, type PostOrderBody, type Position, type Stats, type Trade, type Version, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -25,4 +25,4 @@ export { buildApproveSettlementTx, buildInstallOrderSessionTx, signWithOrderSess
|
|
|
25
25
|
// contract). `UpDownHttpClient.getPnl` is the batteries-included wrapper.
|
|
26
26
|
export { PRICE_BPS_SCALE, WIN_MARK_BPS, LOSE_MARK_BPS, DEFAULT_USDT_DECIMALS, atomicToUsdt, markValueAtomic, midBps, markForOption, isResolvedWinner, positionPnl, feesPaidByWallet, portfolioPnl, computePortfolioPnl, } from "./pnl.js";
|
|
27
27
|
// Types
|
|
28
|
-
export { OrderType, OrderSide, Option, } from "./types.js";
|
|
28
|
+
export { OrderType, OrderSide, Option, takerPriceBps, } from "./types.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -140,18 +140,40 @@ export type Position = {
|
|
|
140
140
|
export type Trade = {
|
|
141
141
|
tradeId: string;
|
|
142
142
|
market: string;
|
|
143
|
+
/** The TAKER leg's option (1=UP, 2=DOWN). On a MINT/MERGE the maker leg is
|
|
144
|
+
* the opposite option. */
|
|
143
145
|
option: number;
|
|
144
146
|
buyOrderId: string;
|
|
145
147
|
sellOrderId: string;
|
|
148
|
+
/** NORMAL: the buyer. MINT/MERGE: the aggressor (taker) — a buyer on MINT,
|
|
149
|
+
* a seller on MERGE. */
|
|
146
150
|
buyer: string;
|
|
151
|
+
/** NORMAL: the seller. MINT/MERGE: the resting maker, on the OPPOSITE option
|
|
152
|
+
* to `option`. */
|
|
147
153
|
seller: string;
|
|
154
|
+
/** Basis points — the resting MAKER's pegged execution price. On a
|
|
155
|
+
* complementary fill the taker executed at the complement; render taker
|
|
156
|
+
* fills with `takerPrice`, not this. */
|
|
148
157
|
price: number;
|
|
149
158
|
amount: string;
|
|
150
159
|
platformFee: string;
|
|
151
160
|
makerFee: string;
|
|
152
161
|
settlementStatus: string;
|
|
153
162
|
createdAt: string;
|
|
163
|
+
/** Match geometry. NORMAL = same-option fill. MINT/MERGE = complementary
|
|
164
|
+
* cross (opposite-option legs). Optional so a pre-2026-07-17 backend
|
|
165
|
+
* (field absent) degrades rather than breaking a consumer. */
|
|
166
|
+
matchType?: "NORMAL" | "MINT" | "MERGE";
|
|
167
|
+
/** Basis points the taker actually executed at: `price` on NORMAL,
|
|
168
|
+
* `10000 − price` on MINT/MERGE. Prefer this over `price` when rendering a
|
|
169
|
+
* wallet's own fills. Optional for the same back-compat reason. */
|
|
170
|
+
takerPrice?: number;
|
|
154
171
|
};
|
|
172
|
+
/** The price the AGGRESSOR paid/received per share, in bps. Mirrors the
|
|
173
|
+
* backend's `takerPriceBps`: the complement on a complementary fill, else the
|
|
174
|
+
* row price. Falls back to computing the complement if a row predates the
|
|
175
|
+
* `takerPrice` field. */
|
|
176
|
+
export declare function takerPriceBps(trade: Pick<Trade, "price" | "matchType" | "takerPrice">): number;
|
|
155
177
|
export type OrderStatus = "OPEN" | "PARTIALLY_FILLED" | "FILLED" | "CANCEL_PENDING" | "CANCELLED" | string;
|
|
156
178
|
export type OrderRow = {
|
|
157
179
|
orderId: string;
|
package/dist/types.js
CHANGED
|
@@ -18,3 +18,14 @@ export const Option = {
|
|
|
18
18
|
UP: 1,
|
|
19
19
|
DOWN: 2,
|
|
20
20
|
};
|
|
21
|
+
/** The price the AGGRESSOR paid/received per share, in bps. Mirrors the
|
|
22
|
+
* backend's `takerPriceBps`: the complement on a complementary fill, else the
|
|
23
|
+
* row price. Falls back to computing the complement if a row predates the
|
|
24
|
+
* `takerPrice` field. */
|
|
25
|
+
export function takerPriceBps(trade) {
|
|
26
|
+
if (typeof trade.takerPrice === "number")
|
|
27
|
+
return trade.takerPrice;
|
|
28
|
+
return trade.matchType === "MINT" || trade.matchType === "MERGE"
|
|
29
|
+
? 10000 - trade.price
|
|
30
|
+
: trade.price;
|
|
31
|
+
}
|
package/dist/ws.js
CHANGED
|
@@ -154,14 +154,42 @@ export class UpDownWsClient {
|
|
|
154
154
|
openSocket() {
|
|
155
155
|
if (this.closed)
|
|
156
156
|
return;
|
|
157
|
+
// Close any socket we're superseding before opening a new one. Without
|
|
158
|
+
// this, a rapid connect→(reconnect|reconnectMode) churn could leave the
|
|
159
|
+
// previous socket open — especially one still in CONNECTING, whose
|
|
160
|
+
// `onopen` fires after we've moved on.
|
|
161
|
+
if (this.ws) {
|
|
162
|
+
const stale = this.ws;
|
|
163
|
+
stale.onopen = stale.onmessage = stale.onclose = stale.onerror = null;
|
|
164
|
+
try {
|
|
165
|
+
stale.close();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* ignore */
|
|
169
|
+
}
|
|
170
|
+
}
|
|
157
171
|
const ws = new WebSocket(this.url);
|
|
158
172
|
this.ws = ws;
|
|
159
173
|
this.state = "idle";
|
|
160
174
|
ws.onopen = () => {
|
|
175
|
+
// Guard: if we were disconnected, or a newer socket has superseded this
|
|
176
|
+
// one, this socket is an orphan (it finished CONNECTING after we moved
|
|
177
|
+
// on). Close it instead of leaving it open and streaming.
|
|
178
|
+
if (this.closed || this.ws !== ws) {
|
|
179
|
+
try {
|
|
180
|
+
ws.close();
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
/* ignore */
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
161
187
|
this.reconnect = 0;
|
|
162
188
|
void this.startHandshake();
|
|
163
189
|
};
|
|
164
190
|
ws.onmessage = (ev) => {
|
|
191
|
+
if (this.ws !== ws)
|
|
192
|
+
return; // ignore frames from a superseded socket
|
|
165
193
|
let parsed;
|
|
166
194
|
try {
|
|
167
195
|
parsed = JSON.parse(String(ev.data));
|
|
@@ -172,7 +200,9 @@ export class UpDownWsClient {
|
|
|
172
200
|
void this.handleIncoming(parsed);
|
|
173
201
|
};
|
|
174
202
|
ws.onclose = () => {
|
|
175
|
-
|
|
203
|
+
// A superseded socket's close must not trigger a reconnect — the live
|
|
204
|
+
// `this.ws` is a different, healthy socket.
|
|
205
|
+
if (this.closed || this.ws !== ws)
|
|
176
206
|
return;
|
|
177
207
|
if (this.state === "unauthed-failure") {
|
|
178
208
|
// signAuth was rejected — don't reconnect into a hot loop.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulsepairs/sdk",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Standalone SDK for the UpDown (PulsePairs) up/down prediction markets
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "Standalone SDK for the UpDown (PulsePairs) up/down prediction markets — matcher REST/WS client, EIP-712 order signing, trade-math, and Alchemy Account Kit (smart-account) order signing for rain.trade integration.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|