@depthhq/sdk 0.0.0-stage → 0.1.1
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/dist/account/confirm.d.ts +5 -0
- package/dist/account/discovery.d.ts +49 -0
- package/dist/account/funding.d.ts +86 -0
- package/dist/account/funding.js +498 -0
- package/dist/account/release.d.ts +8 -0
- package/dist/account/token.d.ts +5 -0
- package/dist/app/app.d.ts +50 -0
- package/dist/catalog/catalog.d.ts +50 -0
- package/dist/catalog/data.d.ts +30 -0
- package/dist/catalog/data.js +169 -0
- package/dist/chain/arcium.d.ts +10 -0
- package/dist/chain/connection.d.ts +4 -0
- package/dist/chain/environment.d.ts +20 -0
- package/dist/chain/manifest.d.ts +36 -0
- package/dist/chain/network.d.ts +18 -0
- package/dist/chain/provider.d.ts +6 -0
- package/dist/chain/random.d.ts +1 -0
- package/dist/chain/settlement.d.ts +15 -0
- package/dist/chain/transaction.d.ts +12 -0
- package/dist/client/client.d.ts +137 -0
- package/dist/client/types.d.ts +105 -0
- package/dist/history/history.d.ts +26 -0
- package/dist/history/replay.d.ts +13 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +47534 -0
- package/dist/operation/error.d.ts +10 -0
- package/dist/operation/operation.d.ts +49 -0
- package/dist/operator.d.ts +6 -0
- package/dist/operator.js +25383 -0
- package/dist/position/pnl.d.ts +14 -0
- package/dist/recovery/coordinator.d.ts +17 -0
- package/dist/recovery/recovery.d.ts +26 -0
- package/dist/recovery/recovery.js +1420 -0
- package/dist/recovery/shares.d.ts +26 -0
- package/dist/recovery/winddown.d.ts +38 -0
- package/dist/recovery/witness.d.ts +16 -0
- package/dist/trade/amount.d.ts +2 -0
- package/dist/trade/flow.d.ts +21 -0
- package/dist/trade/input.d.ts +3 -0
- package/dist/trade/terms.d.ts +3 -0
- package/dist/view/view.d.ts +59 -0
- package/dist/view/view.js +26681 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { FundingClient } from "../account/funding.js";
|
|
4
|
+
export type AppSummary = {
|
|
5
|
+
id: PublicKey;
|
|
6
|
+
feeBps: number;
|
|
7
|
+
version: bigint;
|
|
8
|
+
active: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ConfirmOptions = {
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
pollMs?: number;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
};
|
|
15
|
+
export declare class AppAdmin {
|
|
16
|
+
private readonly program;
|
|
17
|
+
private readonly connection;
|
|
18
|
+
private readonly owner;
|
|
19
|
+
private readonly funding;
|
|
20
|
+
readonly id: PublicKey;
|
|
21
|
+
readonly address: PublicKey;
|
|
22
|
+
constructor(program: anchor.Program, connection: Connection, owner: PublicKey, funding: FundingClient);
|
|
23
|
+
summary(): Promise<AppSummary | undefined>;
|
|
24
|
+
register(input: {
|
|
25
|
+
feeBps: number;
|
|
26
|
+
}): Promise<AppRegistration>;
|
|
27
|
+
setFee(feeBps: number): Promise<AppUpdate>;
|
|
28
|
+
setActive(active: boolean): Promise<AppUpdate>;
|
|
29
|
+
private requireSummary;
|
|
30
|
+
private validateFee;
|
|
31
|
+
private update;
|
|
32
|
+
}
|
|
33
|
+
export declare class AppUpdate {
|
|
34
|
+
private readonly admin;
|
|
35
|
+
private readonly feeBps;
|
|
36
|
+
private readonly active;
|
|
37
|
+
readonly signature: string;
|
|
38
|
+
constructor(admin: AppAdmin, feeBps: number, active: boolean, signature: string);
|
|
39
|
+
confirm(): Promise<AppSummary>;
|
|
40
|
+
}
|
|
41
|
+
export declare class AppRegistration {
|
|
42
|
+
private readonly admin;
|
|
43
|
+
private readonly funding;
|
|
44
|
+
private readonly feeBps;
|
|
45
|
+
readonly signature?: string | undefined;
|
|
46
|
+
constructor(admin: AppAdmin, funding: FundingClient, feeBps: number, signature?: string | undefined);
|
|
47
|
+
confirm(options?: ConfirmOptions): Promise<{
|
|
48
|
+
appId: PublicKey;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SOL_USD_MARKET_ID } from "@depthhq/bindings";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { DepthClient } from "../client/client.js";
|
|
4
|
+
export type MarketPolicy = {
|
|
5
|
+
initialMarginBps: number;
|
|
6
|
+
maintenanceMarginBps: number;
|
|
7
|
+
liquidationFeeBps: number;
|
|
8
|
+
tradeFeeBps: number;
|
|
9
|
+
insuranceFeeBps: number;
|
|
10
|
+
maxAccountNotional: bigint;
|
|
11
|
+
maxMarketNotional: bigint;
|
|
12
|
+
maxOracleAgeSeconds: number;
|
|
13
|
+
maxConfidenceBps: number;
|
|
14
|
+
maxQuoteDeviationBps: number;
|
|
15
|
+
maxQuoteLifetimeSeconds: number;
|
|
16
|
+
maxOrderQueueSeconds: number;
|
|
17
|
+
fundingIntervalSeconds: number;
|
|
18
|
+
fundingRateCapBps: number;
|
|
19
|
+
quoteTiers: bigint[];
|
|
20
|
+
backstopMinCollateral: bigint;
|
|
21
|
+
};
|
|
22
|
+
export type MarketSummary = {
|
|
23
|
+
id: typeof SOL_USD_MARKET_ID;
|
|
24
|
+
address: PublicKey;
|
|
25
|
+
settlementMint: PublicKey;
|
|
26
|
+
status: string;
|
|
27
|
+
incident: string;
|
|
28
|
+
revision: bigint;
|
|
29
|
+
oraclePriceE8: bigint;
|
|
30
|
+
oracleEmaE8: bigint;
|
|
31
|
+
oracleConfidenceE8: bigint;
|
|
32
|
+
oracleTimestamp: bigint;
|
|
33
|
+
oracleSlot: bigint;
|
|
34
|
+
fundingIndex: bigint;
|
|
35
|
+
lastFundingTimestamp: bigint;
|
|
36
|
+
activeQuoteIds: PublicKey[];
|
|
37
|
+
waitingQuoteIds: PublicKey[];
|
|
38
|
+
policy: MarketPolicy;
|
|
39
|
+
slot: number;
|
|
40
|
+
};
|
|
41
|
+
export declare class MarketCatalog {
|
|
42
|
+
private readonly client;
|
|
43
|
+
constructor(client: DepthClient);
|
|
44
|
+
market(id: string): Promise<MarketSummary>;
|
|
45
|
+
markets(): Promise<{
|
|
46
|
+
items: MarketSummary[];
|
|
47
|
+
nextCursor?: string;
|
|
48
|
+
}>;
|
|
49
|
+
marketPolicy(id: string): Promise<MarketPolicy>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CandleInterval, CandlePage, PublicMarket, PublicApp } from "@depthhq/schema";
|
|
2
|
+
export type { Candle, CandleInterval, CandlePage, PublicMarket, PublicApp, } from "@depthhq/schema";
|
|
3
|
+
import { type DepthEnvironment } from "../chain/network.js";
|
|
4
|
+
export type DataOptions = {
|
|
5
|
+
environment: DepthEnvironment;
|
|
6
|
+
serviceUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
export type CandleQuery = {
|
|
9
|
+
interval?: CandleInterval;
|
|
10
|
+
before?: number;
|
|
11
|
+
limit?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare class MarketData {
|
|
14
|
+
readonly serviceUrl: string;
|
|
15
|
+
constructor(options: DataOptions);
|
|
16
|
+
private get;
|
|
17
|
+
markets(): Promise<{
|
|
18
|
+
items: PublicMarket[];
|
|
19
|
+
}>;
|
|
20
|
+
market(marketId?: string): Promise<PublicMarket>;
|
|
21
|
+
app(appId: string): Promise<PublicApp>;
|
|
22
|
+
candles(marketId?: string, query?: CandleQuery, signal?: AbortSignal): Promise<CandlePage>;
|
|
23
|
+
subscribe(input: {
|
|
24
|
+
marketId?: string;
|
|
25
|
+
interval?: CandleInterval;
|
|
26
|
+
onUpdate: (page: CandlePage) => void;
|
|
27
|
+
onError: (error: unknown) => void;
|
|
28
|
+
}): () => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function create_depth_data(options: DataOptions): MarketData;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/catalog/data.ts
|
|
2
|
+
import { candleIntervals } from "@depthhq/schema";
|
|
3
|
+
|
|
4
|
+
// src/chain/network.ts
|
|
5
|
+
var environments = {
|
|
6
|
+
localnet: {
|
|
7
|
+
rpc: "http://127.0.0.1:8899",
|
|
8
|
+
service: "http://127.0.0.1:8787"
|
|
9
|
+
},
|
|
10
|
+
devnet: {
|
|
11
|
+
rpc: "https://api.devnet.solana.com",
|
|
12
|
+
service: "https://depth.supply",
|
|
13
|
+
genesis: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG"
|
|
14
|
+
},
|
|
15
|
+
"mainnet-beta": {
|
|
16
|
+
rpc: "https://api.mainnet.solana.com",
|
|
17
|
+
service: "https://depth.supply",
|
|
18
|
+
genesis: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function endpoint(value, environment, name) {
|
|
22
|
+
const url = new URL(value);
|
|
23
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
24
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
25
|
+
throw new RangeError(`${name} must use HTTPS, or loopback HTTP for local development`);
|
|
26
|
+
}
|
|
27
|
+
return url.toString().replace(/\/$/, "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/catalog/data.ts
|
|
31
|
+
function parseCandles(value) {
|
|
32
|
+
const page = value;
|
|
33
|
+
if (!page || page.marketId !== "SOL-USD" || page.kind !== "reference" || page.source !== "hyperliquid" || !candleIntervals.includes(page.interval) || !Number.isSafeInteger(page.fetchedAt) || typeof page.stale !== "boolean" || page.nextCursor !== null && !Number.isSafeInteger(page.nextCursor) || !Array.isArray(page.items) || page.items.length > 500) {
|
|
34
|
+
throw new Error("Invalid reference candle response");
|
|
35
|
+
}
|
|
36
|
+
let previous = -1;
|
|
37
|
+
for (const candle of page.items) {
|
|
38
|
+
if (!Number.isSafeInteger(candle.time) || candle.time <= previous || [candle.open, candle.high, candle.low, candle.close].some((price) => !Number.isFinite(price) || price <= 0) || candle.high < Math.max(candle.open, candle.close, candle.low) || candle.low > Math.min(candle.open, candle.close))
|
|
39
|
+
throw new Error("Invalid reference candle");
|
|
40
|
+
previous = candle.time;
|
|
41
|
+
}
|
|
42
|
+
return page;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class MarketData {
|
|
46
|
+
serviceUrl;
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.serviceUrl = endpoint(options.serviceUrl ?? environments[options.environment].service, options.environment, "serviceUrl");
|
|
49
|
+
}
|
|
50
|
+
async get(path, signal) {
|
|
51
|
+
const response = await fetch(`${this.serviceUrl}${path}`, {
|
|
52
|
+
signal: signal ?? AbortSignal.timeout(15000),
|
|
53
|
+
cache: "no-store"
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
throw new Error(`Depth public service returned HTTP ${response.status}`);
|
|
57
|
+
return response.json();
|
|
58
|
+
}
|
|
59
|
+
async markets() {
|
|
60
|
+
const page = await this.get("/v1/markets");
|
|
61
|
+
if (!Array.isArray(page.markets))
|
|
62
|
+
throw new Error("Market discovery is unavailable");
|
|
63
|
+
return { items: page.markets };
|
|
64
|
+
}
|
|
65
|
+
async market(marketId = "SOL-USD") {
|
|
66
|
+
const market = await this.get(`/v1/markets/${encodeURIComponent(marketId)}`);
|
|
67
|
+
if (market.id !== marketId)
|
|
68
|
+
throw new Error("Market response identity mismatch");
|
|
69
|
+
return market;
|
|
70
|
+
}
|
|
71
|
+
async app(appId) {
|
|
72
|
+
const app = await this.get(`/v1/apps/${encodeURIComponent(appId)}`);
|
|
73
|
+
if (app.id !== appId || !Number.isSafeInteger(app.fee_bps))
|
|
74
|
+
throw new Error("App response identity mismatch");
|
|
75
|
+
return app;
|
|
76
|
+
}
|
|
77
|
+
async candles(marketId = "SOL-USD", query = {}, signal) {
|
|
78
|
+
const params = new URLSearchParams;
|
|
79
|
+
for (const [name, value] of Object.entries(query))
|
|
80
|
+
if (value !== undefined)
|
|
81
|
+
params.set(name, String(value));
|
|
82
|
+
return parseCandles(await this.get(`/v1/markets/${encodeURIComponent(marketId)}/candles?${params}`, signal));
|
|
83
|
+
}
|
|
84
|
+
subscribe(input) {
|
|
85
|
+
const controller = new AbortController;
|
|
86
|
+
const signal = controller.signal;
|
|
87
|
+
const run = async () => {
|
|
88
|
+
let last = 0;
|
|
89
|
+
while (!signal.aborted) {
|
|
90
|
+
try {
|
|
91
|
+
const url = `${this.serviceUrl}/v1/markets/${encodeURIComponent(input.marketId ?? "SOL-USD")}/stream?interval=${input.interval ?? "15m"}`;
|
|
92
|
+
const response = await fetch(url, {
|
|
93
|
+
signal,
|
|
94
|
+
headers: { accept: "text/event-stream" }
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok || !response.body)
|
|
97
|
+
throw new Error("Market stream is unavailable");
|
|
98
|
+
const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
|
|
99
|
+
const abort = () => {
|
|
100
|
+
reader.cancel().catch(() => {
|
|
101
|
+
return;
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
105
|
+
let buffer = "";
|
|
106
|
+
try {
|
|
107
|
+
for (;; ) {
|
|
108
|
+
const part = await reader.read();
|
|
109
|
+
if (part.done)
|
|
110
|
+
throw new Error("Market stream disconnected");
|
|
111
|
+
buffer += part.value.replace(/\r/g, "");
|
|
112
|
+
if (buffer.length > 1e6)
|
|
113
|
+
throw new Error("Market stream frame is too large");
|
|
114
|
+
let boundary;
|
|
115
|
+
while ((boundary = buffer.indexOf(`
|
|
116
|
+
|
|
117
|
+
`)) !== -1) {
|
|
118
|
+
const frame = buffer.slice(0, boundary);
|
|
119
|
+
buffer = buffer.slice(boundary + 2);
|
|
120
|
+
if (frame.includes("event: unavailable"))
|
|
121
|
+
throw new Error("Reference source is unavailable");
|
|
122
|
+
const line = frame.split(`
|
|
123
|
+
`).find((entry) => entry.startsWith("data: "));
|
|
124
|
+
if (!line)
|
|
125
|
+
continue;
|
|
126
|
+
const page = parseCandles(JSON.parse(line.slice(6)));
|
|
127
|
+
if (page.interval !== (input.interval ?? "15m"))
|
|
128
|
+
throw new Error("Market stream interval mismatch");
|
|
129
|
+
if (page.fetchedAt >= last) {
|
|
130
|
+
last = page.fetchedAt;
|
|
131
|
+
input.onUpdate(page);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} finally {
|
|
136
|
+
signal.removeEventListener("abort", abort);
|
|
137
|
+
await reader.cancel().catch(() => {
|
|
138
|
+
return;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (!signal.aborted)
|
|
143
|
+
input.onError(error);
|
|
144
|
+
}
|
|
145
|
+
if (!signal.aborted)
|
|
146
|
+
await new Promise((resolve) => {
|
|
147
|
+
const abort = () => {
|
|
148
|
+
clearTimeout(timer);
|
|
149
|
+
resolve();
|
|
150
|
+
};
|
|
151
|
+
const timer = setTimeout(() => {
|
|
152
|
+
signal.removeEventListener("abort", abort);
|
|
153
|
+
resolve();
|
|
154
|
+
}, 3000);
|
|
155
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
run();
|
|
160
|
+
return () => controller.abort();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function create_depth_data(options) {
|
|
164
|
+
return new MarketData(options);
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
create_depth_data,
|
|
168
|
+
MarketData
|
|
169
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
type MxeState = {
|
|
4
|
+
cluster: number;
|
|
5
|
+
mxeProgramId: PublicKey;
|
|
6
|
+
};
|
|
7
|
+
export declare function arciumAccount(provider: anchor.AnchorProvider): {
|
|
8
|
+
fetch(address: PublicKey): Promise<MxeState>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Connection, type Commitment, type TransactionConfirmationStrategy, type RpcResponseAndContext, type SignatureResult } from "@solana/web3.js";
|
|
2
|
+
export declare class HttpConnection extends Connection {
|
|
3
|
+
confirmTransaction(strategy: TransactionConfirmationStrategy | string, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
4
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type DepthEnvironment } from "./network.js";
|
|
2
|
+
export { endpoint, environments } from "./network.js";
|
|
3
|
+
export type { DepthEnvironment } from "./network.js";
|
|
4
|
+
import { Connection } from "@solana/web3.js";
|
|
5
|
+
import type { DeploymentPolicy } from "./manifest.js";
|
|
6
|
+
export type ConnectionOptions = {
|
|
7
|
+
environment?: DepthEnvironment;
|
|
8
|
+
connection?: Connection;
|
|
9
|
+
rpcUrl?: string;
|
|
10
|
+
deployment?: DeploymentPolicy;
|
|
11
|
+
serviceUrl?: string;
|
|
12
|
+
manifestUrl?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ResolvedConnection = {
|
|
15
|
+
connection: Connection;
|
|
16
|
+
deployment: DeploymentPolicy;
|
|
17
|
+
serviceUrl?: string;
|
|
18
|
+
environment?: DepthEnvironment;
|
|
19
|
+
};
|
|
20
|
+
export declare function resolveConnection(options: ConnectionOptions): Promise<ResolvedConnection>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
export type DeploymentManifest = {
|
|
5
|
+
version: number;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
genesisHash: string;
|
|
8
|
+
program: string;
|
|
9
|
+
programHash: string;
|
|
10
|
+
idlHash: string;
|
|
11
|
+
mxe: string;
|
|
12
|
+
cluster: number;
|
|
13
|
+
settlementMint: string;
|
|
14
|
+
configHash: string;
|
|
15
|
+
revision: string;
|
|
16
|
+
definitions: {
|
|
17
|
+
name: string;
|
|
18
|
+
address: string;
|
|
19
|
+
hash: string;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
export type SignedManifest = {
|
|
23
|
+
payload: DeploymentManifest;
|
|
24
|
+
signer: string;
|
|
25
|
+
signature: string;
|
|
26
|
+
};
|
|
27
|
+
export type DeploymentPolicy = {
|
|
28
|
+
manifest: SignedManifest;
|
|
29
|
+
trustedSigner: PublicKey;
|
|
30
|
+
} | {
|
|
31
|
+
localnet: true;
|
|
32
|
+
};
|
|
33
|
+
export declare function manifestBytes(value: unknown): Buffer;
|
|
34
|
+
export declare function authenticateManifest(signed: SignedManifest, trusted: PublicKey): Promise<void>;
|
|
35
|
+
export declare function captureDeployment(provider: anchor.AnchorProvider, version: number, expiresAt: number): Promise<DeploymentManifest>;
|
|
36
|
+
export declare function verifyDeployment(provider: anchor.AnchorProvider, policy: DeploymentPolicy): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type DepthEnvironment = "localnet" | "devnet" | "mainnet-beta";
|
|
2
|
+
export declare const environments: {
|
|
3
|
+
readonly localnet: {
|
|
4
|
+
readonly rpc: "http://127.0.0.1:8899";
|
|
5
|
+
readonly service: "http://127.0.0.1:8787";
|
|
6
|
+
};
|
|
7
|
+
readonly devnet: {
|
|
8
|
+
readonly rpc: "https://api.devnet.solana.com";
|
|
9
|
+
readonly service: "https://depth.supply";
|
|
10
|
+
readonly genesis: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
11
|
+
};
|
|
12
|
+
readonly "mainnet-beta": {
|
|
13
|
+
readonly rpc: "https://api.mainnet.solana.com";
|
|
14
|
+
readonly service: "https://depth.supply";
|
|
15
|
+
readonly genesis: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function endpoint(value: string, environment: DepthEnvironment, name: string): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { Transaction } from "@solana/web3.js";
|
|
3
|
+
export declare function applyDepthComputeBudget(transaction: Transaction): void;
|
|
4
|
+
export declare class DepthProvider extends anchor.AnchorProvider {
|
|
5
|
+
sendAndConfirm(transaction: Parameters<anchor.AnchorProvider["sendAndConfirm"]>[0], signers?: Parameters<anchor.AnchorProvider["sendAndConfirm"]>[1], options?: Parameters<anchor.AnchorProvider["sendAndConfirm"]>[2]): Promise<string>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import type { Connection, PublicKey, VersionedTransactionResponse } from "@solana/web3.js";
|
|
3
|
+
export type SettlementTransaction = {
|
|
4
|
+
signature: string;
|
|
5
|
+
slot: number;
|
|
6
|
+
orderId: PublicKey;
|
|
7
|
+
timestamp?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function settlementOrder(transaction: VersionedTransactionResponse, program: anchor.Program): PublicKey | undefined;
|
|
10
|
+
export declare function settlementTransaction(connection: Connection, program: anchor.Program, address: PublicKey, match: {
|
|
11
|
+
orderId: PublicKey;
|
|
12
|
+
} | {
|
|
13
|
+
trader: PublicKey;
|
|
14
|
+
market: PublicKey;
|
|
15
|
+
}): Promise<SettlementTransaction>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import type { Connection, PublicKey, VersionedTransactionResponse } from "@solana/web3.js";
|
|
3
|
+
export type ReceiptTransaction = {
|
|
4
|
+
signature: string;
|
|
5
|
+
slot: number;
|
|
6
|
+
timestamp?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function depthInstructions(transaction: VersionedTransactionResponse, program: anchor.Program): {
|
|
9
|
+
definition: anchor.IdlInstruction;
|
|
10
|
+
accounts: (anchor.web3.PublicKey | undefined)[];
|
|
11
|
+
}[];
|
|
12
|
+
export declare function receiptTransaction(connection: Connection, program: anchor.Program, address: PublicKey, names?: readonly string[]): Promise<ReceiptTransaction>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { SOL_USD_MARKET_ID } from "@depthhq/bindings";
|
|
3
|
+
import { PublicKey } from "@solana/web3.js";
|
|
4
|
+
import { AppAdmin } from "../app/app.js";
|
|
5
|
+
import { MarketCatalog } from "../catalog/catalog.js";
|
|
6
|
+
import { FundingDiscovery } from "../account/discovery.js";
|
|
7
|
+
import { FundingClient } from "../account/funding.js";
|
|
8
|
+
import { DepthOperation } from "../operation/operation.js";
|
|
9
|
+
import { DepthRecovery } from "../recovery/recovery.js";
|
|
10
|
+
import { ExecutionHistory } from "../history/history.js";
|
|
11
|
+
import type { AmountSelector } from "../trade/amount.js";
|
|
12
|
+
import { TradeFlow } from "../trade/flow.js";
|
|
13
|
+
import { DepthView } from "../view/view.js";
|
|
14
|
+
import type { BalanceSnapshot } from "../view/view.js";
|
|
15
|
+
import type { CloseInput, DepthOptions, ResolvedDepthOptions, MarketState, ReductionInput, ReverseInput, TradeInput } from "./types.js";
|
|
16
|
+
export declare class DepthClient {
|
|
17
|
+
readonly options: ResolvedDepthOptions;
|
|
18
|
+
readonly program: anchor.Program;
|
|
19
|
+
readonly provider: anchor.AnchorProvider;
|
|
20
|
+
readonly position: ReturnType<DepthClient["positionActions"]>;
|
|
21
|
+
readonly marketAddress: anchor.web3.PublicKey;
|
|
22
|
+
readonly protocolAddress: anchor.web3.PublicKey;
|
|
23
|
+
readonly mxeAddress: anchor.web3.PublicKey;
|
|
24
|
+
get catalog(): MarketCatalog;
|
|
25
|
+
get funding(): FundingClient;
|
|
26
|
+
get app(): AppAdmin;
|
|
27
|
+
get recovery(): DepthRecovery;
|
|
28
|
+
private historyClient?;
|
|
29
|
+
get history(): ExecutionHistory;
|
|
30
|
+
private constructor();
|
|
31
|
+
static create(options: DepthOptions): Promise<DepthClient>;
|
|
32
|
+
private verifyDeployment;
|
|
33
|
+
private read;
|
|
34
|
+
private queue;
|
|
35
|
+
private accountAddress;
|
|
36
|
+
market(): Promise<{
|
|
37
|
+
address: PublicKey;
|
|
38
|
+
state: MarketState;
|
|
39
|
+
slot: number;
|
|
40
|
+
}>;
|
|
41
|
+
operation(id: PublicKey): DepthOperation;
|
|
42
|
+
requestBalanceView(): Promise<DepthView>;
|
|
43
|
+
requestMarketView(): Promise<DepthView>;
|
|
44
|
+
requestFillView(order: PublicKey): Promise<DepthView>;
|
|
45
|
+
private requestView;
|
|
46
|
+
private ensureBalanceReady;
|
|
47
|
+
private ensureMarketReady;
|
|
48
|
+
private allocateRequest;
|
|
49
|
+
private releaseRequest;
|
|
50
|
+
private depositRequest;
|
|
51
|
+
private withdrawRequest;
|
|
52
|
+
private accountActions;
|
|
53
|
+
readonly account: (() => {
|
|
54
|
+
detail: (item: Parameters<FundingDiscovery["detail"]>[0]) => Promise<import("../account/discovery.js").ReceiptDetail>;
|
|
55
|
+
transaction: (item: Parameters<FundingDiscovery["transaction"]>[0]) => Promise<import("../account/discovery.js").ReceiptDetail>;
|
|
56
|
+
history: (options?: Parameters<FundingDiscovery["history"]>[0]) => Promise<import("../account/discovery.js").PendingPage>;
|
|
57
|
+
pending: (options?: Parameters<FundingDiscovery["pending"]>[0]) => Promise<import("../account/discovery.js").PendingPage>;
|
|
58
|
+
cancelOpen: () => Promise<string>;
|
|
59
|
+
open: () => Promise<{
|
|
60
|
+
address: PublicKey;
|
|
61
|
+
signature: string;
|
|
62
|
+
}>;
|
|
63
|
+
deposit: (sourceOrAmount: PublicKey | bigint, amount?: bigint, clientNonce?: bigint) => Promise<import("../account/funding.js").DepositHandle>;
|
|
64
|
+
withdrawalHandle: (clientNonce: bigint) => import("../account/funding.js").WithdrawalHandle;
|
|
65
|
+
depositHandle: (nonce: bigint) => import("../account/funding.js").DepositHandle;
|
|
66
|
+
withdraw: (destinationOrAmount: PublicKey | AmountSelector, amount?: bigint, clientNonce?: bigint) => Promise<import("../account/funding.js").WithdrawalHandle>;
|
|
67
|
+
allocate: (input: bigint | {
|
|
68
|
+
marketId: typeof SOL_USD_MARKET_ID;
|
|
69
|
+
amount: AmountSelector;
|
|
70
|
+
}, clientNonce?: bigint) => Promise<import("../account/funding.js").TransferHandle>;
|
|
71
|
+
release: (input: bigint | {
|
|
72
|
+
marketId: typeof SOL_USD_MARKET_ID;
|
|
73
|
+
amount: AmountSelector;
|
|
74
|
+
}, clientNonce?: bigint) => Promise<import("../account/funding.js").TransferHandle>;
|
|
75
|
+
transferHandle: (nonce: bigint) => import("../account/funding.js").TransferHandle;
|
|
76
|
+
summary: (options?: {
|
|
77
|
+
timeoutMs: number;
|
|
78
|
+
pollMs?: number;
|
|
79
|
+
}) => Promise<BalanceSnapshot>;
|
|
80
|
+
}) & {
|
|
81
|
+
detail: (item: Parameters<FundingDiscovery["detail"]>[0]) => Promise<import("../account/discovery.js").ReceiptDetail>;
|
|
82
|
+
transaction: (item: Parameters<FundingDiscovery["transaction"]>[0]) => Promise<import("../account/discovery.js").ReceiptDetail>;
|
|
83
|
+
history: (options?: Parameters<FundingDiscovery["history"]>[0]) => Promise<import("../account/discovery.js").PendingPage>;
|
|
84
|
+
pending: (options?: Parameters<FundingDiscovery["pending"]>[0]) => Promise<import("../account/discovery.js").PendingPage>;
|
|
85
|
+
cancelOpen: () => Promise<string>;
|
|
86
|
+
open: () => Promise<{
|
|
87
|
+
address: PublicKey;
|
|
88
|
+
signature: string;
|
|
89
|
+
}>;
|
|
90
|
+
deposit: (sourceOrAmount: PublicKey | bigint, amount?: bigint, clientNonce?: bigint) => Promise<import("../account/funding.js").DepositHandle>;
|
|
91
|
+
withdrawalHandle: (clientNonce: bigint) => import("../account/funding.js").WithdrawalHandle;
|
|
92
|
+
depositHandle: (nonce: bigint) => import("../account/funding.js").DepositHandle;
|
|
93
|
+
withdraw: (destinationOrAmount: PublicKey | AmountSelector, amount?: bigint, clientNonce?: bigint) => Promise<import("../account/funding.js").WithdrawalHandle>;
|
|
94
|
+
allocate: (input: bigint | {
|
|
95
|
+
marketId: typeof SOL_USD_MARKET_ID;
|
|
96
|
+
amount: AmountSelector;
|
|
97
|
+
}, clientNonce?: bigint) => Promise<import("../account/funding.js").TransferHandle>;
|
|
98
|
+
release: (input: bigint | {
|
|
99
|
+
marketId: typeof SOL_USD_MARKET_ID;
|
|
100
|
+
amount: AmountSelector;
|
|
101
|
+
}, clientNonce?: bigint) => Promise<import("../account/funding.js").TransferHandle>;
|
|
102
|
+
transferHandle: (nonce: bigint) => import("../account/funding.js").TransferHandle;
|
|
103
|
+
summary: (options?: {
|
|
104
|
+
timeoutMs: number;
|
|
105
|
+
pollMs?: number;
|
|
106
|
+
}) => Promise<BalanceSnapshot>;
|
|
107
|
+
};
|
|
108
|
+
private positionActions;
|
|
109
|
+
readonly positions: {
|
|
110
|
+
list: (options?: {
|
|
111
|
+
cursor?: string;
|
|
112
|
+
limit?: number;
|
|
113
|
+
}) => Promise<{
|
|
114
|
+
items: {
|
|
115
|
+
id: anchor.web3.PublicKey;
|
|
116
|
+
marketId: string;
|
|
117
|
+
}[];
|
|
118
|
+
nextCursor: null;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
readonly trade: {
|
|
122
|
+
submit: (input: TradeInput) => Promise<DepthOperation>;
|
|
123
|
+
reduce: (input: ReductionInput) => Promise<DepthOperation>;
|
|
124
|
+
close: (input: CloseInput) => Promise<DepthOperation>;
|
|
125
|
+
reverse: (input: ReverseInput) => Promise<DepthOperation>;
|
|
126
|
+
operation: (clientNonce: bigint) => DepthOperation;
|
|
127
|
+
flow: (clientNonce: bigint) => TradeFlow;
|
|
128
|
+
unpairedAllocations: (options?: Parameters<FundingDiscovery["unpairedAllocations"]>[0]) => Promise<{
|
|
129
|
+
items: import("../account/discovery.js").UnpairedAllocation[];
|
|
130
|
+
nextCursor: string | null;
|
|
131
|
+
}>;
|
|
132
|
+
};
|
|
133
|
+
private orderAddress;
|
|
134
|
+
private submitTrade;
|
|
135
|
+
private validateTrade;
|
|
136
|
+
}
|
|
137
|
+
export declare function createDepth(options: DepthOptions): Promise<DepthClient>;
|