@lasersell/lasersell-sdk 0.1.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/LICENSE +21 -0
- package/README.md +114 -0
- package/dist/exitApi.d.ts +87 -0
- package/dist/exitApi.js +238 -0
- package/dist/exitApi.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/retry.d.ts +15 -0
- package/dist/retry.js +74 -0
- package/dist/retry.js.map +1 -0
- package/dist/stream/client.d.ts +144 -0
- package/dist/stream/client.js +995 -0
- package/dist/stream/client.js.map +1 -0
- package/dist/stream/index.d.ts +3 -0
- package/dist/stream/index.js +4 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/proto.d.ts +148 -0
- package/dist/stream/proto.js +266 -0
- package/dist/stream/proto.js.map +1 -0
- package/dist/stream/session.d.ts +64 -0
- package/dist/stream/session.js +243 -0
- package/dist/stream/session.js.map +1 -0
- package/dist/tx.d.ts +85 -0
- package/dist/tx.js +408 -0
- package/dist/tx.js.map +1 -0
- package/package.json +87 -0
- package/src/exitApi.ts +385 -0
- package/src/index.ts +5 -0
- package/src/retry.ts +102 -0
- package/src/stream/client.ts +1362 -0
- package/src/stream/index.ts +3 -0
- package/src/stream/proto.ts +565 -0
- package/src/stream/session.ts +372 -0
- package/src/tx.ts +617 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { strategyConfigFromOptional, validateStrategyAndDeadline, } from "./client.js";
|
|
2
|
+
export class StreamSession {
|
|
3
|
+
connection;
|
|
4
|
+
positionsById = new Map();
|
|
5
|
+
strategy;
|
|
6
|
+
deadlineTimeoutSec;
|
|
7
|
+
deadlineTimers = new Map();
|
|
8
|
+
openedAtMs = new Map();
|
|
9
|
+
constructor(connection, strategy, deadlineTimeoutSec) {
|
|
10
|
+
this.connection = connection;
|
|
11
|
+
this.strategy = { ...strategy };
|
|
12
|
+
this.deadlineTimeoutSec = Math.max(0, deadlineTimeoutSec);
|
|
13
|
+
}
|
|
14
|
+
static async connect(client, configure) {
|
|
15
|
+
const connection = await client.connect(configure);
|
|
16
|
+
return StreamSession.fromConnection(connection, configure.strategy, configure.deadline_timeout_sec ?? 0);
|
|
17
|
+
}
|
|
18
|
+
static fromConnection(connection, strategy = defaultStrategy(), deadlineTimeoutSec = 0) {
|
|
19
|
+
return new StreamSession(connection, strategy, deadlineTimeoutSec);
|
|
20
|
+
}
|
|
21
|
+
sender() {
|
|
22
|
+
return this.connection.sender();
|
|
23
|
+
}
|
|
24
|
+
positions() {
|
|
25
|
+
return [...this.positionsById.values()].map((position) => ({ ...position }));
|
|
26
|
+
}
|
|
27
|
+
positionsForWalletMint(wallet, mint) {
|
|
28
|
+
return this.positions()
|
|
29
|
+
.filter((position) => position.wallet_pubkey === wallet && position.mint === mint)
|
|
30
|
+
.map((position) => ({ ...position }));
|
|
31
|
+
}
|
|
32
|
+
close(handle) {
|
|
33
|
+
if (handle !== undefined) {
|
|
34
|
+
this.sender().closePosition(positionHandleToSelector(handle));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.cancelAllDeadlines();
|
|
38
|
+
this.connection.close();
|
|
39
|
+
}
|
|
40
|
+
requestExitSignal(handle, slippage_bps) {
|
|
41
|
+
this.sender().requestExitSignal(positionHandleToSelector(handle), slippage_bps);
|
|
42
|
+
}
|
|
43
|
+
updateStrategy(strategy, deadlineTimeoutSec = this.deadlineTimeoutSec) {
|
|
44
|
+
validateStrategyAndDeadline(strategy, deadlineTimeoutSec);
|
|
45
|
+
this.strategy = { ...strategy };
|
|
46
|
+
this.deadlineTimeoutSec = Math.max(0, deadlineTimeoutSec);
|
|
47
|
+
this.rescheduleAllDeadlines();
|
|
48
|
+
this.sender().updateStrategy({ ...strategy });
|
|
49
|
+
}
|
|
50
|
+
updateStrategyOptional(strategy = {}, deadlineTimeoutSec = this.deadlineTimeoutSec) {
|
|
51
|
+
this.updateStrategy(strategyConfigFromOptional(strategy), deadlineTimeoutSec);
|
|
52
|
+
}
|
|
53
|
+
async recv() {
|
|
54
|
+
const message = await this.connection.recv();
|
|
55
|
+
if (message === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return this.applyMessage(message);
|
|
59
|
+
}
|
|
60
|
+
applyMessage(message) {
|
|
61
|
+
switch (message.type) {
|
|
62
|
+
case "position_opened": {
|
|
63
|
+
const handle = {
|
|
64
|
+
position_id: message.position_id,
|
|
65
|
+
token_account: message.token_account,
|
|
66
|
+
wallet_pubkey: message.wallet_pubkey,
|
|
67
|
+
mint: message.mint,
|
|
68
|
+
token_program: message.token_program,
|
|
69
|
+
tokens: message.tokens,
|
|
70
|
+
entry_quote_units: message.entry_quote_units,
|
|
71
|
+
};
|
|
72
|
+
this.positionsById.set(message.position_id, handle);
|
|
73
|
+
this.armDeadline(handle.token_account);
|
|
74
|
+
return {
|
|
75
|
+
type: "position_opened",
|
|
76
|
+
handle: { ...handle },
|
|
77
|
+
message,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
case "position_closed": {
|
|
81
|
+
const handle = this.removePosition(message.position_id, message.token_account);
|
|
82
|
+
const tokenAccount = handle?.token_account ?? message.token_account;
|
|
83
|
+
if (tokenAccount !== undefined) {
|
|
84
|
+
this.cancelDeadlineFor(tokenAccount);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
type: "position_closed",
|
|
88
|
+
handle: handle === undefined ? undefined : { ...handle },
|
|
89
|
+
message,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
case "exit_signal_with_tx": {
|
|
93
|
+
const handle = this.findPosition(message.position_id, message.token_account);
|
|
94
|
+
return {
|
|
95
|
+
type: "exit_signal_with_tx",
|
|
96
|
+
handle: handle === undefined ? undefined : { ...handle },
|
|
97
|
+
message,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case "pnl_update": {
|
|
101
|
+
const handle = this.findPosition(message.position_id);
|
|
102
|
+
return {
|
|
103
|
+
type: "pnl_update",
|
|
104
|
+
handle: handle === undefined ? undefined : { ...handle },
|
|
105
|
+
message,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
default: {
|
|
109
|
+
return {
|
|
110
|
+
type: "message",
|
|
111
|
+
message,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
findPosition(positionId, tokenAccount) {
|
|
117
|
+
const byId = this.positionsById.get(positionId);
|
|
118
|
+
if (byId !== undefined) {
|
|
119
|
+
return byId;
|
|
120
|
+
}
|
|
121
|
+
if (tokenAccount === undefined) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
for (const handle of this.positionsById.values()) {
|
|
125
|
+
if (handle.token_account === tokenAccount) {
|
|
126
|
+
return handle;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
removePosition(positionId, tokenAccount) {
|
|
132
|
+
const byId = this.positionsById.get(positionId);
|
|
133
|
+
if (byId !== undefined) {
|
|
134
|
+
this.positionsById.delete(positionId);
|
|
135
|
+
return byId;
|
|
136
|
+
}
|
|
137
|
+
if (tokenAccount === undefined) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
for (const [id, handle] of this.positionsById.entries()) {
|
|
141
|
+
if (handle.token_account === tokenAccount) {
|
|
142
|
+
this.positionsById.delete(id);
|
|
143
|
+
return handle;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
deadlineMs() {
|
|
149
|
+
const raw = this.deadlineTimeoutSec;
|
|
150
|
+
const sec = Number.isFinite(raw) ? Math.max(0, raw) : 0;
|
|
151
|
+
return sec * 1_000;
|
|
152
|
+
}
|
|
153
|
+
armDeadline(tokenAccount) {
|
|
154
|
+
this.cancelDeadlineTimer(tokenAccount);
|
|
155
|
+
const deadlineMs = this.deadlineMs();
|
|
156
|
+
const openedAt = Date.now();
|
|
157
|
+
this.openedAtMs.set(tokenAccount, openedAt);
|
|
158
|
+
if (deadlineMs === 0) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.scheduleDeadline(tokenAccount, deadlineMs);
|
|
162
|
+
}
|
|
163
|
+
rescheduleAllDeadlines() {
|
|
164
|
+
this.cancelAllDeadlineTimers();
|
|
165
|
+
const deadlineMs = this.deadlineMs();
|
|
166
|
+
if (deadlineMs === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
const tokenAccounts = new Set([...this.positionsById.values()].map((position) => position.token_account));
|
|
171
|
+
for (const tokenAccount of tokenAccounts) {
|
|
172
|
+
const openedAt = this.openedAtMs.get(tokenAccount) ?? now;
|
|
173
|
+
this.openedAtMs.set(tokenAccount, openedAt);
|
|
174
|
+
const remaining = openedAt + deadlineMs - now;
|
|
175
|
+
if (remaining <= 0) {
|
|
176
|
+
queueMicrotask(() => {
|
|
177
|
+
this.tryRequestExitSignal(tokenAccount);
|
|
178
|
+
});
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
this.scheduleDeadline(tokenAccount, remaining);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
scheduleDeadline(tokenAccount, delayMs) {
|
|
185
|
+
const timer = setTimeout(() => {
|
|
186
|
+
this.deadlineTimers.delete(tokenAccount);
|
|
187
|
+
this.tryRequestExitSignal(tokenAccount);
|
|
188
|
+
}, Math.max(0, delayMs));
|
|
189
|
+
this.deadlineTimers.set(tokenAccount, timer);
|
|
190
|
+
}
|
|
191
|
+
tryRequestExitSignal(tokenAccount) {
|
|
192
|
+
if (!this.hasOpenPositionForTokenAccount(tokenAccount)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
this.sender().requestExitSignal(tokenAccount);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// Ignore timer callback failures to avoid crashing caller loops.
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
hasOpenPositionForTokenAccount(tokenAccount) {
|
|
203
|
+
for (const handle of this.positionsById.values()) {
|
|
204
|
+
if (handle.token_account === tokenAccount) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
cancelDeadlineFor(tokenAccount) {
|
|
211
|
+
this.cancelDeadlineTimer(tokenAccount);
|
|
212
|
+
this.openedAtMs.delete(tokenAccount);
|
|
213
|
+
}
|
|
214
|
+
cancelDeadlineTimer(tokenAccount) {
|
|
215
|
+
const timer = this.deadlineTimers.get(tokenAccount);
|
|
216
|
+
if (timer !== undefined) {
|
|
217
|
+
clearTimeout(timer);
|
|
218
|
+
this.deadlineTimers.delete(tokenAccount);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
cancelAllDeadlineTimers() {
|
|
222
|
+
for (const timer of this.deadlineTimers.values()) {
|
|
223
|
+
clearTimeout(timer);
|
|
224
|
+
}
|
|
225
|
+
this.deadlineTimers.clear();
|
|
226
|
+
}
|
|
227
|
+
cancelAllDeadlines() {
|
|
228
|
+
this.cancelAllDeadlineTimers();
|
|
229
|
+
this.openedAtMs.clear();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function positionHandleToSelector(handle) {
|
|
233
|
+
return {
|
|
234
|
+
token_account: handle.token_account,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function defaultStrategy() {
|
|
238
|
+
return {
|
|
239
|
+
target_profit_pct: 0,
|
|
240
|
+
stop_loss_pct: 0,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/stream/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,aA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AC,CAAC;YACpB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAEO,uBAAuB;QAC7B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YACjD,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAED,SAAS,wBAAwB,CAAC,MAAsB;IACtD,OAAO;QACL,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe;IACtB,OAAO;QACL,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,CAAC;KACjB,CAAC;AACJ,CAAC"}
|
package/dist/tx.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { VersionedTransaction, type Signer } from "@solana/web3.js";
|
|
2
|
+
export declare const HELIUS_SENDER_BASE_URL = "https://sender.helius-rpc.com";
|
|
3
|
+
export declare const HELIUS_SENDER_FAST_URL = "https://sender.helius-rpc.com/fast";
|
|
4
|
+
export declare const HELIUS_SENDER_PING_URL = "https://sender.helius-rpc.com/ping";
|
|
5
|
+
/** Default Astralane Iris region (Frankfurt). */
|
|
6
|
+
export declare const ASTRALANE_DEFAULT_REGION = "fr";
|
|
7
|
+
/**
|
|
8
|
+
* Builds the Astralane Iris endpoint URL for a given region.
|
|
9
|
+
*
|
|
10
|
+
* Known regions: `fr` (Frankfurt, recommended), `fr2`, `la` (San Francisco),
|
|
11
|
+
* `jp` (Tokyo), `ny` (New York), `ams` (Amsterdam, recommended), `ams2`,
|
|
12
|
+
* `lim` (Limburg), `sg` (Singapore), `lit` (Lithuania).
|
|
13
|
+
*/
|
|
14
|
+
export declare function astralaneIrisUrl(region: string): string;
|
|
15
|
+
/** Unified send target that selects the transaction submission endpoint. */
|
|
16
|
+
export type SendTarget = {
|
|
17
|
+
kind: "rpc";
|
|
18
|
+
url: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "helius_sender";
|
|
21
|
+
} | {
|
|
22
|
+
kind: "astralane";
|
|
23
|
+
apiKey: string;
|
|
24
|
+
region?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Creates an RPC send target. */
|
|
27
|
+
export declare function sendTargetRpc(url: string): SendTarget;
|
|
28
|
+
/** Creates a Helius Sender send target. */
|
|
29
|
+
export declare function sendTargetHeliusSender(): SendTarget;
|
|
30
|
+
/** Creates an Astralane Iris send target. */
|
|
31
|
+
export declare function sendTargetAstralane(apiKey: string, region?: string): SendTarget;
|
|
32
|
+
/** Submits a signed transaction via the specified send target. */
|
|
33
|
+
export declare function sendTransaction(target: SendTarget, tx: VersionedTransaction, options?: SendTransactionOptions): Promise<string>;
|
|
34
|
+
/** Submits a signed base64-encoded transaction via the specified send target. */
|
|
35
|
+
export declare function sendTransactionB64To(target: SendTarget, txB64: string, options?: SendTransactionOptions): Promise<string>;
|
|
36
|
+
/** Signs an unsigned base64 transaction and sends via the specified send target. */
|
|
37
|
+
export declare function signAndSendUnsignedTxB64(target: SendTarget, unsignedTxB64: string, signer: Signer, options?: SendTransactionOptions): Promise<string>;
|
|
38
|
+
export type TxSubmitErrorKind = "decode_unsigned_tx" | "deserialize_unsigned_tx" | "sign_tx" | "serialize_tx" | "request_send" | "response_read" | "http_status" | "decode_response" | "rpc_error" | "missing_result";
|
|
39
|
+
export declare class TxSubmitError extends Error {
|
|
40
|
+
readonly kind: TxSubmitErrorKind;
|
|
41
|
+
readonly target?: string;
|
|
42
|
+
readonly status?: number;
|
|
43
|
+
readonly body?: string;
|
|
44
|
+
private constructor();
|
|
45
|
+
static decodeUnsignedTx(cause: unknown): TxSubmitError;
|
|
46
|
+
static deserializeUnsignedTx(cause: unknown): TxSubmitError;
|
|
47
|
+
static signTx(cause: unknown): TxSubmitError;
|
|
48
|
+
static serializeTx(cause: unknown): TxSubmitError;
|
|
49
|
+
static requestSend(target: string, cause: unknown): TxSubmitError;
|
|
50
|
+
static responseRead(target: string, cause: unknown): TxSubmitError;
|
|
51
|
+
static httpStatus(target: string, status: number, body: string): TxSubmitError;
|
|
52
|
+
static decodeResponse(target: string, body: string, cause: unknown): TxSubmitError;
|
|
53
|
+
static rpcError(target: string, error: string): TxSubmitError;
|
|
54
|
+
static missingResult(target: string, response: string): TxSubmitError;
|
|
55
|
+
}
|
|
56
|
+
export declare function signUnsignedTx(unsignedTxB64: string, signer: Signer): VersionedTransaction;
|
|
57
|
+
/**
|
|
58
|
+
* Fast-path signer for LaserSell-provided unsigned transactions.
|
|
59
|
+
*
|
|
60
|
+
* Unlike `signUnsignedTx` (which deserializes into a `VersionedTransaction`), this method:
|
|
61
|
+
* 1) base64-decodes the transaction
|
|
62
|
+
* 2) signs the raw message bytes
|
|
63
|
+
* 3) patches the signature bytes in-place
|
|
64
|
+
* 4) re-encodes to base64
|
|
65
|
+
*
|
|
66
|
+
* This avoids `VersionedTransaction.deserialize()` and `tx.serialize()` on the hot path.
|
|
67
|
+
*/
|
|
68
|
+
export declare function signUnsignedTxB64Fast(unsignedTxB64: string, signer: Signer): string;
|
|
69
|
+
export declare function encodeSignedTx(tx: VersionedTransaction): string;
|
|
70
|
+
export interface SendTransactionOptions {
|
|
71
|
+
fetch_impl?: FetchLike;
|
|
72
|
+
}
|
|
73
|
+
export declare function pingHeliusSender(options?: {
|
|
74
|
+
baseUrl?: string;
|
|
75
|
+
fetch_impl?: FetchLike;
|
|
76
|
+
}): Promise<boolean>;
|
|
77
|
+
export declare function startHeliusSenderWarmLoop(options?: {
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
intervalMs?: number;
|
|
80
|
+
fetch_impl?: FetchLike;
|
|
81
|
+
}): {
|
|
82
|
+
stop: () => void;
|
|
83
|
+
};
|
|
84
|
+
type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
85
|
+
export {};
|