@depthhq/maker-sdk 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,35 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import type { MakerClient } from "../client/client.js";
3
+ import type { BackstopInput } from "../client/types.js";
4
+ export type BackstopSnapshot = {
5
+ offerId: PublicKey;
6
+ status: string;
7
+ capacity: bigint;
8
+ margin: bigint;
9
+ expiresAt: number;
10
+ };
11
+ type ConfirmOptions = {
12
+ timeoutMs?: number;
13
+ pollMs?: number;
14
+ };
15
+ export declare class BackstopHandle {
16
+ readonly id: PublicKey;
17
+ private readonly client;
18
+ readonly signature?: string | undefined;
19
+ constructor(id: PublicKey, client: MakerClient, signature?: string | undefined);
20
+ static offer(client: MakerClient, input: BackstopInput): Promise<BackstopHandle>;
21
+ status(): Promise<BackstopSnapshot>;
22
+ confirm(options?: ConfirmOptions): Promise<{
23
+ offerId: PublicKey;
24
+ snapshot: BackstopSnapshot;
25
+ }>;
26
+ release(): Promise<BackstopRelease>;
27
+ close(): Promise<string>;
28
+ }
29
+ export declare class BackstopRelease {
30
+ private readonly offer;
31
+ readonly signature?: string | undefined;
32
+ constructor(offer: BackstopHandle, signature?: string | undefined);
33
+ confirm(options?: ConfirmOptions): Promise<BackstopSnapshot>;
34
+ }
35
+ export {};
@@ -0,0 +1,18 @@
1
+ import * as anchor from "@anchor-lang/core";
2
+ import type { Connection, PublicKey } from "@solana/web3.js";
3
+ type MxeState = {
4
+ cluster: number;
5
+ mxeProgramId: PublicKey;
6
+ };
7
+ export declare function mxeAccount(provider: anchor.AnchorProvider): {
8
+ fetch(address: PublicKey): Promise<MxeState>;
9
+ };
10
+ export declare function queueAccounts(provider: anchor.AnchorProvider, connection: Connection, name: string, offset: anchor.BN): Promise<{
11
+ computationAccount: anchor.web3.PublicKey;
12
+ clusterAccount: anchor.web3.PublicKey;
13
+ mxeAccount: anchor.web3.PublicKey;
14
+ mempoolAccount: anchor.web3.PublicKey;
15
+ executingPool: anchor.web3.PublicKey;
16
+ compDefAccount: anchor.web3.PublicKey;
17
+ }>;
18
+ export {};
@@ -0,0 +1 @@
1
+ export declare function randomBytes(length: number): Uint8Array;
@@ -0,0 +1,176 @@
1
+ import * as anchor from "@anchor-lang/core";
2
+ import { SOL_USD_MARKET_ID } from "@depthhq/bindings";
3
+ import { DepthView } from "@depthhq/sdk/views";
4
+ import { DepthRecovery } from "@depthhq/sdk/recovery";
5
+ import type { FillSnapshot } from "@depthhq/sdk/views";
6
+ import { PublicKey } from "@solana/web3.js";
7
+ import { DepthClient, FundingClient } from "@depthhq/sdk";
8
+ import type { AmountSelector, CloseInput, ReductionInput, ReverseInput, TradeInput } from "@depthhq/sdk";
9
+ import { BackstopHandle } from "../backstop/backstop.js";
10
+ import { FillHistory } from "../fill/history.js";
11
+ import { QuoteHandle } from "../quote/quote.js";
12
+ import { QuoteReplacement } from "../quote/replacement.js";
13
+ import type { GrantState, BackstopInput, MakerOptions, ResolvedMakerOptions, QuoteRequest, QuoteState } from "./types.js";
14
+ export declare class MakerClient {
15
+ readonly options: ResolvedMakerOptions;
16
+ readonly provider: anchor.AnchorProvider;
17
+ readonly program: anchor.Program;
18
+ readonly position: ReturnType<MakerClient["positionActions"]>;
19
+ readonly marketAddress: anchor.web3.PublicKey;
20
+ readonly quoteQueueAddress: anchor.web3.PublicKey;
21
+ readonly protocolAddress: anchor.web3.PublicKey;
22
+ readonly backstop: ((id: PublicKey) => BackstopHandle) & {
23
+ offer: (input: BackstopInput) => Promise<BackstopHandle>;
24
+ };
25
+ private ownerClient?;
26
+ private owned;
27
+ get funding(): FundingClient;
28
+ get recovery(): DepthRecovery;
29
+ private constructor();
30
+ static create(options: MakerOptions): Promise<MakerClient>;
31
+ private accountActions;
32
+ readonly account: (() => {
33
+ history: (options?: Parameters<DepthClient["account"]["history"]>[0]) => Promise<import("@depthhq/sdk").PendingPage>;
34
+ cancelOpen: () => Promise<string>;
35
+ open: () => Promise<{
36
+ address: PublicKey;
37
+ signature: string;
38
+ }>;
39
+ openMarket: () => Promise<{
40
+ address: PublicKey;
41
+ signature: string;
42
+ }>;
43
+ summary: () => Promise<import("@depthhq/sdk").BalanceSnapshot>;
44
+ pending: () => Promise<import("@depthhq/sdk").PendingPage>;
45
+ deposit: (sourceOrAmount: PublicKey | bigint, amount?: bigint, clientNonce?: bigint) => Promise<import("@depthhq/sdk").DepositHandle>;
46
+ withdrawalHandle: (clientNonce: bigint) => import("@depthhq/sdk").WithdrawalHandle;
47
+ depositHandle: (nonce: bigint) => import("@depthhq/sdk").DepositHandle;
48
+ withdraw: (destinationOrAmount: PublicKey | AmountSelector, amount?: bigint, clientNonce?: bigint) => Promise<import("@depthhq/sdk").WithdrawalHandle>;
49
+ allocate: (input: bigint | {
50
+ marketId: typeof SOL_USD_MARKET_ID;
51
+ amount: AmountSelector;
52
+ }, clientNonce?: bigint) => Promise<import("@depthhq/sdk").TransferHandle>;
53
+ release: (input: bigint | {
54
+ marketId: typeof SOL_USD_MARKET_ID;
55
+ amount: AmountSelector;
56
+ }, clientNonce?: bigint) => Promise<import("@depthhq/sdk").TransferHandle>;
57
+ transferHandle: (nonce: bigint) => import("@depthhq/sdk").TransferHandle;
58
+ }) & {
59
+ history: (options?: Parameters<DepthClient["account"]["history"]>[0]) => Promise<import("@depthhq/sdk").PendingPage>;
60
+ cancelOpen: () => Promise<string>;
61
+ open: () => Promise<{
62
+ address: PublicKey;
63
+ signature: string;
64
+ }>;
65
+ openMarket: () => Promise<{
66
+ address: PublicKey;
67
+ signature: string;
68
+ }>;
69
+ summary: () => Promise<import("@depthhq/sdk").BalanceSnapshot>;
70
+ pending: () => Promise<import("@depthhq/sdk").PendingPage>;
71
+ deposit: (sourceOrAmount: PublicKey | bigint, amount?: bigint, clientNonce?: bigint) => Promise<import("@depthhq/sdk").DepositHandle>;
72
+ withdrawalHandle: (clientNonce: bigint) => import("@depthhq/sdk").WithdrawalHandle;
73
+ depositHandle: (nonce: bigint) => import("@depthhq/sdk").DepositHandle;
74
+ withdraw: (destinationOrAmount: PublicKey | AmountSelector, amount?: bigint, clientNonce?: bigint) => Promise<import("@depthhq/sdk").WithdrawalHandle>;
75
+ allocate: (input: bigint | {
76
+ marketId: typeof SOL_USD_MARKET_ID;
77
+ amount: AmountSelector;
78
+ }, clientNonce?: bigint) => Promise<import("@depthhq/sdk").TransferHandle>;
79
+ release: (input: bigint | {
80
+ marketId: typeof SOL_USD_MARKET_ID;
81
+ amount: AmountSelector;
82
+ }, clientNonce?: bigint) => Promise<import("@depthhq/sdk").TransferHandle>;
83
+ transferHandle: (nonce: bigint) => import("@depthhq/sdk").TransferHandle;
84
+ };
85
+ readonly positions: {
86
+ list: () => Promise<{
87
+ items: {
88
+ id: anchor.web3.PublicKey;
89
+ marketId: string;
90
+ }[];
91
+ nextCursor: null;
92
+ }>;
93
+ };
94
+ readonly trade: {
95
+ submit: (input: TradeInput) => Promise<import("@depthhq/sdk").DepthOperation>;
96
+ reduce: (input: ReductionInput) => Promise<import("@depthhq/sdk").DepthOperation>;
97
+ close: (input: CloseInput) => Promise<import("@depthhq/sdk").DepthOperation>;
98
+ reverse: (input: ReverseInput) => Promise<import("@depthhq/sdk").DepthOperation>;
99
+ };
100
+ marketAccount(): PublicKey;
101
+ grantAddress(operator?: anchor.web3.PublicKey): PublicKey;
102
+ read<T>(name: string, address: PublicKey): Promise<T>;
103
+ quoteState(id: PublicKey): Promise<QuoteState>;
104
+ queue(name: string, computationOffset: anchor.BN): Promise<{
105
+ computationAccount: anchor.web3.PublicKey;
106
+ clusterAccount: anchor.web3.PublicKey;
107
+ mxeAccount: anchor.web3.PublicKey;
108
+ mempoolAccount: anchor.web3.PublicKey;
109
+ executingPool: anchor.web3.PublicKey;
110
+ compDefAccount: anchor.web3.PublicKey;
111
+ }>;
112
+ private grantFor;
113
+ readonly operator: {
114
+ list: () => Promise<{
115
+ id: anchor.web3.PublicKey;
116
+ state: GrantState;
117
+ }[]>;
118
+ authorize: (input: {
119
+ operator: PublicKey;
120
+ maxCapacity: bigint;
121
+ expiresAt: number;
122
+ canView: boolean;
123
+ }) => Promise<string>;
124
+ revoke: (operator: PublicKey) => Promise<string>;
125
+ };
126
+ readonly quote: {
127
+ replacement: (prior: PublicKey, clientNonce: bigint) => QuoteReplacement;
128
+ publish: (request: QuoteRequest) => Promise<QuoteHandle>;
129
+ get: (id: PublicKey) => QuoteHandle;
130
+ list: (options?: {
131
+ cursor?: string;
132
+ limit?: number;
133
+ }) => Promise<{
134
+ items: {
135
+ id: anchor.web3.PublicKey;
136
+ nonce: bigint;
137
+ status: string;
138
+ replacementNonce: bigint | undefined;
139
+ handle: QuoteHandle;
140
+ }[];
141
+ nextCursor: string | null;
142
+ }>;
143
+ active: () => Promise<QuoteHandle[]>;
144
+ replace: (prior: PublicKey, input: QuoteRequest, options?: {
145
+ timeoutMs?: number;
146
+ pollMs?: number;
147
+ }) => Promise<QuoteHandle>;
148
+ };
149
+ private flatQuote;
150
+ private viewGrant;
151
+ requestMarketView(): Promise<DepthView>;
152
+ requestFillView(order: PublicKey): Promise<DepthView>;
153
+ requestQuoteView(quote: PublicKey): Promise<DepthView>;
154
+ private requestView;
155
+ private positionActions;
156
+ readonly fills: {
157
+ list: (options?: Parameters<FillHistory["list"]>[0]) => Promise<import("../fill/history.js").FillPage>;
158
+ subscribe: (options: {
159
+ marketId: typeof SOL_USD_MARKET_ID;
160
+ onFill: (fill: {
161
+ id: string;
162
+ signature: string;
163
+ slot: number;
164
+ execution: FillSnapshot;
165
+ }) => Promise<void>;
166
+ onError: (error: unknown) => void;
167
+ pollMs?: number;
168
+ }) => Promise<() => void>;
169
+ get: (order: PublicKey, options?: {
170
+ timeoutMs: number;
171
+ pollMs?: number;
172
+ }) => Promise<FillSnapshot>;
173
+ };
174
+ private validateQuote;
175
+ }
176
+ export declare function createDepthMaker(options: MakerOptions): Promise<MakerClient>;
@@ -0,0 +1,98 @@
1
+ import type { ConnectionOptions, ResolvedConnection, DepthWallet } from "@depthhq/sdk";
2
+ import type * as anchor from "@anchor-lang/core";
3
+ import type { PublicKey } from "@solana/web3.js";
4
+ import { SOL_USD_MARKET_ID } from "@depthhq/bindings";
5
+ export type MakerOptions = ConnectionOptions & {
6
+ wallet: DepthWallet;
7
+ maker?: PublicKey;
8
+ makerOwner?: PublicKey;
9
+ appId?: PublicKey | string;
10
+ cursorDirectory?: string;
11
+ };
12
+ export type ResolvedMakerOptions = ResolvedConnection & Omit<MakerOptions, keyof ConnectionOptions | "maker" | "appId"> & {
13
+ maker: PublicKey;
14
+ appId?: PublicKey;
15
+ };
16
+ export type QuoteTier = {
17
+ size: bigint;
18
+ bidE8: bigint;
19
+ askE8: bigint;
20
+ };
21
+ export type QuoteInput = {
22
+ tiers: QuoteTier[];
23
+ maxCapacity: bigint;
24
+ expiresAt: number;
25
+ clientNonce: bigint;
26
+ };
27
+ export type FlatQuoteInput = {
28
+ marketId: typeof SOL_USD_MARKET_ID;
29
+ bidE8: bigint;
30
+ askE8: bigint;
31
+ maxCapacity: bigint;
32
+ validForSeconds: number;
33
+ clientNonce?: bigint;
34
+ };
35
+ export type QuoteRequest = QuoteInput | FlatQuoteInput;
36
+ export type QuoteState = {
37
+ status: Record<string, unknown>;
38
+ maker: PublicKey;
39
+ operator: PublicKey;
40
+ operatorVersion: anchor.BN;
41
+ market: PublicKey;
42
+ nonce: anchor.BN;
43
+ capacity: anchor.BN;
44
+ expiry: anchor.BN;
45
+ attachedOrders: number;
46
+ replacementNonce: anchor.BN | null;
47
+ };
48
+ export type MarketState = {
49
+ revision: anchor.BN;
50
+ status: Record<string, unknown>;
51
+ settlementMint: PublicKey;
52
+ vault: PublicKey;
53
+ oracleTimestamp: anchor.BN;
54
+ pendingOrders: number;
55
+ backstopOffer: PublicKey;
56
+ activeQuoteCount: number;
57
+ activeQuotes: PublicKey[];
58
+ quotedNotional: anchor.BN;
59
+ config: {
60
+ quoteTiers: anchor.BN[];
61
+ initialMarginBps: number;
62
+ maxAccountNotional: anchor.BN;
63
+ maxMarketNotional: anchor.BN;
64
+ maxQuoteLifetimeSeconds: number;
65
+ maxOracleAgeSeconds: number;
66
+ backstopMinCollateral: anchor.BN;
67
+ };
68
+ };
69
+ export type QuoteQueueState = {
70
+ market: PublicKey;
71
+ count: number;
72
+ entries: PublicKey[];
73
+ };
74
+ export type BackstopInput = {
75
+ marketId: typeof SOL_USD_MARKET_ID;
76
+ maxCapacity: bigint;
77
+ validForSeconds: number;
78
+ clientNonce?: bigint;
79
+ };
80
+ export type BackstopState = {
81
+ maker: PublicKey;
82
+ market: PublicKey;
83
+ nonce: anchor.BN;
84
+ capacity: anchor.BN;
85
+ margin: anchor.BN;
86
+ expiry: anchor.BN;
87
+ status: Record<string, unknown>;
88
+ };
89
+ export type GrantState = {
90
+ active: boolean;
91
+ canView: boolean;
92
+ maker: PublicKey;
93
+ operator: PublicKey;
94
+ market: PublicKey;
95
+ maxCapacity: anchor.BN;
96
+ expiresAt: anchor.BN;
97
+ version: anchor.BN;
98
+ };
@@ -0,0 +1,8 @@
1
+ export declare class BrowserCursorStore {
2
+ readonly key: string;
3
+ constructor(genesis: string, maker: string);
4
+ private database;
5
+ load(): Promise<string | undefined>;
6
+ save(cursor: string): Promise<void>;
7
+ }
8
+ export declare function createCursorStore(genesis: string, maker: string, _directory?: string): BrowserCursorStore;
@@ -0,0 +1,8 @@
1
+ export declare class FillCursorStore {
2
+ readonly genesis: string;
3
+ readonly maker: string;
4
+ readonly path: string;
5
+ constructor(genesis: string, maker: string, directory?: string);
6
+ load(): Promise<string | undefined>;
7
+ save(cursor: string): Promise<void>;
8
+ }
@@ -0,0 +1,25 @@
1
+ import type { MakerClient } from "../client/client.js";
2
+ export type FillPage = {
3
+ fills: {
4
+ id: string;
5
+ signature: string;
6
+ slot: number;
7
+ }[];
8
+ cursor?: string;
9
+ head?: string;
10
+ };
11
+ export declare class FillHistory {
12
+ private readonly client;
13
+ constructor(client: MakerClient);
14
+ list(options?: {
15
+ before?: string;
16
+ until?: string;
17
+ limit?: number;
18
+ }): Promise<FillPage>;
19
+ subscribe(listener: (fill: FillPage["fills"][number]) => Promise<void>, options: {
20
+ cursor?: string;
21
+ pollMs?: number;
22
+ saveCursor: (cursor: string) => Promise<void>;
23
+ onError: (error: unknown) => void;
24
+ }): () => void;
25
+ }
@@ -0,0 +1,2 @@
1
+ import { FillCursorStore } from "./cursor.js";
2
+ export declare function createCursorStore(genesis: string, maker: string, directory?: string): FillCursorStore;
@@ -0,0 +1,9 @@
1
+ export { createDepthMaker, createDepthMaker as create_depth_maker, MakerClient, } from "./client/client.js";
2
+ export { QuoteHandle } from "./quote/quote.js";
3
+ export { QuoteReplacement } from "./quote/replacement.js";
4
+ export type { ReplacementSnapshot } from "./quote/replacement.js";
5
+ export { BackstopHandle, BackstopRelease } from "./backstop/backstop.js";
6
+ export type { BackstopSnapshot } from "./backstop/backstop.js";
7
+ export type { QuoteSnapshot } from "./quote/quote.js";
8
+ export type { FlatQuoteInput, BackstopInput, MakerOptions, QuoteInput, QuoteRequest, QuoteTier, } from "./client/types.js";
9
+ export type { FillPage } from "./fill/history.js";