@solard/sdk 0.2.16 → 0.2.19
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/package.json +2 -2
- package/src/browser/client.ts +46 -27
- package/src/browser/index.ts +12 -12
- package/src/browser/pump.ts +6 -6
- package/src/browser/types.ts +9 -6
- package/src/client.ts +141 -0
- package/src/export-surface.test.ts +101 -0
- package/src/index.ts +47 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solard/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.19",
|
|
4
4
|
"description": "Public Solard SDK for wallets, transactions, trading and token launches.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@solana/web3.js": "^1.98.4",
|
|
25
|
-
"@solard/core": "0.2.
|
|
25
|
+
"@solard/core": "0.2.19"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser.json",
|
package/src/browser/client.ts
CHANGED
|
@@ -9,28 +9,29 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
buildPumpExternalDeployment,
|
|
11
11
|
type PumpLaunchPairInput,
|
|
12
|
-
} from "@solard/core
|
|
12
|
+
} from "@solard/core";
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
snapshotTokenHolders,
|
|
16
16
|
type TokenHolderSnapshotOptions,
|
|
17
|
-
} from "@solard/core
|
|
18
|
-
import { readMint } from "@solard/core
|
|
17
|
+
} from "@solard/core";
|
|
18
|
+
import { readMint } from "@solard/core";
|
|
19
19
|
import {
|
|
20
20
|
subscribeTokenEvents,
|
|
21
21
|
type SubscribeTokenEventsOptions,
|
|
22
22
|
type TokenEventSubscription,
|
|
23
|
-
} from "@solard/core
|
|
24
|
-
import type { TokenRow } from "@solard/core
|
|
25
|
-
import { PumpCurveVenue } from "@solard/core
|
|
26
|
-
import { PumpSwapVenue } from "@solard/core
|
|
27
|
-
import { VenueRegistry } from "@solard/core
|
|
28
|
-
import { PumpPairService } from "@solard/core
|
|
23
|
+
} from "@solard/core";
|
|
24
|
+
import type { TokenRow } from "@solard/core";
|
|
25
|
+
import { PumpCurveVenue } from "@solard/core";
|
|
26
|
+
import { PumpSwapVenue } from "@solard/core";
|
|
27
|
+
import { VenueRegistry } from "@solard/core";
|
|
28
|
+
import { PumpPairService } from "@solard/core";
|
|
29
29
|
|
|
30
30
|
import { BrowserSolardStore, defaultBrowserStorage } from "./storage.ts";
|
|
31
31
|
import { buildLocalPumpBuy, buildLocalPumpSell } from "./pump.ts";
|
|
32
32
|
import type {
|
|
33
|
-
|
|
33
|
+
BrowserConfirmedTransaction,
|
|
34
|
+
BrowserTransactionSubmission,
|
|
34
35
|
BrowserPortfolio,
|
|
35
36
|
BrowserPumpDeploymentBuild,
|
|
36
37
|
BrowserPumpDeploymentResult,
|
|
@@ -344,14 +345,14 @@ export class BrowserSolard {
|
|
|
344
345
|
};
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
async
|
|
348
|
+
async submitTransaction(
|
|
348
349
|
transaction: VersionedTransaction,
|
|
349
350
|
strategy: {
|
|
350
351
|
blockhash: string;
|
|
351
352
|
lastValidBlockHeight: number;
|
|
352
353
|
skipPreflight?: boolean;
|
|
353
354
|
},
|
|
354
|
-
): Promise<
|
|
355
|
+
): Promise<BrowserTransactionSubmission> {
|
|
355
356
|
const signed = await this.signer().signTransaction(transaction);
|
|
356
357
|
if (!(signed instanceof VersionedTransaction))
|
|
357
358
|
throw new Error("Browser wallet did not return a VersionedTransaction.");
|
|
@@ -363,30 +364,48 @@ export class BrowserSolard {
|
|
|
363
364
|
maxRetries: 0,
|
|
364
365
|
},
|
|
365
366
|
);
|
|
367
|
+
return {
|
|
368
|
+
signature,
|
|
369
|
+
blockhash: strategy.blockhash,
|
|
370
|
+
lastValidBlockHeight: strategy.lastValidBlockHeight,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async confirmSubmission(
|
|
375
|
+
submission: BrowserTransactionSubmission,
|
|
376
|
+
): Promise<BrowserConfirmedTransaction> {
|
|
366
377
|
const confirmation = await this.connection.confirmTransaction(
|
|
367
378
|
{
|
|
368
|
-
signature,
|
|
369
|
-
blockhash:
|
|
370
|
-
lastValidBlockHeight:
|
|
379
|
+
signature: submission.signature,
|
|
380
|
+
blockhash: submission.blockhash,
|
|
381
|
+
lastValidBlockHeight: submission.lastValidBlockHeight,
|
|
371
382
|
},
|
|
372
383
|
"confirmed",
|
|
373
384
|
);
|
|
374
385
|
if (confirmation.value.err)
|
|
375
386
|
throw new Error(
|
|
376
|
-
`Transaction ${signature} failed: ${JSON.stringify(confirmation.value.err)}`,
|
|
387
|
+
`Transaction ${submission.signature} failed: ${JSON.stringify(confirmation.value.err)}`,
|
|
377
388
|
);
|
|
378
|
-
return {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
389
|
+
return { ...submission, status: "confirmed" };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private async submitAndConfirm(
|
|
393
|
+
transaction: VersionedTransaction,
|
|
394
|
+
strategy: {
|
|
395
|
+
blockhash: string;
|
|
396
|
+
lastValidBlockHeight: number;
|
|
397
|
+
skipPreflight?: boolean;
|
|
398
|
+
},
|
|
399
|
+
): Promise<BrowserConfirmedTransaction> {
|
|
400
|
+
return await this.confirmSubmission(
|
|
401
|
+
await this.submitTransaction(transaction, strategy),
|
|
402
|
+
);
|
|
384
403
|
}
|
|
385
404
|
|
|
386
405
|
async sendSol(
|
|
387
406
|
destinationRef: string,
|
|
388
407
|
amountSol: string | number,
|
|
389
|
-
): Promise<
|
|
408
|
+
): Promise<BrowserConfirmedTransaction> {
|
|
390
409
|
const wallet = this.signer();
|
|
391
410
|
const destination = new PublicKey(
|
|
392
411
|
this.store.resolveDestination(destinationRef),
|
|
@@ -406,7 +425,7 @@ export class BrowserSolard {
|
|
|
406
425
|
}),
|
|
407
426
|
],
|
|
408
427
|
}).compileToV0Message();
|
|
409
|
-
return await this.
|
|
428
|
+
return await this.submitAndConfirm(
|
|
410
429
|
new VersionedTransaction(message),
|
|
411
430
|
latest,
|
|
412
431
|
);
|
|
@@ -451,7 +470,7 @@ export class BrowserSolard {
|
|
|
451
470
|
skipPreflight?: boolean;
|
|
452
471
|
}): Promise<BrowserPumpDeploymentResult> {
|
|
453
472
|
const build = await this.buildPumpDeployment(args);
|
|
454
|
-
const receipt = await this.
|
|
473
|
+
const receipt = await this.submitAndConfirm(build.transaction, {
|
|
455
474
|
blockhash: build.blockhash,
|
|
456
475
|
lastValidBlockHeight: build.lastValidBlockHeight,
|
|
457
476
|
skipPreflight: args.skipPreflight,
|
|
@@ -511,7 +530,7 @@ export class BrowserSolard {
|
|
|
511
530
|
skipPreflight?: boolean;
|
|
512
531
|
}): Promise<BrowserTradeResult> {
|
|
513
532
|
const build = await this.buildBuy(args);
|
|
514
|
-
const receipt = await this.
|
|
533
|
+
const receipt = await this.submitAndConfirm(build.transaction, {
|
|
515
534
|
blockhash: build.blockhash,
|
|
516
535
|
lastValidBlockHeight: build.lastValidBlockHeight,
|
|
517
536
|
skipPreflight: args.skipPreflight,
|
|
@@ -536,7 +555,7 @@ export class BrowserSolard {
|
|
|
536
555
|
skipPreflight?: boolean;
|
|
537
556
|
}): Promise<BrowserTradeResult> {
|
|
538
557
|
const build = await this.buildSell(args);
|
|
539
|
-
const receipt = await this.
|
|
558
|
+
const receipt = await this.submitAndConfirm(build.transaction, {
|
|
540
559
|
blockhash: build.blockhash,
|
|
541
560
|
lastValidBlockHeight: build.lastValidBlockHeight,
|
|
542
561
|
skipPreflight: args.skipPreflight,
|
package/src/browser/index.ts
CHANGED
|
@@ -20,40 +20,40 @@ export {
|
|
|
20
20
|
} from "./storage.ts";
|
|
21
21
|
export { BrowserKeyVault, KeypairBrowserSigner } from "./wallet.ts";
|
|
22
22
|
export { buildLocalPumpBuy, buildLocalPumpSell } from "./pump.ts";
|
|
23
|
-
export {
|
|
24
|
-
|
|
25
|
-
PumpPairService,
|
|
26
|
-
} from "@solard/core/launches/pump/pairs.ts";
|
|
27
|
-
export type { PumpSupportedPair } from "@solard/core/launches/pump/pairs.ts";
|
|
23
|
+
export { getSupportedPumpPairs, PumpPairService } from "@solard/core";
|
|
24
|
+
export type { PumpSupportedPair } from "@solard/core";
|
|
28
25
|
export {
|
|
29
26
|
PUMP_USDC_MINT,
|
|
30
27
|
buildPumpExternalDeployment,
|
|
31
28
|
resolvePumpQuoteAsset,
|
|
32
|
-
} from "@solard/core
|
|
29
|
+
} from "@solard/core";
|
|
33
30
|
export type {
|
|
34
31
|
PumpExternalDeploymentBuild,
|
|
35
32
|
PumpCustomPairSelection,
|
|
36
33
|
PumpLaunchPairInput,
|
|
37
|
-
} from "@solard/core
|
|
38
|
-
export { snapshotTokenHolders } from "@solard/core
|
|
34
|
+
} from "@solard/core";
|
|
35
|
+
export { snapshotTokenHolders } from "@solard/core";
|
|
39
36
|
export type {
|
|
40
37
|
TokenHolder,
|
|
41
38
|
ExcludedTokenHolder,
|
|
42
39
|
TokenHolderSnapshot,
|
|
43
40
|
TokenHolderSnapshotOptions,
|
|
44
|
-
} from "@solard/core
|
|
45
|
-
export { subscribeTokenEvents } from "@solard/core
|
|
41
|
+
} from "@solard/core";
|
|
42
|
+
export { subscribeTokenEvents } from "@solard/core";
|
|
46
43
|
export type {
|
|
47
44
|
SolardTokenCreateEvent,
|
|
48
45
|
SolardTokenEvent,
|
|
49
46
|
SolardTokenSwapEvent,
|
|
50
47
|
SolardTokenTransferEvent,
|
|
48
|
+
SolardTokenTransferMovement,
|
|
49
|
+
SolardTokenTransferSource,
|
|
51
50
|
SubscribeTokenEventsOptions,
|
|
52
51
|
TokenEventSubscription,
|
|
53
|
-
} from "@solard/core
|
|
52
|
+
} from "@solard/core";
|
|
54
53
|
|
|
55
54
|
export type {
|
|
56
|
-
|
|
55
|
+
BrowserConfirmedTransaction,
|
|
56
|
+
BrowserTransactionSubmission,
|
|
57
57
|
BrowserContact,
|
|
58
58
|
BrowserPortfolio,
|
|
59
59
|
BrowserPumpDeploymentBuild,
|
package/src/browser/pump.ts
CHANGED
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
type TransactionInstruction,
|
|
8
8
|
} from "@solana/web3.js";
|
|
9
9
|
|
|
10
|
-
import { readMint } from "@solard/core
|
|
11
|
-
import { rawAmount } from "@solard/core
|
|
12
|
-
import type { TokenRow } from "@solard/core
|
|
13
|
-
import { PumpCurveVenue } from "@solard/core
|
|
14
|
-
import { PumpSwapVenue } from "@solard/core
|
|
15
|
-
import { VenueRegistry } from "@solard/core
|
|
10
|
+
import { readMint } from "@solard/core";
|
|
11
|
+
import { rawAmount } from "@solard/core";
|
|
12
|
+
import type { TokenRow } from "@solard/core";
|
|
13
|
+
import { PumpCurveVenue } from "@solard/core";
|
|
14
|
+
import { PumpSwapVenue } from "@solard/core";
|
|
15
|
+
import { VenueRegistry } from "@solard/core";
|
|
16
16
|
|
|
17
17
|
import type { BrowserTradeBuild } from "./types.ts";
|
|
18
18
|
|
package/src/browser/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PumpExternalDeploymentBuild } from "@solard/core";
|
|
1
2
|
import type {
|
|
2
3
|
PublicKey,
|
|
3
4
|
Transaction,
|
|
@@ -55,13 +56,16 @@ export type BrowserPortfolio = {
|
|
|
55
56
|
tokenBalances: BrowserTokenBalance[];
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
export type
|
|
59
|
+
export type BrowserTransactionSubmission = {
|
|
59
60
|
signature: string;
|
|
60
|
-
confirmed: boolean;
|
|
61
61
|
blockhash: string;
|
|
62
62
|
lastValidBlockHeight: number;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
export type BrowserConfirmedTransaction = BrowserTransactionSubmission & {
|
|
66
|
+
status: "confirmed";
|
|
67
|
+
};
|
|
68
|
+
|
|
65
69
|
export type BrowserTradeSide = "buy" | "sell";
|
|
66
70
|
|
|
67
71
|
export type BrowserTradeBuild = {
|
|
@@ -79,7 +83,7 @@ export type BrowserTradeBuild = {
|
|
|
79
83
|
serializedSize: number;
|
|
80
84
|
};
|
|
81
85
|
|
|
82
|
-
export type BrowserTradeResult =
|
|
86
|
+
export type BrowserTradeResult = BrowserConfirmedTransaction & {
|
|
83
87
|
side: BrowserTradeSide;
|
|
84
88
|
venue: string;
|
|
85
89
|
mint: string;
|
|
@@ -97,10 +101,9 @@ export type BrowserSolardOptions = {
|
|
|
97
101
|
rpcMaxRps?: number;
|
|
98
102
|
fetch?: typeof globalThis.fetch;
|
|
99
103
|
};
|
|
100
|
-
export type BrowserPumpDeploymentBuild =
|
|
101
|
-
import("@solard/core/launches/pump/external-deployment.ts").PumpExternalDeploymentBuild;
|
|
104
|
+
export type BrowserPumpDeploymentBuild = PumpExternalDeploymentBuild;
|
|
102
105
|
|
|
103
|
-
export type BrowserPumpDeploymentResult =
|
|
106
|
+
export type BrowserPumpDeploymentResult = BrowserConfirmedTransaction & {
|
|
104
107
|
mint: string;
|
|
105
108
|
beneficiary: string;
|
|
106
109
|
quoteMint: string;
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
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 TokenHolderSnapshot,
|
|
20
|
+
type TokenHolderSnapshotOptions,
|
|
21
|
+
type TokenRef,
|
|
22
|
+
type WalletRef,
|
|
23
|
+
} from "@solard/core";
|
|
24
|
+
|
|
25
|
+
export type SolardOptions = {
|
|
26
|
+
rpcUrl?: string;
|
|
27
|
+
dbPath?: string;
|
|
28
|
+
cacheTtlMs?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type SolardHistoryApi = {
|
|
32
|
+
replay(token: TokenRef, options?: ReplayOptions): Promise<ReplayHistory>;
|
|
33
|
+
market(
|
|
34
|
+
token: TokenRef,
|
|
35
|
+
options?: MarketHistoryOptions,
|
|
36
|
+
): Promise<MarketHistory>;
|
|
37
|
+
merge(
|
|
38
|
+
histories: readonly (ReplayHistory | Iterable<ReplayItem>)[],
|
|
39
|
+
): ReplayItem[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type SolardEventsApi = {
|
|
43
|
+
(
|
|
44
|
+
token: TokenRef,
|
|
45
|
+
options?: ReplayEventsOptions,
|
|
46
|
+
): Promise<ReplayEventSubscription>;
|
|
47
|
+
merge(streams: readonly ReplayEventSubscription[]): MergedReplayEventStream;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type Solard = {
|
|
51
|
+
close(): void;
|
|
52
|
+
history: SolardHistoryApi;
|
|
53
|
+
events: SolardEventsApi;
|
|
54
|
+
claims: {
|
|
55
|
+
creatorFees: {
|
|
56
|
+
claim(
|
|
57
|
+
token: TokenRef,
|
|
58
|
+
wallet: WalletRef,
|
|
59
|
+
options?: ClaimCreatorRewardsOptions,
|
|
60
|
+
): Promise<CreatorRewardClaimResult>;
|
|
61
|
+
status(
|
|
62
|
+
id: string,
|
|
63
|
+
): ReturnType<
|
|
64
|
+
ReturnType<typeof createCoreSolard>["claims"]["creatorFees"]["status"]
|
|
65
|
+
>;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
distributions: {
|
|
69
|
+
plan(
|
|
70
|
+
options: CumulativeDistributionInput,
|
|
71
|
+
): Promise<CumulativeDistributionPlan>;
|
|
72
|
+
execute(
|
|
73
|
+
options: CumulativeDistributionExecuteOptions,
|
|
74
|
+
): Promise<CumulativeDistributionState>;
|
|
75
|
+
status(id: string): CumulativeDistributionState | null;
|
|
76
|
+
};
|
|
77
|
+
createWallet: ReturnType<typeof createCoreSolard>["createWallet"];
|
|
78
|
+
createVanityWallet: ReturnType<typeof createCoreSolard>["createVanityWallet"];
|
|
79
|
+
importWallet: ReturnType<typeof createCoreSolard>["importWallet"];
|
|
80
|
+
listWallets: ReturnType<typeof createCoreSolard>["listWallets"];
|
|
81
|
+
addToken: ReturnType<typeof createCoreSolard>["addToken"];
|
|
82
|
+
resolveToken: ReturnType<typeof createCoreSolard>["resolveToken"];
|
|
83
|
+
tokenAccounts: ReturnType<typeof createCoreSolard>["tokenAccounts"];
|
|
84
|
+
snapshotHolders(
|
|
85
|
+
token: TokenRef,
|
|
86
|
+
options?: Omit<TokenHolderSnapshotOptions, "token">,
|
|
87
|
+
): Promise<TokenHolderSnapshot>;
|
|
88
|
+
walletBalances: ReturnType<typeof createCoreSolard>["walletBalances"];
|
|
89
|
+
samplePrice(token: TokenRef): Promise<MarketPrice>;
|
|
90
|
+
buy(
|
|
91
|
+
token: TokenRef,
|
|
92
|
+
wallet: WalletRef,
|
|
93
|
+
amount: HumanAmount,
|
|
94
|
+
options?: Parameters<ReturnType<typeof createCoreSolard>["buy"]>[3],
|
|
95
|
+
): ReturnType<ReturnType<typeof createCoreSolard>["buy"]>;
|
|
96
|
+
sell: ReturnType<typeof createCoreSolard>["sell"];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export function createSolard(options: SolardOptions = {}): Solard {
|
|
100
|
+
const core = createCoreSolard(options);
|
|
101
|
+
const history: SolardHistoryApi = Object.freeze({
|
|
102
|
+
replay: (token, replayOptions) => core.history.replay(token, replayOptions),
|
|
103
|
+
market: (token, marketOptions) => core.history.market(token, marketOptions),
|
|
104
|
+
merge: core.history.merge,
|
|
105
|
+
});
|
|
106
|
+
const events = Object.assign(
|
|
107
|
+
(token: TokenRef, eventOptions: ReplayEventsOptions = {}) =>
|
|
108
|
+
core.events(token, eventOptions),
|
|
109
|
+
{ merge: core.events.merge },
|
|
110
|
+
) as SolardEventsApi;
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
close: core.close.bind(core),
|
|
113
|
+
history,
|
|
114
|
+
events: Object.freeze(events),
|
|
115
|
+
claims: Object.freeze({
|
|
116
|
+
creatorFees: Object.freeze({
|
|
117
|
+
claim: core.claims.creatorFees.claim,
|
|
118
|
+
status: core.claims.creatorFees.status,
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
distributions: Object.freeze({
|
|
122
|
+
plan: core.distributions.plan,
|
|
123
|
+
execute: core.distributions.execute,
|
|
124
|
+
status: core.distributions.status,
|
|
125
|
+
}),
|
|
126
|
+
createWallet: core.createWallet.bind(core),
|
|
127
|
+
createVanityWallet: core.createVanityWallet.bind(core),
|
|
128
|
+
importWallet: core.importWallet.bind(core),
|
|
129
|
+
listWallets: core.listWallets.bind(core),
|
|
130
|
+
addToken: core.addToken.bind(core),
|
|
131
|
+
resolveToken: core.resolveToken.bind(core),
|
|
132
|
+
tokenAccounts: core.tokenAccounts.bind(core),
|
|
133
|
+
snapshotHolders: core.snapshotHolders.bind(core),
|
|
134
|
+
walletBalances: core.walletBalances.bind(core),
|
|
135
|
+
samplePrice: core.samplePrice.bind(core),
|
|
136
|
+
buy: core.buy.bind(core),
|
|
137
|
+
sell: core.sell.bind(core),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const createTraderSolard = createSolard;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const source = readFileSync(join(import.meta.dir, "index.ts"), "utf8");
|
|
6
|
+
const client = readFileSync(join(import.meta.dir, "client.ts"), "utf8");
|
|
7
|
+
|
|
8
|
+
function exportedNames(value: string) {
|
|
9
|
+
const values: string[] = [];
|
|
10
|
+
const types: string[] = [];
|
|
11
|
+
const pattern = /export\s+(type\s+)?\{([\s\S]*?)\}\s+from\s+["'][^"']+["'];/g;
|
|
12
|
+
for (const match of value.matchAll(pattern)) {
|
|
13
|
+
const target = match[1] ? types : values;
|
|
14
|
+
for (const raw of match[2]!.split(",")) {
|
|
15
|
+
const name =
|
|
16
|
+
raw.trim().split(/\s+as\s+/)[1] ?? raw.trim().split(/\s+as\s+/)[0];
|
|
17
|
+
if (name) target.push(name.trim());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
values: [...new Set(values)].sort(),
|
|
22
|
+
types: [...new Set(types)].sort(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("sdk membrane", () => {
|
|
27
|
+
test("has an exact curated root export surface", () => {
|
|
28
|
+
expect(exportedNames(source)).toEqual({
|
|
29
|
+
values: [
|
|
30
|
+
"createSolard",
|
|
31
|
+
"createTraderSolard",
|
|
32
|
+
"formatRaw",
|
|
33
|
+
"sol",
|
|
34
|
+
"tokenAmount",
|
|
35
|
+
].sort(),
|
|
36
|
+
types: [
|
|
37
|
+
"ClaimCreatorRewardsOptions",
|
|
38
|
+
"CreatorRewardClaimPayout",
|
|
39
|
+
"CreatorRewardClaimResult",
|
|
40
|
+
"CumulativeDistributionExecuteOptions",
|
|
41
|
+
"CumulativeDistributionInput",
|
|
42
|
+
"CumulativeDistributionPlan",
|
|
43
|
+
"CumulativeDistributionRecipient",
|
|
44
|
+
"CumulativeDistributionState",
|
|
45
|
+
"CumulativeEntitlement",
|
|
46
|
+
"HumanAmount",
|
|
47
|
+
"MarketHistory",
|
|
48
|
+
"MarketHistoryOptions",
|
|
49
|
+
"MarketPrice",
|
|
50
|
+
"MergedReplayEventStream",
|
|
51
|
+
"QuoteAsset",
|
|
52
|
+
"ReplayCoverage",
|
|
53
|
+
"ReplayEventSubscription",
|
|
54
|
+
"ReplayEventsOptions",
|
|
55
|
+
"ReplayHistory",
|
|
56
|
+
"ReplayItem",
|
|
57
|
+
"ReplayOptions",
|
|
58
|
+
"ReplayPayout",
|
|
59
|
+
"ReplayTransaction",
|
|
60
|
+
"SendReceipt",
|
|
61
|
+
"SenderId",
|
|
62
|
+
"SimulationResult",
|
|
63
|
+
"Solard",
|
|
64
|
+
"SolardCanonicalEvent",
|
|
65
|
+
"SolardClaimAttribution",
|
|
66
|
+
"SolardClaimEvent",
|
|
67
|
+
"SolardEventsApi",
|
|
68
|
+
"SolardHistoryApi",
|
|
69
|
+
"SolardOptions",
|
|
70
|
+
"ExcludedTokenHolder",
|
|
71
|
+
"TokenHolder",
|
|
72
|
+
"TokenHolderSnapshot",
|
|
73
|
+
"TokenHolderSnapshotOptions",
|
|
74
|
+
"TokenEventHistoryProgress",
|
|
75
|
+
"TokenRef",
|
|
76
|
+
"TokenRow",
|
|
77
|
+
"WalletInfo",
|
|
78
|
+
"WalletRef",
|
|
79
|
+
].sort(),
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("does not wildcard-export or deep-import core", () => {
|
|
84
|
+
expect(source).not.toContain('export * from "@solard/core"');
|
|
85
|
+
expect(source).not.toMatch(/\.\.\/\.\.\/core\/src|@solard\/core\//);
|
|
86
|
+
expect(client).not.toMatch(/\.\.\/\.\.\/core\/src|@solard\/core\//);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("does not create persistence at module import", () => {
|
|
90
|
+
expect(source).not.toMatch(/createCoreSolard|createTraderSolard\(\)/);
|
|
91
|
+
expect(client.indexOf("createCoreSolard(options)")).toBeGreaterThan(
|
|
92
|
+
client.indexOf("export function createSolard"),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("does not expose core repositories or secret-bearing handles", () => {
|
|
97
|
+
expect(client).not.toMatch(
|
|
98
|
+
/\b(?:db|wallets|tokens|groups|executions|positions|prices|alts|senders|venues|claimSources|launches|launchpads|connection|signer)\s*:/,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
* Public Solard SDK.
|
|
3
|
-
*
|
|
4
|
-
* All stateful behavior lives in @solard/core so the SDK and CLI share exactly
|
|
5
|
-
* the same wallet store, transaction engine, venues, senders and database.
|
|
6
|
-
*/
|
|
7
|
-
export * from "@solard/core";
|
|
8
|
-
|
|
9
|
-
// Explicit source-level re-export for the generic Jupiter swap helpers.
|
|
10
|
-
// This avoids depending on the @solard/core package barrel resolution when the
|
|
11
|
-
// monorepo CLI is executed directly from source with Bun.
|
|
12
|
-
export {
|
|
13
|
-
executeJupiterSwap,
|
|
14
|
-
quoteJupiterSwap,
|
|
15
|
-
executeJupiterTokenToSol,
|
|
16
|
-
quoteJupiterTokenToSol,
|
|
17
|
-
} from "../../core/src/chain/jupiter-swap.ts";
|
|
1
|
+
export { createSolard, createTraderSolard } from "./client.ts";
|
|
18
2
|
export type {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
Solard,
|
|
4
|
+
SolardEventsApi,
|
|
5
|
+
SolardHistoryApi,
|
|
6
|
+
SolardOptions,
|
|
7
|
+
} from "./client.ts";
|
|
8
|
+
|
|
9
|
+
export { formatRaw, sol, tokenAmount } from "@solard/core";
|
|
23
10
|
|
|
24
|
-
// Direct source re-exports used by the source-executed CLI.
|
|
25
|
-
export { readMint } from "../../core/src/chain/state.ts";
|
|
26
|
-
export { transferTokenIxs } from "../../core/src/tx/spl.ts";
|
|
27
|
-
// Direct source re-exports for the target-weight portfolio controller and
|
|
28
|
-
// backtester. Keeping these explicit lets the source-executed CLI/examples use
|
|
29
|
-
// the new strategy without requiring a root @solard/core barrel replacement.
|
|
30
|
-
export {
|
|
31
|
-
normalizeTargetWeightPolicy,
|
|
32
|
-
planTargetWeightRebalance,
|
|
33
|
-
targetWeightGapPct,
|
|
34
|
-
} from "../../core/src/strategy/target-weight.ts";
|
|
35
|
-
export type {
|
|
36
|
-
TargetWeightCandle,
|
|
37
|
-
TargetWeightGapMode,
|
|
38
|
-
TargetWeightGapPolicy,
|
|
39
|
-
TargetWeightPolicy,
|
|
40
|
-
TargetWeightRebalancePlan,
|
|
41
|
-
} from "../../core/src/strategy/target-weight.ts";
|
|
42
|
-
export { simulateTargetWeightStrategy } from "../../core/src/backtest/target-weight-sim.ts";
|
|
43
11
|
export type {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
12
|
+
ClaimCreatorRewardsOptions,
|
|
13
|
+
CreatorRewardClaimPayout,
|
|
14
|
+
CreatorRewardClaimResult,
|
|
15
|
+
CumulativeDistributionExecuteOptions,
|
|
16
|
+
CumulativeDistributionInput,
|
|
17
|
+
CumulativeDistributionPlan,
|
|
18
|
+
CumulativeDistributionRecipient,
|
|
19
|
+
CumulativeDistributionState,
|
|
20
|
+
CumulativeEntitlement,
|
|
21
|
+
HumanAmount,
|
|
22
|
+
MarketHistory,
|
|
23
|
+
MarketHistoryOptions,
|
|
24
|
+
MarketPrice,
|
|
25
|
+
MergedReplayEventStream,
|
|
26
|
+
QuoteAsset,
|
|
27
|
+
ReplayCoverage,
|
|
28
|
+
ReplayEventSubscription,
|
|
29
|
+
ReplayEventsOptions,
|
|
30
|
+
ReplayHistory,
|
|
31
|
+
ReplayItem,
|
|
32
|
+
ReplayOptions,
|
|
33
|
+
ReplayPayout,
|
|
34
|
+
ReplayTransaction,
|
|
35
|
+
SendReceipt,
|
|
36
|
+
SenderId,
|
|
37
|
+
SimulationResult,
|
|
38
|
+
SolardCanonicalEvent,
|
|
39
|
+
SolardClaimAttribution,
|
|
40
|
+
SolardClaimEvent,
|
|
41
|
+
TokenEventHistoryProgress,
|
|
42
|
+
TokenHolder,
|
|
43
|
+
ExcludedTokenHolder,
|
|
44
|
+
TokenHolderSnapshot,
|
|
45
|
+
TokenHolderSnapshotOptions,
|
|
46
|
+
TokenRef,
|
|
47
|
+
TokenRow,
|
|
48
|
+
WalletInfo,
|
|
49
|
+
WalletRef,
|
|
50
|
+
} from "@solard/core";
|