Skip to content

Commit fd9c483

Browse files
committed
Merge branch 'master' into lukas/per-market-lev-swift-plus-more
2 parents 68ee193 + 3ff1240 commit fd9c483

File tree

9 files changed

+369
-15
lines changed

9 files changed

+369
-15
lines changed

sdk/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.139.0-beta.1
1+
2.139.0-beta.7

sdk/bun.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@triton-one/yellowstone-grpc": "1.3.0",
2121
"anchor-bankrun": "0.3.0",
2222
"gill": "^0.10.2",
23+
"helius-laserstream": "0.1.8",
2324
"nanoid": "3.3.4",
2425
"node-cache": "5.1.2",
2526
"rpc-websockets": "7.5.1",
@@ -335,6 +336,8 @@
335336

336337
"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-G3EfaZS+iOGYWLLRCEAXdWK9my08oHNZ+FHluRiggIYJPOXzhOiDgpVCUHaUvyIC5/fj7C/p637jdzC666AOKQ=="],
337338

339+
"@types/protobufjs": ["@types/[email protected]", "", { "dependencies": { "protobufjs": "*" } }, "sha512-A27RDExpAf3rdDjIrHKiJK6x8kqqJ4CmoChwtipfhVAn1p7+wviQFFP7dppn8FslSbHtQeVPvi8wNKkDjSYjHw=="],
340+
338341
"@types/semver": ["@types/[email protected]", "", {}, "sha512-k107IF4+Xr7UHjwDc7Cfd6PRQfbdkiRabXGRjo07b4WyPahFBZCZ1sE+BNxYIJPPg73UkfOsVOLwqVc/6ETrIA=="],
339342

340343
"@types/stack-utils": ["@types/[email protected]", "", {}, "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw=="],
@@ -711,6 +714,20 @@
711714

712715
"he": ["[email protected]", "", { "bin": { "he": "bin/he" } }, "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="],
713716

717+
"helius-laserstream": ["[email protected]", "", { "dependencies": { "@types/protobufjs": "^6.0.0", "protobufjs": "^7.5.3" }, "optionalDependencies": { "helius-laserstream-darwin-arm64": "0.1.8", "helius-laserstream-darwin-x64": "0.1.8", "helius-laserstream-linux-arm64-gnu": "0.1.8", "helius-laserstream-linux-arm64-musl": "0.1.8", "helius-laserstream-linux-x64-gnu": "0.1.8", "helius-laserstream-linux-x64-musl": "0.1.8" }, "os": [ "linux", "darwin", ], "cpu": [ "x64", "arm64", ] }, "sha512-jXQkwQRWiowbVPGQrGacOkI5shKPhrEixCu93OpoMtL5fs9mnhtD7XKMPi8CX0W8gsqsJjwR4NlaR+EflyANbQ=="],
718+
719+
"helius-laserstream-darwin-arm64": ["[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-p/K2Mi3wZnMxEYSLCvu858VyMvtJFonhdF8cLaMcszFv04WWdsK+hINNZpVRfakypvDfDPbMudEhL1Q9USD5+w=="],
720+
721+
"helius-laserstream-darwin-x64": ["[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-Hd5irFyfOqQZLdoj5a+OV7vML2YfySSBuKlOwtisMHkUuIXZ4NpAexslDmK7iP5VWRI+lOv9X/tA7BhxW7RGSQ=="],
722+
723+
"helius-laserstream-linux-arm64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-PlPm1dvOvTGBL1nuzK98Xe40BJq1JWNREXlBHKDVA/B+KCGQnIMJ1s6e1MevSvFE7SOix5i1BxhYIxGioK2GMg=="],
724+
725+
"helius-laserstream-linux-arm64-musl": ["[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-LFadfMRuTd1zo6RZqLTgHQapo3gJYioS7wFMWFoBOFulG0BpAqHEDNobkxx0002QArw+zX29MQ/5OaOCf8kKTA=="],
726+
727+
"helius-laserstream-linux-x64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-IZWK/OQIe0647QqfYikLb1DFK+nYtXLJiMcpj24qnNVWBOtMXmPc1hL6ebazdEiaKt7fxNd5IiM1RqeaqZAZMw=="],
728+
729+
"helius-laserstream-linux-x64-musl": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-riTS6VgxDae1fHOJ2XC/o/v1OZRbEv/3rcoa3NlAOnooDKp5HDgD0zJTcImjQHpYWwGaejx1oX/Ht53lxNoijw=="],
730+
714731
"humanize-ms": ["[email protected]", "", { "dependencies": { "ms": "^2.0.0" } }, "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ=="],
715732

