@solard/sdk 0.2.27 → 0.2.29
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/client.trade-fees.test.ts +60 -0
- package/src/client.ts +270 -276
- package/src/export-surface.test.ts +2 -0
- package/src/index.ts +109 -103
- package/src/live.ts +1 -1
- package/src/operator-api.architecture.test.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solard/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29",
|
|
4
4
|
"description": "Public Solard SDK for wallets, trading, history, live market subscriptions and token metadata.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@solana/web3.js": "^1.98.4",
|
|
30
|
-
"@solard/core": "0.2.
|
|
30
|
+
"@solard/core": "0.2.29"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser.json",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { Keypair } from "@solana/web3.js";
|
|
6
|
+
import { Solard } from "../../core/src/core/solard.ts";
|
|
7
|
+
import { TransactionComposer } from "../../core/src/tx/composer.ts";
|
|
8
|
+
import type { PlannedTransaction, TransactionDraft } from "../../core/src/tx/types.ts";
|
|
9
|
+
import { createSolard } from "./client.ts";
|
|
10
|
+
|
|
11
|
+
test("SDK buy rebuild and sell preserve custom fees in immediate submitted results", async () => {
|
|
12
|
+
const directory = mkdtempSync(join(tmpdir(), "solard-sdk-fees-"));
|
|
13
|
+
const drafts: Array<TransactionDraft> = [];
|
|
14
|
+
// A sentinel plan is never compiled, signed, or broadcast in this test.
|
|
15
|
+
const payer = Keypair.generate();
|
|
16
|
+
const plan = { payer: payer.publicKey } as PlannedTransaction;
|
|
17
|
+
const build = spyOn(TransactionComposer.prototype, "build").mockImplementation(async function (this: TransactionComposer) {
|
|
18
|
+
drafts.push(this.snapshot());
|
|
19
|
+
return { ...plan, draft: this.snapshot() };
|
|
20
|
+
});
|
|
21
|
+
const signer = spyOn(Solard.prototype, "signer").mockImplementation(() => payer);
|
|
22
|
+
const compile = spyOn(Solard.prototype, "compile").mockImplementation(async (_payer, draft) => ({ ...plan, draft }));
|
|
23
|
+
let submissions = 0;
|
|
24
|
+
const submit = spyOn(Solard.prototype, "submitPlan").mockImplementation(async () => {
|
|
25
|
+
submissions += 1;
|
|
26
|
+
if (submissions === 1) {
|
|
27
|
+
throw new Error("Simulation failed: BuySlippageBelowMinBaseAmountOut");
|
|
28
|
+
}
|
|
29
|
+
return { signature: "test-signature", sender: "rpc", executionId: 42, plan };
|
|
30
|
+
});
|
|
31
|
+
const settle = spyOn(Solard.prototype, "settleSubmission").mockImplementation(async () => {
|
|
32
|
+
throw new Error("Immediate submission must not wait for confirmation");
|
|
33
|
+
});
|
|
34
|
+
const sdk = createSolard({ dbPath: join(directory, "test.sqlite") });
|
|
35
|
+
try {
|
|
36
|
+
const options = {
|
|
37
|
+
priorityFee: { cuLimit: 300_000, microLamports: 0 },
|
|
38
|
+
waitForConfirmation: false,
|
|
39
|
+
};
|
|
40
|
+
const buy = await sdk.buy({ token: "token", wallet: "wallet", amount: 0.1 }, options);
|
|
41
|
+
const sell = await sdk.sell({ token: "token", wallet: "wallet" }, options);
|
|
42
|
+
expect(drafts).toHaveLength(3);
|
|
43
|
+
for (const draft of drafts) {
|
|
44
|
+
expect(draft.cuLimit).toBe(300_000);
|
|
45
|
+
expect(draft.cuPriceMicroLamports).toBe(0);
|
|
46
|
+
}
|
|
47
|
+
expect(buy.status).toBe("submitted");
|
|
48
|
+
expect(sell.status).toBe("submitted");
|
|
49
|
+
expect(buy.executionId).toBe(42);
|
|
50
|
+
expect(settle).not.toHaveBeenCalled();
|
|
51
|
+
} finally {
|
|
52
|
+
sdk.close();
|
|
53
|
+
build.mockRestore();
|
|
54
|
+
signer.mockRestore();
|
|
55
|
+
compile.mockRestore();
|
|
56
|
+
submit.mockRestore();
|
|
57
|
+
settle.mockRestore();
|
|
58
|
+
rmSync(directory, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
});
|
package/src/client.ts
CHANGED
|
@@ -1,285 +1,279 @@
|
|
|
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,
|
|
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
20
|
type SendReceipt,
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type
|
|
30
|
-
type
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
21
|
+
type TradeLandingPolicy,
|
|
22
|
+
type SenderId,
|
|
23
|
+
type SolardDecodedTransaction,
|
|
24
|
+
type SolardTransactionOptions,
|
|
25
|
+
type SolardPosition,
|
|
26
|
+
type SolardPositionQuery,
|
|
27
|
+
type SolardTrade,
|
|
28
|
+
type SolardTradeQuery,
|
|
29
|
+
type TokenHolderSnapshot,
|
|
30
|
+
type TokenHolderSnapshotOptions,
|
|
31
|
+
type TokenRef,
|
|
32
|
+
type WalletRef,
|
|
33
|
+
type WalletPrivateKeyExport,
|
|
34
|
+
type WalletPrivateKeyFormat,
|
|
35
|
+
} from "@solard/core";
|
|
36
|
+
|
|
37
|
+
export type SolardOptions = {
|
|
38
|
+
rpcUrl?: string;
|
|
39
|
+
dbPath?: string;
|
|
40
|
+
cacheTtlMs?: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type SolardHistoryApi = {
|
|
44
|
+
replay(token: TokenRef, options?: ReplayOptions): Promise<ReplayHistory>;
|
|
45
|
+
market(
|
|
46
|
+
token: TokenRef,
|
|
47
|
+
options?: MarketHistoryOptions,
|
|
48
|
+
): Promise<MarketHistory>;
|
|
49
|
+
merge(
|
|
50
|
+
histories: readonly (ReplayHistory | Iterable<ReplayItem>)[],
|
|
51
|
+
): ReplayItem[];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type SolardEventsApi = {
|
|
55
|
+
(
|
|
56
|
+
token: TokenRef,
|
|
57
|
+
options?: ReplayEventsOptions,
|
|
58
|
+
): Promise<ReplayEventSubscription>;
|
|
59
|
+
merge(streams: readonly ReplayEventSubscription[]): MergedReplayEventStream;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type SolardBuyInput = {
|
|
63
|
+
wallet: WalletRef;
|
|
64
|
+
token: TokenRef;
|
|
65
|
+
amount: HumanAmount | string | number;
|
|
66
|
+
slippageBps?: number;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type SolardSellInput = {
|
|
70
|
+
wallet: WalletRef;
|
|
71
|
+
token: TokenRef;
|
|
72
|
+
amount?: "all" | { bps: number };
|
|
73
|
+
slippageBps?: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
75
76
|
export type SolardTradeExecutionOptions = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
landing?: TradeLandingPolicy;
|
|
78
|
+
waitForConfirmation?: boolean;
|
|
79
|
+
priorityFee?: { cuLimit?: number; microLamports?: number };
|
|
80
|
+
via?: SenderId;
|
|
81
|
+
skipSimulation?: boolean;
|
|
82
|
+
skipPreflight?: boolean;
|
|
83
|
+
};
|
|
84
|
+
|
|
82
85
|
export type SolardTradeExecutionResult = {
|
|
83
|
-
executionId: number;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
):
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
)
|
|
185
|
-
const via = options.via ?? "rpc";
|
|
186
|
-
const buildAndSubmit = async () => {
|
|
187
|
-
const composer = core.tx(input.wallet);
|
|
86
|
+
attempts?: Array<{ executionId: number; signature: string; priorityMicroLamports: number }>;
|
|
87
|
+
executionId: number;
|
|
88
|
+
signature: string;
|
|
89
|
+
sender: string;
|
|
90
|
+
status: SendReceipt["status"];
|
|
91
|
+
slot: number | null;
|
|
92
|
+
error: string | null;
|
|
93
|
+
feeLamports?: number;
|
|
94
|
+
computeUnitsConsumed?: number;
|
|
95
|
+
/** Signed economic SOL delta excluding network fee and token-account rent. */
|
|
96
|
+
solPrincipalDeltaLamports?: bigint;
|
|
97
|
+
/** Signed target-token delta for the confirmed atomic route. */
|
|
98
|
+
targetTokenDeltaRaw?: bigint;
|
|
99
|
+
/** Confirmed transaction network fee. */
|
|
100
|
+
networkFeeLamports?: bigint;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type Solard = {
|
|
104
|
+
close(): void;
|
|
105
|
+
history: SolardHistoryApi;
|
|
106
|
+
events: SolardEventsApi;
|
|
107
|
+
claims: {
|
|
108
|
+
creatorFees: {
|
|
109
|
+
claim(
|
|
110
|
+
token: TokenRef,
|
|
111
|
+
wallet: WalletRef,
|
|
112
|
+
options?: ClaimCreatorRewardsOptions,
|
|
113
|
+
): Promise<CreatorRewardClaimResult>;
|
|
114
|
+
status(
|
|
115
|
+
id: string,
|
|
116
|
+
): ReturnType<
|
|
117
|
+
ReturnType<typeof createCoreSolard>["claims"]["creatorFees"]["status"]
|
|
118
|
+
>;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
distributions: {
|
|
122
|
+
plan(
|
|
123
|
+
options: CumulativeDistributionInput,
|
|
124
|
+
): Promise<CumulativeDistributionPlan>;
|
|
125
|
+
execute(
|
|
126
|
+
options: CumulativeDistributionExecuteOptions,
|
|
127
|
+
): Promise<CumulativeDistributionState>;
|
|
128
|
+
status(id: string): CumulativeDistributionState | null;
|
|
129
|
+
};
|
|
130
|
+
createWallet: ReturnType<typeof createCoreSolard>["createWallet"];
|
|
131
|
+
createVanityWallet: ReturnType<typeof createCoreSolard>["createVanityWallet"];
|
|
132
|
+
importWallet: ReturnType<typeof createCoreSolard>["importWallet"];
|
|
133
|
+
listWallets: ReturnType<typeof createCoreSolard>["listWallets"];
|
|
134
|
+
walletAddress(wallet: WalletRef): string;
|
|
135
|
+
exportPrivateKey(
|
|
136
|
+
wallet: WalletRef,
|
|
137
|
+
format?: WalletPrivateKeyFormat,
|
|
138
|
+
): WalletPrivateKeyExport;
|
|
139
|
+
addToken: ReturnType<typeof createCoreSolard>["addToken"];
|
|
140
|
+
resolveToken: ReturnType<typeof createCoreSolard>["resolveToken"];
|
|
141
|
+
tokenAccounts: ReturnType<typeof createCoreSolard>["tokenAccounts"];
|
|
142
|
+
snapshotHolders(
|
|
143
|
+
token: TokenRef,
|
|
144
|
+
options?: Omit<TokenHolderSnapshotOptions, "token">,
|
|
145
|
+
): Promise<TokenHolderSnapshot>;
|
|
146
|
+
walletBalances: ReturnType<typeof createCoreSolard>["walletBalances"];
|
|
147
|
+
recordConfirmedTrade(input: RecordConfirmedTradeInput): Promise<SolardTrade>;
|
|
148
|
+
trades(options?: SolardTradeQuery): Promise<SolardTrade[]>;
|
|
149
|
+
position(options: SolardPositionQuery): Promise<SolardPosition>;
|
|
150
|
+
getTransaction(
|
|
151
|
+
signature: string,
|
|
152
|
+
options?: SolardTransactionOptions,
|
|
153
|
+
): Promise<SolardDecodedTransaction | null>;
|
|
154
|
+
samplePrice(token: TokenRef): Promise<MarketPrice>;
|
|
155
|
+
buy(
|
|
156
|
+
input: SolardBuyInput,
|
|
157
|
+
options?: SolardTradeExecutionOptions,
|
|
158
|
+
): Promise<SolardTradeExecutionResult>;
|
|
159
|
+
sell(
|
|
160
|
+
input: SolardSellInput,
|
|
161
|
+
options?: SolardTradeExecutionOptions,
|
|
162
|
+
): Promise<SolardTradeExecutionResult>;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
function tradeAmount(value: HumanAmount | string | number): HumanAmount {
|
|
166
|
+
return typeof value === "string" || typeof value === "number"
|
|
167
|
+
? { sol: value }
|
|
168
|
+
: value;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function sellBps(value: SolardSellInput["amount"]): number {
|
|
172
|
+
if (value == null || value === "all") return 10_000;
|
|
173
|
+
const bps = Math.trunc(value.bps);
|
|
174
|
+
if (!(bps > 0 && bps <= 10_000))
|
|
175
|
+
throw new Error("sell amount.bps must be between 1 and 10000");
|
|
176
|
+
return bps;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
async function executeTrade(
|
|
181
|
+
core: ReturnType<typeof createCoreSolard>,
|
|
182
|
+
side: "buy" | "sell",
|
|
183
|
+
input: SolardBuyInput | SolardSellInput,
|
|
184
|
+
options: SolardTradeExecutionOptions = {},
|
|
185
|
+
): Promise<SolardTradeExecutionResult> {
|
|
186
|
+
const { submission, receipt, attempts } = await core.executeTradePlan(input.wallet, async () => {
|
|
187
|
+
const composer = core.tx(input.wallet).priorityFee(options.priorityFee ?? {});
|
|
188
188
|
if (side === "buy") {
|
|
189
189
|
const buy = input as SolardBuyInput;
|
|
190
|
-
composer.buy(buy.token, tradeAmount(buy.amount), {
|
|
191
|
-
slippageBps: buy.slippageBps,
|
|
192
|
-
});
|
|
190
|
+
composer.buy(buy.token, tradeAmount(buy.amount), { slippageBps: buy.slippageBps });
|
|
193
191
|
} else {
|
|
194
192
|
const sell = input as SolardSellInput;
|
|
195
|
-
composer.sell(sell.token, {
|
|
196
|
-
bps: sellBps(sell.amount),
|
|
197
|
-
slippageBps: sell.slippageBps,
|
|
198
|
-
});
|
|
193
|
+
composer.sell(sell.token, { bps: sellBps(sell.amount), slippageBps: sell.slippageBps });
|
|
199
194
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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,
|
|
195
|
+
return await composer.build();
|
|
196
|
+
}, options.via ?? "rpc", side, options);
|
|
197
|
+
const confirmedTrade =
|
|
198
|
+
receipt.status === "confirmed"
|
|
199
|
+
? (
|
|
200
|
+
await core.trades({
|
|
201
|
+
wallet: input.wallet,
|
|
202
|
+
token: input.token,
|
|
203
|
+
side,
|
|
204
|
+
status: "confirmed",
|
|
205
|
+
limit: 32,
|
|
206
|
+
})
|
|
207
|
+
).find((trade) => trade.signature === receipt.signature) ?? null
|
|
208
|
+
: null;
|
|
209
|
+
return {
|
|
210
|
+
executionId: submission.executionId,
|
|
211
|
+
signature: receipt.signature,
|
|
212
|
+
sender: receipt.sender,
|
|
213
|
+
status: receipt.status,
|
|
214
|
+
slot: receipt.slot,
|
|
215
|
+
error: receipt.error ?? null,
|
|
216
|
+
feeLamports: receipt.feeLamports,
|
|
233
217
|
computeUnitsConsumed: receipt.computeUnitsConsumed,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
history,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
218
|
+
attempts,
|
|
219
|
+
...(confirmedTrade?.solDeltaLamports != null
|
|
220
|
+
? { solPrincipalDeltaLamports: confirmedTrade.solDeltaLamports }
|
|
221
|
+
: {}),
|
|
222
|
+
...(confirmedTrade?.tokenDeltaRaw != null
|
|
223
|
+
? { targetTokenDeltaRaw: confirmedTrade.tokenDeltaRaw }
|
|
224
|
+
: {}),
|
|
225
|
+
...(confirmedTrade?.networkFeeLamports != null
|
|
226
|
+
? { networkFeeLamports: confirmedTrade.networkFeeLamports }
|
|
227
|
+
: {}),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function createSolard(options: SolardOptions = {}): Solard {
|
|
232
|
+
const core = createCoreSolard(options);
|
|
233
|
+
const history: SolardHistoryApi = Object.freeze({
|
|
234
|
+
replay: (token, replayOptions) => core.history.replay(token, replayOptions),
|
|
235
|
+
market: (token, marketOptions) => core.history.market(token, marketOptions),
|
|
236
|
+
merge: core.history.merge,
|
|
237
|
+
});
|
|
238
|
+
const events = Object.assign(
|
|
239
|
+
(token: TokenRef, eventOptions: ReplayEventsOptions = {}) =>
|
|
240
|
+
core.events(token, eventOptions),
|
|
241
|
+
{ merge: core.events.merge },
|
|
242
|
+
) as SolardEventsApi;
|
|
243
|
+
return Object.freeze({
|
|
244
|
+
close: core.close.bind(core),
|
|
245
|
+
history,
|
|
246
|
+
events: Object.freeze(events),
|
|
247
|
+
claims: Object.freeze({
|
|
248
|
+
creatorFees: Object.freeze({
|
|
249
|
+
claim: core.claims.creatorFees.claim,
|
|
250
|
+
status: core.claims.creatorFees.status,
|
|
251
|
+
}),
|
|
252
|
+
}),
|
|
253
|
+
distributions: Object.freeze({
|
|
254
|
+
plan: core.distributions.plan,
|
|
255
|
+
execute: core.distributions.execute,
|
|
256
|
+
status: core.distributions.status,
|
|
257
|
+
}),
|
|
258
|
+
createWallet: core.createWallet.bind(core),
|
|
259
|
+
createVanityWallet: core.createVanityWallet.bind(core),
|
|
260
|
+
importWallet: core.importWallet.bind(core),
|
|
261
|
+
listWallets: core.listWallets.bind(core),
|
|
262
|
+
walletAddress: core.walletAddress.bind(core),
|
|
263
|
+
exportPrivateKey: core.exportWalletPrivateKey.bind(core),
|
|
264
|
+
addToken: core.addToken.bind(core),
|
|
265
|
+
resolveToken: core.resolveToken.bind(core),
|
|
266
|
+
tokenAccounts: core.tokenAccounts.bind(core),
|
|
267
|
+
snapshotHolders: core.snapshotHolders.bind(core),
|
|
268
|
+
walletBalances: core.walletBalances.bind(core),
|
|
269
|
+
recordConfirmedTrade: core.recordConfirmedTrade.bind(core),
|
|
270
|
+
trades: core.trades.bind(core),
|
|
271
|
+
position: core.position.bind(core),
|
|
272
|
+
getTransaction: core.getTransaction.bind(core),
|
|
273
|
+
samplePrice: core.samplePrice.bind(core),
|
|
274
|
+
buy: (input, executionOptions) =>
|
|
275
|
+
executeTrade(core, "buy", input, executionOptions),
|
|
276
|
+
sell: (input, executionOptions) =>
|
|
277
|
+
executeTrade(core, "sell", input, executionOptions),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
@@ -35,6 +35,7 @@ describe("sdk membrane", () => {
|
|
|
35
35
|
"fetchTokenMetadata",
|
|
36
36
|
"formatRaw",
|
|
37
37
|
"getSolUsdPrice",
|
|
38
|
+
"isDefinitivePreSubmissionError",
|
|
38
39
|
"publicTokenMetadataUrl",
|
|
39
40
|
"subscribeLaunches",
|
|
40
41
|
"subscribeMigrations",
|
|
@@ -43,6 +44,7 @@ describe("sdk membrane", () => {
|
|
|
43
44
|
"tokenAmount",
|
|
44
45
|
].sort(),
|
|
45
46
|
types: [
|
|
47
|
+
"TradeLandingPolicy",
|
|
46
48
|
"ClaimCreatorRewardsOptions",
|
|
47
49
|
"CreatorRewardClaimPayout",
|
|
48
50
|
"CreatorRewardClaimResult",
|
package/src/index.ts
CHANGED
|
@@ -1,106 +1,112 @@
|
|
|
1
|
-
export { default } from "./default.ts";
|
|
2
|
-
export { createSolard } from "./client.ts";
|
|
1
|
+
export { default } from "./default.ts";
|
|
2
|
+
export { createSolard } from "./client.ts";
|
|
3
3
|
export type {
|
|
4
|
-
Solard,
|
|
5
|
-
SolardBuyInput,
|
|
6
|
-
SolardEventsApi,
|
|
7
|
-
SolardHistoryApi,
|
|
8
|
-
SolardOptions,
|
|
9
|
-
SolardSellInput,
|
|
10
|
-
SolardTradeExecutionOptions,
|
|
11
|
-
SolardTradeExecutionResult,
|
|
12
|
-
} from "./client.ts";
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
|
|
4
|
+
Solard,
|
|
5
|
+
SolardBuyInput,
|
|
6
|
+
SolardEventsApi,
|
|
7
|
+
SolardHistoryApi,
|
|
8
|
+
SolardOptions,
|
|
9
|
+
SolardSellInput,
|
|
10
|
+
SolardTradeExecutionOptions,
|
|
11
|
+
SolardTradeExecutionResult,
|
|
12
|
+
} from "./client.ts";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
formatRaw,
|
|
16
|
+
sol,
|
|
17
|
+
tokenAmount,
|
|
18
|
+
isDefinitivePreSubmissionError,
|
|
19
|
+
} from "@solard/core";
|
|
20
|
+
|
|
16
21
|
export type {
|
|
17
22
|
ClaimCreatorRewardsOptions,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
23
|
+
TradeLandingPolicy,
|
|
24
|
+
CreatorRewardClaimPayout,
|
|
25
|
+
CreatorRewardClaimResult,
|
|
26
|
+
CumulativeDistributionExecuteOptions,
|
|
27
|
+
CumulativeDistributionInput,
|
|
28
|
+
CumulativeDistributionPlan,
|
|
29
|
+
CumulativeDistributionRecipient,
|
|
30
|
+
CumulativeDistributionState,
|
|
31
|
+
CumulativeEntitlement,
|
|
32
|
+
HumanAmount,
|
|
33
|
+
MarketHistory,
|
|
34
|
+
MarketHistoryOptions,
|
|
35
|
+
MarketPrice,
|
|
36
|
+
MergedReplayEventStream,
|
|
37
|
+
QuoteAsset,
|
|
38
|
+
ReplayCoverage,
|
|
39
|
+
ReplayEventSubscription,
|
|
40
|
+
ReplayEventsOptions,
|
|
41
|
+
ReplayHistory,
|
|
42
|
+
ReplayItem,
|
|
43
|
+
ReplayOptions,
|
|
44
|
+
ReplayPayout,
|
|
45
|
+
ReplayTransaction,
|
|
46
|
+
RecordConfirmedTradeInput,
|
|
47
|
+
SendReceipt,
|
|
48
|
+
SenderId,
|
|
49
|
+
SimulationResult,
|
|
50
|
+
SolardDecodedTransaction,
|
|
51
|
+
SolardPosition,
|
|
52
|
+
SolardPositionQuery,
|
|
53
|
+
SolardTransactionNativeBalance,
|
|
54
|
+
SolardTransactionOptions,
|
|
55
|
+
SolardTransactionTokenBalance,
|
|
56
|
+
SolardTrade,
|
|
57
|
+
SolardTradeQuery,
|
|
58
|
+
SolardTradeSide,
|
|
59
|
+
SolardTradeStatus,
|
|
60
|
+
SolardCanonicalEvent,
|
|
61
|
+
SolardClaimAttribution,
|
|
62
|
+
SolardClaimEvent,
|
|
63
|
+
TokenEventHistoryProgress,
|
|
64
|
+
TokenHolder,
|
|
65
|
+
ExcludedTokenHolder,
|
|
66
|
+
TokenHolderSnapshot,
|
|
67
|
+
TokenHolderSnapshotOptions,
|
|
68
|
+
TokenRef,
|
|
69
|
+
TokenRow,
|
|
70
|
+
WalletInfo,
|
|
71
|
+
WalletPrivateKeyExport,
|
|
72
|
+
WalletPrivateKeyFormat,
|
|
73
|
+
WalletRef,
|
|
74
|
+
} from "@solard/core";
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
fetchTokenMetadata,
|
|
78
|
+
getSolUsdPrice,
|
|
79
|
+
publicTokenMetadataUrl,
|
|
80
|
+
} from "@solard/core";
|
|
81
|
+
export {
|
|
82
|
+
listenTrades,
|
|
83
|
+
subscribeLaunches,
|
|
84
|
+
subscribeMigrations,
|
|
85
|
+
} from "./live.ts";
|
|
86
|
+
export type {
|
|
87
|
+
ListenTradesOptions,
|
|
88
|
+
SubscribeLaunchesOptions,
|
|
89
|
+
SubscribeMigrationsOptions,
|
|
90
|
+
TradeListener,
|
|
91
|
+
} from "./live.ts";
|
|
92
|
+
export type {
|
|
93
|
+
LaunchEvent,
|
|
94
|
+
LaunchSubscription,
|
|
95
|
+
LaunchVenue,
|
|
96
|
+
MigrationDestination,
|
|
97
|
+
MigrationEvent,
|
|
98
|
+
MigrationSubscription,
|
|
99
|
+
MigrationVenue,
|
|
100
|
+
GetSolUsdPriceOptions,
|
|
101
|
+
SolUsdPrice,
|
|
102
|
+
SolUsdSource,
|
|
103
|
+
TradeEvent,
|
|
104
|
+
TradeMarket,
|
|
105
|
+
TradeSide,
|
|
106
|
+
TradeVenue,
|
|
107
|
+
FetchTokenMetadataOptions,
|
|
108
|
+
TokenMetadata,
|
|
109
|
+
TokenMetadataHint,
|
|
110
|
+
TokenMetadataKind,
|
|
111
|
+
TokenMetadataMode,
|
|
112
|
+
} from "@solard/core";
|
package/src/live.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe("operator api", () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test("default trades settle inside Solard rather than leaking submitted state", () => {
|
|
40
|
-
expect(client).toContain("core.
|
|
40
|
+
expect(client).toContain("core.executeTradePlan(");
|
|
41
41
|
expect(core).toContain("async settleSubmission(");
|
|
42
42
|
expect(core).toContain("submission.plan.lastValidBlockHeight");
|
|
43
43
|
});
|