@stryke-xyz/premarket-sdk 1.2.5 → 1.2.7
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 +40 -0
- package/dist/cjs/api/orderbook-api/deserializers.js +3 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/utils/token-id.js +41 -0
- package/dist/esm/api/orderbook-api/deserializers.js +3 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/utils/token-id.js +20 -0
- package/dist/types/api/orderbook-api/deserializers.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/shared/types.d.ts +7 -0
- package/dist/types/utils/token-id.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -894,6 +894,9 @@ export interface BaseMarket {
|
|
|
894
894
|
Public exports:
|
|
895
895
|
|
|
896
896
|
- `UserPosition` — raw position fields (holding, cost, proceeds, PnL)
|
|
897
|
+
- `totalCost` is lifetime accumulated cost.
|
|
898
|
+
- `openCostBasis` is the current open-position basis.
|
|
899
|
+
- `avgEntryPrice` is derived from `openCostBasis / holding`.
|
|
897
900
|
- `EventEnrichment` — optional market/instrument metadata attached to positions
|
|
898
901
|
and history events (`collateralSymbol`, `marketId`, `marketName`,
|
|
899
902
|
`instrumentName`, `logoUri`, `collateralDecimals`, `collateralToken`)
|
|
@@ -901,6 +904,23 @@ Public exports:
|
|
|
901
904
|
additional instrument fields:
|
|
902
905
|
|
|
903
906
|
```ts
|
|
907
|
+
export type CostBasisMethod = "weighted_average";
|
|
908
|
+
|
|
909
|
+
export interface UserPosition {
|
|
910
|
+
id: string;
|
|
911
|
+
tokenId: string;
|
|
912
|
+
holding: string;
|
|
913
|
+
totalCost: string;
|
|
914
|
+
openCostBasis: string;
|
|
915
|
+
avgEntryPrice: string; // collateral per 1 PRM/oPRM, scaled by 1e18
|
|
916
|
+
costBasisMethod: CostBasisMethod;
|
|
917
|
+
totalProceeds: string;
|
|
918
|
+
realizedPnL: string;
|
|
919
|
+
tradePnl: string;
|
|
920
|
+
redeemExercisePnl: string;
|
|
921
|
+
updatedAt: string;
|
|
922
|
+
}
|
|
923
|
+
|
|
904
924
|
export interface EnrichedPosition extends UserPosition, EventEnrichment {
|
|
905
925
|
isOpen: boolean; // true when holding > 0
|
|
906
926
|
isOPrm: boolean; // true = oPRM (outcome), false = PRM (write/minted)
|
|
@@ -950,6 +970,26 @@ export interface EnrichedPositionsResponse {
|
|
|
950
970
|
- `TokenPnL`
|
|
951
971
|
- `Erc20PnL`
|
|
952
972
|
|
|
973
|
+
```ts
|
|
974
|
+
export interface TokenPnL {
|
|
975
|
+
tokenId: string;
|
|
976
|
+
position: {
|
|
977
|
+
holding: string;
|
|
978
|
+
totalCost: string;
|
|
979
|
+
openCostBasis: string;
|
|
980
|
+
avgEntryPrice: string; // collateral per 1 PRM/oPRM, scaled by 1e18
|
|
981
|
+
costBasisMethod: "weighted_average";
|
|
982
|
+
totalProceeds: string;
|
|
983
|
+
realizedPnL: string;
|
|
984
|
+
} | null;
|
|
985
|
+
trading: TradingPnL | null;
|
|
986
|
+
redeemExercise: SettlementPnL | null;
|
|
987
|
+
tradePnl: string;
|
|
988
|
+
redeemExercisePnl: string;
|
|
989
|
+
totalPnl: string;
|
|
990
|
+
}
|
|
991
|
+
```
|
|
992
|
+
|
|
953
993
|
### History DTOs
|
|
954
994
|
|
|
955
995
|
Public exports:
|
|
@@ -221,6 +221,9 @@ function submarketToBigInt(submarket) {
|
|
|
221
221
|
tokenId: BigInt(pos.tokenId),
|
|
222
222
|
holding: BigInt(pos.holding),
|
|
223
223
|
totalCost: BigInt(pos.totalCost),
|
|
224
|
+
openCostBasis: BigInt(pos.openCostBasis),
|
|
225
|
+
avgEntryPrice: BigInt(pos.avgEntryPrice),
|
|
226
|
+
costBasisMethod: pos.costBasisMethod,
|
|
224
227
|
totalProceeds: BigInt(pos.totalProceeds),
|
|
225
228
|
realizedPnL: BigInt(pos.realizedPnL),
|
|
226
229
|
updatedAt: BigInt(pos.updatedAt)
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,6 +10,7 @@ _export_star(require("./constants.js"), exports);
|
|
|
10
10
|
_export_star(require("./utils/rand-bigint.js"), exports);
|
|
11
11
|
_export_star(require("./utils/mul-div.js"), exports);
|
|
12
12
|
_export_star(require("./utils/orderUtils.js"), exports);
|
|
13
|
+
_export_star(require("./utils/token-id.js"), exports);
|
|
13
14
|
_export_star(require("./shared/index.js"), exports);
|
|
14
15
|
_export_star(require("./api/orderbook-api/index.js"), exports);
|
|
15
16
|
_export_star(require("./api/order-helper.js"), exports);
|
package/dist/cjs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@stryke-xyz/premarket-sdk","version":"1.2.
|
|
1
|
+
{"name":"@stryke-xyz/premarket-sdk","version":"1.2.7","type":"commonjs"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get canonTokenId () {
|
|
13
|
+
return canonTokenId;
|
|
14
|
+
},
|
|
15
|
+
get isErc20TokenId () {
|
|
16
|
+
return isErc20TokenId;
|
|
17
|
+
},
|
|
18
|
+
get isOprmTokenId () {
|
|
19
|
+
return isOprmTokenId;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/i;
|
|
23
|
+
function isErc20TokenId(tokenId) {
|
|
24
|
+
return tokenId === "erc20" || ADDRESS_RE.test(tokenId !== null && tokenId !== void 0 ? tokenId : "");
|
|
25
|
+
}
|
|
26
|
+
function isOprmTokenId(tokenId) {
|
|
27
|
+
if (!tokenId || isErc20TokenId(tokenId)) return false;
|
|
28
|
+
try {
|
|
29
|
+
return (BigInt(tokenId) & 1n) !== 0n;
|
|
30
|
+
} catch (unused) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Collapse oPRM (odd) → PRM (even). ERC20 address tokenIds are returned unchanged. */ function canonTokenId(tokenId) {
|
|
35
|
+
if (!tokenId || isErc20TokenId(tokenId)) return tokenId;
|
|
36
|
+
try {
|
|
37
|
+
return (BigInt(tokenId) & ~1n).toString();
|
|
38
|
+
} catch (unused) {
|
|
39
|
+
return tokenId;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -179,6 +179,9 @@ function submarketToBigInt(submarket) {
|
|
|
179
179
|
tokenId: BigInt(pos.tokenId),
|
|
180
180
|
holding: BigInt(pos.holding),
|
|
181
181
|
totalCost: BigInt(pos.totalCost),
|
|
182
|
+
openCostBasis: BigInt(pos.openCostBasis),
|
|
183
|
+
avgEntryPrice: BigInt(pos.avgEntryPrice),
|
|
184
|
+
costBasisMethod: pos.costBasisMethod,
|
|
182
185
|
totalProceeds: BigInt(pos.totalProceeds),
|
|
183
186
|
realizedPnL: BigInt(pos.realizedPnL),
|
|
184
187
|
updatedAt: BigInt(pos.updatedAt)
|
package/dist/esm/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./constants.js";
|
|
|
6
6
|
export * from "./utils/rand-bigint.js";
|
|
7
7
|
export * from "./utils/mul-div.js";
|
|
8
8
|
export * from "./utils/orderUtils.js";
|
|
9
|
+
export * from "./utils/token-id.js";
|
|
9
10
|
export * from "./shared/index.js";
|
|
10
11
|
export * from "./api/orderbook-api/index.js";
|
|
11
12
|
export * from "./api/order-helper.js";
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@stryke-xyz/premarket-sdk","version":"1.2.
|
|
1
|
+
{"name":"@stryke-xyz/premarket-sdk","version":"1.2.7","type":"module"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/i;
|
|
2
|
+
export function isErc20TokenId(tokenId) {
|
|
3
|
+
return tokenId === "erc20" || ADDRESS_RE.test(tokenId !== null && tokenId !== void 0 ? tokenId : "");
|
|
4
|
+
}
|
|
5
|
+
export function isOprmTokenId(tokenId) {
|
|
6
|
+
if (!tokenId || isErc20TokenId(tokenId)) return false;
|
|
7
|
+
try {
|
|
8
|
+
return (BigInt(tokenId) & 1n) !== 0n;
|
|
9
|
+
} catch (unused) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Collapse oPRM (odd) → PRM (even). ERC20 address tokenIds are returned unchanged. */ export function canonTokenId(tokenId) {
|
|
14
|
+
if (!tokenId || isErc20TokenId(tokenId)) return tokenId;
|
|
15
|
+
try {
|
|
16
|
+
return (BigInt(tokenId) & ~1n).toString();
|
|
17
|
+
} catch (unused) {
|
|
18
|
+
return tokenId;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -123,6 +123,9 @@ export declare function positionToBigInt(pos: UserPosition): {
|
|
|
123
123
|
tokenId: bigint;
|
|
124
124
|
holding: bigint;
|
|
125
125
|
totalCost: bigint;
|
|
126
|
+
openCostBasis: bigint;
|
|
127
|
+
avgEntryPrice: bigint;
|
|
128
|
+
costBasisMethod: "weighted_average";
|
|
126
129
|
totalProceeds: bigint;
|
|
127
130
|
realizedPnL: bigint;
|
|
128
131
|
updatedAt: bigint;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./constants.js";
|
|
|
6
6
|
export * from "./utils/rand-bigint.js";
|
|
7
7
|
export * from "./utils/mul-div.js";
|
|
8
8
|
export * from "./utils/orderUtils.js";
|
|
9
|
+
export * from "./utils/token-id.js";
|
|
9
10
|
export * from "./shared/index.js";
|
|
10
11
|
export * from "./api/orderbook-api/index.js";
|
|
11
12
|
export * from "./api/order-helper.js";
|
|
@@ -234,11 +234,15 @@ export interface MarketsResponse {
|
|
|
234
234
|
total: number;
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
|
+
export type CostBasisMethod = "weighted_average";
|
|
237
238
|
export interface UserPosition {
|
|
238
239
|
id: string;
|
|
239
240
|
tokenId: string;
|
|
240
241
|
holding: string;
|
|
241
242
|
totalCost: string;
|
|
243
|
+
openCostBasis: string;
|
|
244
|
+
avgEntryPrice: string;
|
|
245
|
+
costBasisMethod: CostBasisMethod;
|
|
242
246
|
totalProceeds: string;
|
|
243
247
|
realizedPnL: string;
|
|
244
248
|
/** PnL contribution from limit-order trades */
|
|
@@ -322,6 +326,9 @@ export interface TokenPnL {
|
|
|
322
326
|
position: {
|
|
323
327
|
holding: string;
|
|
324
328
|
totalCost: string;
|
|
329
|
+
openCostBasis: string;
|
|
330
|
+
avgEntryPrice: string;
|
|
331
|
+
costBasisMethod: CostBasisMethod;
|
|
325
332
|
totalProceeds: string;
|
|
326
333
|
realizedPnL: string;
|
|
327
334
|
} | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isErc20TokenId(tokenId: string | undefined | null): boolean;
|
|
2
|
+
export declare function isOprmTokenId(tokenId: string | undefined | null): boolean;
|
|
3
|
+
/** Collapse oPRM (odd) → PRM (even). ERC20 address tokenIds are returned unchanged. */
|
|
4
|
+
export declare function canonTokenId(tokenId: string): string;
|