716733
"iconv-lite": ["[email protected]", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw=="],
@@ -1195,6 +1212,8 @@
11951212

11961213
"@switchboard-xyz/on-demand/bs58": ["[email protected]", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="],
11971214

1215+
"@types/protobufjs/protobufjs": ["[email protected]", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="],
1216+
11981217
"@typescript-eslint/project-service/@typescript-eslint/types": ["@typescript-eslint/[email protected]", "", {}, "sha512-wzkUfX3plUqij4YwWaJyqhiPE5UCRVlFpKn1oCRn2O1bJ592XxWJj8ROQ3JD5MYXLORW84063z3tZTb/cs4Tyw=="],
11991218

12001219
"@typescript-eslint/typescript-estree/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg=="],
@@ -1221,6 +1240,8 @@
12211240

12221241
"glob/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g=="],
12231242

1243+
"helius-laserstream/protobufjs": ["[email protected]", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="],
1244+
12241245
"jayson/@types/node": ["@types/[email protected]", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="],
12251246

12261247
"jayson/commander": ["[email protected]", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="],

sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@drift-labs/sdk",
3-
"version": "2.139.0-beta.1",
3+
"version": "2.139.0-beta.7",
44
"main": "lib/node/index.js",
55
"types": "lib/node/index.d.ts",
66
"browser": "./lib/browser/index.js",
@@ -55,6 +55,7 @@
5555
"@triton-one/yellowstone-grpc": "1.3.0",
5656
"anchor-bankrun": "0.3.0",
5757
"gill": "^0.10.2",
58+
"helius-laserstream": "0.1.8",
5859
"nanoid": "3.3.4",
5960
"node-cache": "5.1.2",
6061
"rpc-websockets": "7.5.1",
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
import { GrpcConfigs, ResubOpts } from './types';
2+
import { Program } from '@coral-xyz/anchor';
3+
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
4+
import * as Buffer from 'buffer';
5+
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
6+
7+
import {
8+
LaserCommitmentLevel,
9+
LaserSubscribe,
10+
LaserstreamConfig,
11+
LaserSubscribeRequest,
12+
LaserSubscribeUpdate,
13+
CompressionAlgorithms,
14+
CommitmentLevel,
15+
} from '../isomorphic/grpc';
16+
17+
type LaserCommitment =
18+
(typeof LaserCommitmentLevel)[keyof typeof LaserCommitmentLevel];
19+
20+
export class LaserstreamProgramAccountSubscriber<
21+
T,
22+
> extends WebSocketProgramAccountSubscriber<T> {
23+
private stream:
24+
| {
25+
id: string;
26+
cancel: () => void;
27+
write?: (req: LaserSubscribeRequest) => Promise<void>;
28+
}
29+
| undefined;
30+
31+
private commitmentLevel: CommitmentLevel;
32+
public listenerId?: number;
33+
34+
private readonly laserConfig: LaserstreamConfig;
35+
36+
private constructor(
37+
laserConfig: LaserstreamConfig,
38+
commitmentLevel: CommitmentLevel,
39+
subscriptionName: string,
40+
accountDiscriminator: string,
41+
program: Program,
42+
decodeBufferFn: (accountName: string, ix: Buffer) => T,
43+
options: { filters: MemcmpFilter[] } = { filters: [] },
44+
resubOpts?: ResubOpts
45+
) {
46+
super(
47+
subscriptionName,
48+
accountDiscriminator,
49+
program,
50+
decodeBufferFn,
51+
options,
52+
resubOpts
53+
);
54+
this.laserConfig = laserConfig;
55+
this.commitmentLevel = this.toLaserCommitment(commitmentLevel);
56+
}
57+
58+
public static async create<U>(
59+
grpcConfigs: GrpcConfigs,
60+
subscriptionName: string,
61+
accountDiscriminator: string,
62+
program: Program,
63+
decodeBufferFn: (accountName: string, ix: Buffer) => U,
64+
options: { filters: MemcmpFilter[] } = {
65+
filters: [],
66+
},
67+
resubOpts?: ResubOpts
68+
): Promise<LaserstreamProgramAccountSubscriber<U>> {
69+
const laserConfig: LaserstreamConfig = {
70+
apiKey: grpcConfigs.token,
71+
endpoint: grpcConfigs.endpoint,
72+
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
73+
channelOptions: {
74+
'grpc.default_compression_algorithm': CompressionAlgorithms.zstd,
75+
'grpc.max_receive_message_length': 1_000_000_000,
76+
},
77+
};
78+
79+
const commitmentLevel =
80+
grpcConfigs.commitmentLevel ?? CommitmentLevel.CONFIRMED;
81+
82+
return new LaserstreamProgramAccountSubscriber<U>(
83+
laserConfig,
84+
commitmentLevel,
85+
subscriptionName,
86+
accountDiscriminator,
87+
program,
88+
decodeBufferFn,
89+
options,
90+
resubOpts
91+
);
92+
}
93+
94+
async subscribe(
95+
onChange: (
96+
accountId: PublicKey,
97+
data: T,
98+
context: Context,
99+
buffer: Buffer
100+
) => void
101+
): Promise<void> {
102+
if (this.listenerId != null || this.isUnsubscribing) return;
103+
104+
this.onChange = onChange;
105+
106+
const filters = this.options.filters.map((filter) => {
107+
return {
108+
memcmp: {
109+
offset: filter.memcmp.offset,
110+
base58: filter.memcmp.bytes,
111+
},
112+
};
113+
});
114+
115+
const request: LaserSubscribeRequest = {
116+
slots: {},
117+
accounts: {
118+
drift: {
119+
account: [],
120+
owner: [this.program.programId.toBase58()],
121+
filters,
122+
},
123+
},
124+
transactions: {},
125+
blocks: {},
126+
blocksMeta: {},
127+
accountsDataSlice: [],
128+
commitment: this.commitmentLevel,
129+
entry: {},
130+
transactionsStatus: {},
131+
};
132+
133+
try {
134+
const stream = await LaserSubscribe(
135+
this.laserConfig,
136+
request,
137+
async (update: LaserSubscribeUpdate) => {
138+
if (update.account) {
139+
const slot = Number(update.account.slot);
140+
const acc = update.account.account;
141+
142+
const accountInfo = {
143+
owner: new PublicKey(acc.owner),
144+
lamports: Number(acc.lamports),
145+
data: Buffer.Buffer.from(acc.data),
146+
executable: acc.executable,
147+
rentEpoch: Number(acc.rentEpoch),
148+
};
149+
150+
const payload = {
151+
accountId: new PublicKey(acc.pubkey),
152+
accountInfo,
153+
};
154+
155+
if (this.resubOpts?.resubTimeoutMs) {
156+
this.receivingData = true;
157+
clearTimeout(this.timeoutId);
158+
this.handleRpcResponse({ slot }, payload);
159+
this.setTimeout();
160+
} else {
161+
this.handleRpcResponse({ slot }, payload);
162+
}
163+
}
164+
},
165+
async (error) => {
166+
console.error('LaserStream client error:', error);
167+
throw error;
168+
}
169+
);
170+
171+
this.stream = stream;
172+
this.listenerId = 1;
173+
174+
if (this.resubOpts?.resubTimeoutMs) {
175+
this.receivingData = true;
176+
this.setTimeout();
177+
}
178+
} catch (err) {
179+
console.error('Failed to start LaserStream client:', err);
180+
throw err;
181+
}
182+
}
183+
184+
public async unsubscribe(onResub = false): Promise<void> {
185+
if (!onResub && this.resubOpts) {
186+
this.resubOpts.resubTimeoutMs = undefined;
187+
}
188+
this.isUnsubscribing = true;
189+
clearTimeout(this.timeoutId);
190+
this.timeoutId = undefined;
191+
192+
if (this.listenerId != null && this.stream) {
193+
try {
194+
this.stream.cancel();
195+
} finally {
196+
this.listenerId = undefined;
197+
this.isUnsubscribing = false;
198+
}
199+
} else {
200+
this.isUnsubscribing = false;
201+
}
202+
}
203+
204+
public toLaserCommitment(
205+
level: string | number | undefined
206+
): LaserCommitment {
207+
if (typeof level === 'string') {
208+
return (
209+
(LaserCommitmentLevel as any)[level.toUpperCase()] ??
210+
LaserCommitmentLevel.CONFIRMED
211+
);
212+
}
213+
return (level as LaserCommitment) ?? LaserCommitmentLevel.CONFIRMED;
214+
}
215+
}

sdk/src/accounts/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export type GrpcConfigs = {
234234
* Defaults to false, will throw on connection loss.
235235
*/
236236
enableReconnect?: boolean;
237+
client?: 'yellowstone' | 'laser';
237238
};
238239

239240
export interface HighLeverageModeConfigAccountSubscriber {

sdk/src/constants/perpMarkets.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,19 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
13121312
oracleSource: OracleSource.PYTH_LAZER,
13131313
pythLazerId: 1578,
13141314
},
1315+
{
1316+
fullName: 'ASTER',
1317+
category: ['DEX'],
1318+
symbol: 'ASTER-PERP',
1319+
baseAssetSymbol: 'ASTER',
1320+
marketIndex: 76,
1321+
oracle: new PublicKey('E4tyjB3os4jVczLVQ258uxLdcwjuqmhcsPquVWgrpah4'),
1322+
launchTs: 1758632629000,
1323+
oracleSource: OracleSource.PYTH_LAZER,
1324+
pythFeedId:
1325+
'0xa903b5a82cb572397e3d47595d2889cf80513f5b4cf7a36b513ae10cc8b1e338',
1326+
pythLazerId: 2310,
1327+
},
13151328
];
13161329

13171330
export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {

sdk/src/isomorphic/grpc.node.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@ import type Client from '@triton-one/yellowstone-grpc';
22
import type {
33
SubscribeRequest,
44
SubscribeUpdate,
5-
CommitmentLevel,
65
} from '@triton-one/yellowstone-grpc';
6+
import { CommitmentLevel } from '@triton-one/yellowstone-grpc';
77
import { ClientDuplexStream, ChannelOptions } from '@grpc/grpc-js';
88

9+
import {
10+
CommitmentLevel as LaserCommitmentLevel,
11+
subscribe as LaserSubscribe,
12+
LaserstreamConfig,
13+
SubscribeRequest as LaserSubscribeRequest,
14+
SubscribeUpdate as LaserSubscribeUpdate,
15+
CompressionAlgorithms,
16+
} from 'helius-laserstream';
17+
918
export {
1019
ClientDuplexStream,
1120
ChannelOptions,
1221
SubscribeRequest,
1322
SubscribeUpdate,
1423
CommitmentLevel,
1524
Client,
25+
LaserSubscribe,
26+
LaserCommitmentLevel,
27+
LaserstreamConfig,
28+
LaserSubscribeRequest,
29+
LaserSubscribeUpdate,
30+
CompressionAlgorithms,
1631
};
1732

1833
// Export a function to create a new Client instance

0 commit comments

Comments
 (0)