@solard/sdk 0.2.27 → 0.2.31

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/src/client.ts CHANGED
@@ -1,285 +1,268 @@
1
- import {
2
- createTraderSolard as createCoreSolard,
3
- type ClaimCreatorRewardsOptions,
4
- type CreatorRewardClaimResult,
5
- type CumulativeDistributionExecuteOptions,
6
- type CumulativeDistributionInput,
7
- type CumulativeDistributionPlan,
8
- type CumulativeDistributionState,
9
- type HumanAmount,
10
- type MarketHistory,
11
- type MarketHistoryOptions,
12
- type MarketPrice,
13
- type MergedReplayEventStream,
14
- type ReplayEventSubscription,
15
- type ReplayHistory,
16
- type ReplayItem,
17
- type ReplayOptions,
18
- type ReplayEventsOptions,
19
- type RecordConfirmedTradeInput,
20
- type SendReceipt,
21
- type SenderId,
22
- type SolardDecodedTransaction,
23
- type SolardTransactionOptions,
24
- type SolardPosition,
25
- type SolardPositionQuery,
26
- type SolardTrade,
27
- type SolardTradeQuery,
28
- type TokenHolderSnapshot,
29
- type TokenHolderSnapshotOptions,
30
- type TokenRef,
31
- type WalletRef,
32
- type WalletPrivateKeyExport,
33
- type WalletPrivateKeyFormat,
34
- } from "@solard/core";
35
-
36
- export type SolardOptions = {
1
+ import {
2
+ createTraderSolard as createCoreSolard,
3
+ type ClaimCreatorRewardsOptions,
4
+ type CreatorRewardClaimResult,
5
+ type CumulativeDistributionExecuteOptions,
6
+ type CumulativeDistributionInput,
7
+ type CumulativeDistributionPlan,
8
+ type CumulativeDistributionState,
9
+ type HumanAmount,
10
+ type MarketHistory,
11
+ type MarketHistoryOptions,
12
+ type MarketPrice,
13
+ type MergedReplayEventStream,
14
+ type ReplayEventSubscription,
15
+ type ReplayHistory,
16
+ type ReplayItem,
17
+ type ReplayOptions,
18
+ type ReplayEventsOptions,
19
+ type RecordConfirmedTradeInput,
20
+ type SendReceipt,
21
+ type TradeLandingPolicy,
22
+ type TradeResult,
23
+ type TradeExecutionOptions,
24
+ type LivePoolReserves,
25
+ type SenderId,
26
+ type SolardDecodedTransaction,
27
+ type SolardTransactionOptions,
28
+ type SolardPosition,
29
+ type SolardPositionQuery,
30
+ type SolardTrade,
31
+ type SolardTradeQuery,
32
+ type TokenHolderSnapshot,
33
+ type TokenHolderSnapshotOptions,
34
+ type TokenRef,
35
+ type WalletRef,
36
+ type WalletPrivateKeyExport,
37
+ type WalletPrivateKeyFormat,
38
+ } from "@solard/core";
39
+
40
+ export type SolardOptions = {
37
41
  rpcUrl?: string;
38
- dbPath?: string;
39
- cacheTtlMs?: number;
40
- };
41
-
42
- export type SolardHistoryApi = {
43
- replay(token: TokenRef, options?: ReplayOptions): Promise<ReplayHistory>;
44
- market(
45
- token: TokenRef,
46
- options?: MarketHistoryOptions,
47
- ): Promise<MarketHistory>;
48
- merge(
49
- histories: readonly (ReplayHistory | Iterable<ReplayItem>)[],
50
- ): ReplayItem[];
51
- };
52
-
53
- export type SolardEventsApi = {
54
- (
55
- token: TokenRef,
56
- options?: ReplayEventsOptions,
57
- ): Promise<ReplayEventSubscription>;
58
- merge(streams: readonly ReplayEventSubscription[]): MergedReplayEventStream;
59
- };
60
-
42
+ rpcUrls?: readonly string[];
43
+ dbPath?: string;
44
+ cacheTtlMs?: number;
45
+ };
46
+
47
+ export type SolardHistoryApi = {
48
+ replay(token: TokenRef, options?: ReplayOptions): Promise<ReplayHistory>;
49
+ market(
50
+ token: TokenRef,
51
+ options?: MarketHistoryOptions,
52
+ ): Promise<MarketHistory>;
53
+ merge(
54
+ histories: readonly (ReplayHistory | Iterable<ReplayItem>)[],
55
+ ): ReplayItem[];
56
+ };
57
+
58
+ export type SolardEventsApi = {
59
+ (
60
+ token: TokenRef,
61
+ options?: ReplayEventsOptions,
62
+ ): Promise<ReplayEventSubscription>;
63
+ merge(streams: readonly ReplayEventSubscription[]): MergedReplayEventStream;
64
+ };
65
+
61
66
  export type SolardBuyInput = {
62
- wallet: WalletRef;
63
- token: TokenRef;
64
- amount: HumanAmount | string | number;
65
- slippageBps?: number;
66
- };
67
-
67
+ reserves?: LivePoolReserves;
68
+ maxPriceSol?: string | number;
69
+ wallet: WalletRef;
70
+ token: TokenRef;
71
+ amount: HumanAmount | string | number;
72
+ slippageBps?: number;
73
+ minOutputRaw?: bigint | string;
74
+ };
75
+
68
76
  export type SolardSellInput = {
69
- wallet: WalletRef;
70
- token: TokenRef;
71
- amount?: "all" | { bps: number };
72
- slippageBps?: number;
73
- };
74
-
75
- export type SolardTradeExecutionOptions = {
76
- waitForConfirmation?: boolean;
77
- via?: SenderId;
78
- skipSimulation?: boolean;
79
- skipPreflight?: boolean;
80
- };
81
-
82
- export type SolardTradeExecutionResult = {
83
- executionId: number;
84
- signature: string;
85
- sender: string;
86
- status: SendReceipt["status"];
87
- slot: number | null;
88
- error: string | null;
89
- feeLamports?: number;
90
- computeUnitsConsumed?: number;
91
- };
92
-
77
+ closeTokenAccount?: boolean;
78
+ reserves?: LivePoolReserves;
79
+ minPriceSol?: string | number;
80
+ wallet: WalletRef;
81
+ token: TokenRef;
82
+ amount?: "all" | { bps: number };
83
+ slippageBps?: number;
84
+ minOutputLamports?: bigint | string;
85
+ };
86
+
87
+ export type SolardTradeExecutionOptions = TradeExecutionOptions;
88
+
89
+ export type SolardTradeExecutionResult = TradeResult;
93
90
  export type Solard = {
94
- close(): void;
95
- history: SolardHistoryApi;
96
- events: SolardEventsApi;
97
- claims: {
98
- creatorFees: {
99
- claim(
100
- token: TokenRef,
101
- wallet: WalletRef,
102
- options?: ClaimCreatorRewardsOptions,
103
- ): Promise<CreatorRewardClaimResult>;
104
- status(
105
- id: string,
106
- ): ReturnType<
107
- ReturnType<typeof createCoreSolard>["claims"]["creatorFees"]["status"]
108
- >;
109
- };
110
- };
111
- distributions: {
112
- plan(
113
- options: CumulativeDistributionInput,
114
- ): Promise<CumulativeDistributionPlan>;
115
- execute(
116
- options: CumulativeDistributionExecuteOptions,
117
- ): Promise<CumulativeDistributionState>;
118
- status(id: string): CumulativeDistributionState | null;
119
- };
120
- createWallet: ReturnType<typeof createCoreSolard>["createWallet"];
121
- createVanityWallet: ReturnType<typeof createCoreSolard>["createVanityWallet"];
122
- importWallet: ReturnType<typeof createCoreSolard>["importWallet"];
123
- listWallets: ReturnType<typeof createCoreSolard>["listWallets"];
124
- walletAddress(wallet: WalletRef): string;
125
- exportPrivateKey(
126
- wallet: WalletRef,
127
- format?: WalletPrivateKeyFormat,
128
- ): WalletPrivateKeyExport;
129
- addToken: ReturnType<typeof createCoreSolard>["addToken"];
130
- resolveToken: ReturnType<typeof createCoreSolard>["resolveToken"];
131
- tokenAccounts: ReturnType<typeof createCoreSolard>["tokenAccounts"];
132
- snapshotHolders(
133
- token: TokenRef,
134
- options?: Omit<TokenHolderSnapshotOptions, "token">,
135
- ): Promise<TokenHolderSnapshot>;
136
- walletBalances: ReturnType<typeof createCoreSolard>["walletBalances"];
137
- recordConfirmedTrade(input: RecordConfirmedTradeInput): Promise<SolardTrade>;
138
- trades(options?: SolardTradeQuery): Promise<SolardTrade[]>;
139
- position(options: SolardPositionQuery): Promise<SolardPosition>;
140
- getTransaction(
141
- signature: string,
142
- options?: SolardTransactionOptions,
143
- ): Promise<SolardDecodedTransaction | null>;
144
- samplePrice(token: TokenRef): Promise<MarketPrice>;
145
- buy(
146
- input: SolardBuyInput,
147
- options?: SolardTradeExecutionOptions,
148
- ): Promise<SolardTradeExecutionResult>;
149
- sell(
150
- input: SolardSellInput,
151
- options?: SolardTradeExecutionOptions,
152
- ): Promise<SolardTradeExecutionResult>;
153
- };
154
-
155
- function tradeAmount(value: HumanAmount | string | number): HumanAmount {
156
- return typeof value === "string" || typeof value === "number"
157
- ? { sol: value }
158
- : value;
159
- }
160
-
161
- function sellBps(value: SolardSellInput["amount"]): number {
162
- if (value == null || value === "all") return 10_000;
163
- const bps = Math.trunc(value.bps);
164
- if (!(bps > 0 && bps <= 10_000))
165
- throw new Error("sell amount.bps must be between 1 and 10000");
166
- return bps;
167
- }
168
-
169
- function pumpSwap6040(error: unknown): boolean {
170
- const message = error instanceof Error ? error.message : String(error);
171
- return (
172
- message.includes("Simulation failed") &&
173
- (message.includes("BuySlippageBelowMinBaseAmountOut") ||
174
- message.includes("Error Number: 6040") ||
175
- /["']?Custom["']?\s*[:=]\s*6040/.test(message))
176
- );
177
- }
178
-
179
- async function executeTrade(
180
- core: ReturnType<typeof createCoreSolard>,
181
- side: "buy" | "sell",
182
- input: SolardBuyInput | SolardSellInput,
183
- options: SolardTradeExecutionOptions = {},
184
- ): Promise<SolardTradeExecutionResult> {
185
- const via = options.via ?? "rpc";
186
- const buildAndSubmit = async () => {
187
- const composer = core.tx(input.wallet);
188
- if (side === "buy") {
189
- const buy = input as SolardBuyInput;
190
- composer.buy(buy.token, tradeAmount(buy.amount), {
191
- slippageBps: buy.slippageBps,
192
- });
193
- } else {
194
- const sell = input as SolardSellInput;
195
- composer.sell(sell.token, {
196
- bps: sellBps(sell.amount),
197
- slippageBps: sell.slippageBps,
198
- });
199
- }
200
- const plan = await composer.build();
201
- return await core.submitPlan(plan, via, side, {
202
- skipSimulation: options.skipSimulation,
203
- skipPreflight: options.skipPreflight,
204
- });
205
- };
206
- let submission;
207
- try {
208
- submission = await buildAndSubmit();
209
- } catch (error) {
210
- if (side !== "buy" || options.skipSimulation || !pumpSwap6040(error))
211
- throw error;
212
- submission = await buildAndSubmit();
213
- }
214
- if (options.waitForConfirmation === false) {
215
- return {
216
- executionId: submission.executionId,
217
- signature: submission.signature,
218
- sender: submission.sender,
219
- status: "submitted",
220
- slot: null,
221
- error: null,
222
- };
223
- }
224
- const receipt = await core.settleSubmission(submission);
225
- return {
226
- executionId: submission.executionId,
227
- signature: receipt.signature,
228
- sender: receipt.sender,
229
- status: receipt.status,
230
- slot: receipt.slot,
231
- error: receipt.error ?? null,
232
- feeLamports: receipt.feeLamports,
233
- computeUnitsConsumed: receipt.computeUnitsConsumed,
234
- };
235
- }
236
-
237
- export function createSolard(options: SolardOptions = {}): Solard {
238
- const core = createCoreSolard(options);
239
- const history: SolardHistoryApi = Object.freeze({
240
- replay: (token, replayOptions) => core.history.replay(token, replayOptions),
241
- market: (token, marketOptions) => core.history.market(token, marketOptions),
242
- merge: core.history.merge,
243
- });
244
- const events = Object.assign(
245
- (token: TokenRef, eventOptions: ReplayEventsOptions = {}) =>
246
- core.events(token, eventOptions),
247
- { merge: core.events.merge },
248
- ) as SolardEventsApi;
91
+ resolveCurrentMarket: ReturnType<typeof createCoreSolard>["resolveCurrentMarket"];
92
+ getClaimableCreatorFees: ReturnType<typeof createCoreSolard>["getClaimableCreatorFees"];
93
+ claimAllCreatorFees: ReturnType<typeof createCoreSolard>["claimAllCreatorFees"];
94
+ walletLedger: ReturnType<typeof createCoreSolard>["walletLedger"];
95
+ historicalTape: ReturnType<typeof createCoreSolard>["historicalTape"];
96
+ getSupportedPumpPairs: ReturnType<typeof createCoreSolard>["getSupportedPumpPairs"];
97
+ listVanityMints: ReturnType<typeof createCoreSolard>["listVanityMints"];
98
+ releaseVanityMint: ReturnType<typeof createCoreSolard>["releaseVanityMint"];
99
+ closeEmptyTokenAccounts: ReturnType<typeof createCoreSolard>["closeEmptyTokenAccounts"];
100
+ prepareTokenDeployment: ReturnType<typeof createCoreSolard>["prepareTokenDeployment"];
101
+ deployToken: ReturnType<typeof createCoreSolard>["deployToken"];
102
+ warmBlockhash: ReturnType<typeof createCoreSolard>["warmBlockhash"];
103
+ curveLiquidity: ReturnType<typeof createCoreSolard>["curveLiquidity"];
104
+ maxSendableSol: ReturnType<typeof createCoreSolard>["maxSendableSol"];
105
+ transferToken: ReturnType<typeof createCoreSolard>["transferToken"];
106
+ exitWallet: ReturnType<typeof createCoreSolard>["exitWallet"];
107
+ resumeTrade(intentKey: string): Promise<SolardTradeExecutionResult>;
108
+ reconcile(intentKey: string): Promise<SolardTradeExecutionResult>;
109
+ quote: ReturnType<typeof createCoreSolard>["quote"];
110
+ close(): void;
111
+ history: SolardHistoryApi;
112
+ events: SolardEventsApi;
113
+ claims: {
114
+ creatorFees: {
115
+ claim(
116
+ token: TokenRef,
117
+ wallet: WalletRef,
118
+ options?: ClaimCreatorRewardsOptions,
119
+ ): Promise<CreatorRewardClaimResult>;
120
+ status(
121
+ id: string,
122
+ ): ReturnType<
123
+ ReturnType<typeof createCoreSolard>["claims"]["creatorFees"]["status"]
124
+ >;
125
+ };
126
+ };
127
+ distributions: {
128
+ plan(
129
+ options: CumulativeDistributionInput,
130
+ ): Promise<CumulativeDistributionPlan>;
131
+ execute(
132
+ options: CumulativeDistributionExecuteOptions,
133
+ ): Promise<CumulativeDistributionState>;
134
+ status(id: string): CumulativeDistributionState | null;
135
+ };
136
+ createWallet: ReturnType<typeof createCoreSolard>["createWallet"];
137
+ createVanityWallet: ReturnType<typeof createCoreSolard>["createVanityWallet"];
138
+ importWallet: ReturnType<typeof createCoreSolard>["importWallet"];
139
+ listWallets: ReturnType<typeof createCoreSolard>["listWallets"];
140
+ walletAddress(wallet: WalletRef): string;
141
+ exportPrivateKey(
142
+ wallet: WalletRef,
143
+ format?: WalletPrivateKeyFormat,
144
+ ): WalletPrivateKeyExport;
145
+ addToken: ReturnType<typeof createCoreSolard>["addToken"];
146
+ resolveToken: ReturnType<typeof createCoreSolard>["resolveToken"];
147
+ tokenAccounts: ReturnType<typeof createCoreSolard>["tokenAccounts"];
148
+ snapshotHolders(
149
+ token: TokenRef,
150
+ options?: Omit<TokenHolderSnapshotOptions, "token">,
151
+ ): Promise<TokenHolderSnapshot>;
152
+ walletBalances: ReturnType<typeof createCoreSolard>["walletBalances"];
153
+ recordConfirmedTrade(input: RecordConfirmedTradeInput): Promise<SolardTrade>;
154
+ trades(options?: SolardTradeQuery): Promise<SolardTrade[]>;
155
+ position(options: SolardPositionQuery): Promise<SolardPosition>;
156
+ getTransaction(
157
+ signature: string,
158
+ options?: SolardTransactionOptions,
159
+ ): Promise<SolardDecodedTransaction | null>;
160
+ samplePrice(token: TokenRef): Promise<MarketPrice>;
161
+ buy(
162
+ input: SolardBuyInput,
163
+ options?: SolardTradeExecutionOptions,
164
+ ): Promise<SolardTradeExecutionResult>;
165
+ sell(
166
+ input: SolardSellInput,
167
+ options?: SolardTradeExecutionOptions,
168
+ ): Promise<SolardTradeExecutionResult>;
169
+ };
170
+
171
+ function tradeAmount(value: HumanAmount | string | number): HumanAmount {
172
+ return typeof value === "string" || typeof value === "number"
173
+ ? { sol: value }
174
+ : value;
175
+ }
176
+
177
+ function sellBps(value: SolardSellInput["amount"]): number {
178
+ if (value == null || value === "all") return 10_000;
179
+ const bps = Math.trunc(value.bps);
180
+ if (!(bps > 0 && bps <= 10_000))
181
+ throw new Error("sell amount.bps must be between 1 and 10000");
182
+ return bps;
183
+ }
184
+
185
+
186
+ async function executeTrade(
187
+ core: ReturnType<typeof createCoreSolard>,
188
+ side: "buy" | "sell",
189
+ input: SolardBuyInput | SolardSellInput,
190
+ options: SolardTradeExecutionOptions = {},
191
+ ): Promise<SolardTradeExecutionResult> {
192
+ if (side === "buy") {
193
+ const buy = input as SolardBuyInput;
194
+ return await core.buy(buy.token, buy.wallet, tradeAmount(buy.amount), { ...options, slippageBps: buy.slippageBps, minOutputRaw: buy.minOutputRaw, maxPriceSol: buy.maxPriceSol, reserves: buy.reserves });
195
+ }
196
+ const sell = input as SolardSellInput;
197
+ return await core.sell(sell.token, sell.wallet, { ...options, bps: sellBps(sell.amount), slippageBps: sell.slippageBps, minOutputLamports: sell.minOutputLamports, minPriceSol: sell.minPriceSol, reserves: sell.reserves, closeTokenAccount: sell.closeTokenAccount });
198
+
199
+ }
200
+
201
+ export function createSolard(options: SolardOptions = {}): Solard {
202
+ const core = createCoreSolard(options);
203
+ const history: SolardHistoryApi = Object.freeze({
204
+ replay: (token, replayOptions) => core.history.replay(token, replayOptions),
205
+ market: (token, marketOptions) => core.history.market(token, marketOptions),
206
+ merge: core.history.merge,
207
+ });
208
+ const events = Object.assign(
209
+ (token: TokenRef, eventOptions: ReplayEventsOptions = {}) =>
210
+ core.events(token, eventOptions),
211
+ { merge: core.events.merge },
212
+ ) as SolardEventsApi;
249
213
  return Object.freeze({
250
- close: core.close.bind(core),
251
- history,
252
- events: Object.freeze(events),
253
- claims: Object.freeze({
254
- creatorFees: Object.freeze({
255
- claim: core.claims.creatorFees.claim,
256
- status: core.claims.creatorFees.status,
257
- }),
258
- }),
259
- distributions: Object.freeze({
260
- plan: core.distributions.plan,
261
- execute: core.distributions.execute,
262
- status: core.distributions.status,
263
- }),
264
- createWallet: core.createWallet.bind(core),
265
- createVanityWallet: core.createVanityWallet.bind(core),
266
- importWallet: core.importWallet.bind(core),
267
- listWallets: core.listWallets.bind(core),
268
- walletAddress: core.walletAddress.bind(core),
269
- exportPrivateKey: core.exportWalletPrivateKey.bind(core),
270
- addToken: core.addToken.bind(core),
271
- resolveToken: core.resolveToken.bind(core),
272
- tokenAccounts: core.tokenAccounts.bind(core),
273
- snapshotHolders: core.snapshotHolders.bind(core),
274
- walletBalances: core.walletBalances.bind(core),
275
- recordConfirmedTrade: core.recordConfirmedTrade.bind(core),
276
- trades: core.trades.bind(core),
277
- position: core.position.bind(core),
278
- getTransaction: core.getTransaction.bind(core),
279
- samplePrice: core.samplePrice.bind(core),
280
- buy: (input, executionOptions) =>
281
- executeTrade(core, "buy", input, executionOptions),
282
- sell: (input, executionOptions) =>
283
- executeTrade(core, "sell", input, executionOptions),
284
- });
285
- }
214
+ resolveCurrentMarket: core.resolveCurrentMarket.bind(core),
215
+ getClaimableCreatorFees: core.getClaimableCreatorFees.bind(core),
216
+ claimAllCreatorFees: core.claimAllCreatorFees.bind(core),
217
+ walletLedger: core.walletLedger.bind(core),
218
+ historicalTape: core.historicalTape.bind(core),
219
+ getSupportedPumpPairs: core.getSupportedPumpPairs.bind(core),
220
+ listVanityMints: core.listVanityMints.bind(core),
221
+ releaseVanityMint: core.releaseVanityMint.bind(core),
222
+ closeEmptyTokenAccounts: core.closeEmptyTokenAccounts.bind(core),
223
+ prepareTokenDeployment: core.prepareTokenDeployment.bind(core),
224
+ deployToken: core.deployToken.bind(core),
225
+ warmBlockhash: core.warmBlockhash.bind(core),
226
+ curveLiquidity: core.curveLiquidity.bind(core),
227
+ maxSendableSol: core.maxSendableSol.bind(core),
228
+ transferToken: core.transferToken.bind(core),
229
+ exitWallet: core.exitWallet.bind(core),
230
+ resumeTrade: core.resumeTrade.bind(core),
231
+ reconcile: core.reconcile.bind(core),
232
+ quote: core.quote.bind(core),
233
+ close: core.close.bind(core),
234
+ history,
235
+ events: Object.freeze(events),
236
+ claims: Object.freeze({
237
+ creatorFees: Object.freeze({
238
+ claim: core.claims.creatorFees.claim,
239
+ status: core.claims.creatorFees.status,
240
+ }),
241
+ }),
242
+ distributions: Object.freeze({
243
+ plan: core.distributions.plan,
244
+ execute: core.distributions.execute,
245
+ status: core.distributions.status,
246
+ }),
247
+ createWallet: core.createWallet.bind(core),
248
+ createVanityWallet: core.createVanityWallet.bind(core),
249
+ importWallet: core.importWallet.bind(core),
250
+ listWallets: core.listWallets.bind(core),
251
+ walletAddress: core.walletAddress.bind(core),
252
+ exportPrivateKey: core.exportWalletPrivateKey.bind(core),
253
+ addToken: core.addToken.bind(core),
254
+ resolveToken: core.resolveToken.bind(core),
255
+ tokenAccounts: core.tokenAccounts.bind(core),
256
+ snapshotHolders: core.snapshotHolders.bind(core),
257
+ walletBalances: core.walletBalances.bind(core),
258
+ recordConfirmedTrade: core.recordConfirmedTrade.bind(core),
259
+ trades: core.trades.bind(core),
260
+ position: core.position.bind(core),
261
+ getTransaction: core.getTransaction.bind(core),
262
+ samplePrice: core.samplePrice.bind(core),
263
+ buy: (input, executionOptions) =>
264
+ executeTrade(core, "buy", input, executionOptions),
265
+ sell: (input, executionOptions) =>
266
+ executeTrade(core, "sell", input, executionOptions),
267
+ });
268
+ }
package/src/default.ts CHANGED
@@ -1,51 +1,51 @@
1
- import { getSolUsdPrice } from "@solard/core";
2
- import {
3
- listenTrades,
4
- subscribeLaunches,
5
- subscribeMigrations,
6
- } from "./live.ts";
7
- import { createSolard, type Solard } from "./client.ts";
8
-
9
- type DefaultSolard = Solard & {
10
- getSolUsdPrice: typeof getSolUsdPrice;
11
- listenTrades: typeof listenTrades;
12
- subscribeLaunches: typeof subscribeLaunches;
13
- subscribeMigrations: typeof subscribeMigrations;
14
- };
15
-
16
- let instance: Solard | undefined;
17
-
18
- function client(): Solard {
19
- instance ??= createSolard();
20
- return instance;
21
- }
22
-
23
- const operations = {
24
- getSolUsdPrice,
25
- listenTrades,
26
- subscribeLaunches,
27
- subscribeMigrations,
28
- } as const;
29
-
30
- const slrd = new Proxy({} as DefaultSolard, {
31
- get(_target, key) {
32
- if (key === "close") {
33
- return () => {
34
- const current = instance;
35
- instance = undefined;
36
- current?.close();
37
- };
38
- }
39
- if (typeof key === "string" && key in operations) {
40
- return operations[key as keyof typeof operations];
41
- }
42
- const current = client();
43
- const value = Reflect.get(current as object, key, current);
44
- return typeof value === "function" ? value.bind(current) : value;
45
- },
46
- set() {
47
- return false;
48
- },
49
- });
50
-
51
- export default slrd;
1
+ import { getSolUsdPrice } from "@solard/core";
2
+ import {
3
+ listenTrades,
4
+ subscribeLaunches,
5
+ subscribeMigrations,
6
+ } from "./live.ts";
7
+ import { createSolard, type Solard } from "./client.ts";
8
+
9
+ type DefaultSolard = Solard & {
10
+ getSolUsdPrice: typeof getSolUsdPrice;
11
+ listenTrades: typeof listenTrades;
12
+ subscribeLaunches: typeof subscribeLaunches;
13
+ subscribeMigrations: typeof subscribeMigrations;
14
+ };
15
+
16
+ let instance: Solard | undefined;
17
+
18
+ function client(): Solard {
19
+ instance ??= createSolard();
20
+ return instance;
21
+ }
22
+
23
+ const operations = {
24
+ getSolUsdPrice,
25
+ listenTrades,
26
+ subscribeLaunches,
27
+ subscribeMigrations,
28
+ } as const;
29
+
30
+ const slrd = new Proxy({} as DefaultSolard, {
31
+ get(_target, key) {
32
+ if (key === "close") {
33
+ return () => {
34
+ const current = instance;
35
+ instance = undefined;
36
+ current?.close();
37
+ };
38
+ }
39
+ if (typeof key === "string" && key in operations) {
40
+ return operations[key as keyof typeof operations];
41
+ }
42
+ const current = client();
43
+ const value = Reflect.get(current as object, key, current);
44
+ return typeof value === "function" ? value.bind(current) : value;
45
+ },
46
+ set() {
47
+ return false;
48
+ },
49
+ });
50
+
51
+ export default slrd;