@depthhq/maker-sdk 0.1.0 → 0.1.2

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,24 @@
1
+ import type { AbstractWallet } from "@nktkas/hyperliquid/signing";
2
+ import type { MakerClient } from "../client/client.js";
3
+ import { WalletSession } from "../hedge/access.js";
4
+ import { type AutomationConfig, type AutomationView } from "./types.js";
5
+ export declare class MakerAutomation extends WalletSession {
6
+ private readonly maker;
7
+ constructor(maker: MakerClient);
8
+ private view;
9
+ summary(): Promise<AutomationView | null>;
10
+ configure(config: AutomationConfig, revision?: number): Promise<AutomationView>;
11
+ approve(profile: AutomationView, options?: {
12
+ grantSeconds?: number;
13
+ operatorFundingLamports?: bigint;
14
+ hedgeWallet?: AbstractWallet;
15
+ }): Promise<{
16
+ profile: AutomationView;
17
+ signatures: string[];
18
+ }>;
19
+ private waitFunding;
20
+ private command;
21
+ start(revision?: number): Promise<AutomationView>;
22
+ pause(revision?: number): Promise<AutomationView>;
23
+ resume(revision?: number): Promise<AutomationView>;
24
+ }
@@ -0,0 +1,40 @@
1
+ import { type BotPolicy } from "../bot/policy.js";
2
+ import type { HedgePolicy } from "../hedge/types.js";
3
+ import type { MakerHedgeView } from "../hedge/access.js";
4
+ export type AutomationConfig = {
5
+ quote: BotPolicy;
6
+ hedge?: {
7
+ account: `0x${string}`;
8
+ policy: HedgePolicy;
9
+ };
10
+ };
11
+ export type Wire<T> = T extends bigint ? string : T extends object ? {
12
+ [K in keyof T]: Wire<T[K]>;
13
+ } : T;
14
+ export type AutomationView = {
15
+ owner: string;
16
+ environment: "devnet" | "mainnet-beta";
17
+ revision: number;
18
+ operator: string;
19
+ agent: `0x${string}`;
20
+ config: Wire<AutomationConfig>;
21
+ desired: "running" | "paused";
22
+ phase: "configured" | "starting" | "running" | "pausing" | "paused" | "blocked";
23
+ updatedAt: number;
24
+ reason?: string;
25
+ bot?: {
26
+ phase: "active" | "pending" | "idle" | "stopped";
27
+ reason?: string;
28
+ quoteId?: string;
29
+ fillCount: number;
30
+ };
31
+ hedge: MakerHedgeView;
32
+ funding?: {
33
+ signature: string;
34
+ lamports: string;
35
+ status: "pending" | "confirmed" | "expired" | "failed";
36
+ };
37
+ };
38
+ export declare function automationConfig(value: unknown): AutomationConfig;
39
+ export declare const automationWire: (config: AutomationConfig) => Wire<AutomationConfig>;
40
+ export declare function automationView(value: unknown, owner: string, environment: string): AutomationView | null;
@@ -0,0 +1,42 @@
1
+ import type { MakerClient } from "../client/client.js";
2
+ import { BotStore } from "./store.js";
3
+ import { type BotPolicy } from "./policy.js";
4
+ import { HedgeEngine } from "../hedge/engine.js";
5
+ export type BotSnapshot = {
6
+ phase: "active" | "pending" | "idle" | "stopped";
7
+ reason?: string;
8
+ quoteId?: string;
9
+ fillCount: number;
10
+ };
11
+ export declare class MakerBot {
12
+ readonly maker: MakerClient;
13
+ readonly policy: BotPolicy;
14
+ readonly store: BotStore;
15
+ readonly hedge?: HedgeEngine | undefined;
16
+ private state?;
17
+ private position?;
18
+ private dirty;
19
+ private busy;
20
+ private stopping;
21
+ private pricing?;
22
+ private hedgeLease?;
23
+ private pricingDirty;
24
+ private constructor();
25
+ static create(options: {
26
+ maker: MakerClient;
27
+ policy: BotPolicy;
28
+ stateDirectory: string;
29
+ hedge?: HedgeEngine;
30
+ }): Promise<MakerBot>;
31
+ private saveHedge;
32
+ private hedgeTick;
33
+ private snapshot;
34
+ private requestId;
35
+ private reconcile;
36
+ private fills;
37
+ private cancel;
38
+ tick(): Promise<BotSnapshot>;
39
+ stop(): void;
40
+ close(): Promise<void>;
41
+ }
42
+ export declare const create_maker_bot: typeof MakerBot.create;
@@ -0,0 +1,41 @@
1
+ import type { QuoteInput, MarketState } from "../client/types.js";
2
+ import type { PositionSnapshot } from "@depthhq/sdk";
3
+ import { type HedgeBook } from "../hedge/types.js";
4
+ export type BotPolicy = {
5
+ maxCapacity: bigint;
6
+ maxInventoryNotional: bigint;
7
+ spreadBps: number;
8
+ repriceBps: number;
9
+ lifetimeSeconds: number;
10
+ refreshSeconds: number;
11
+ gasReserveLamports?: bigint;
12
+ inventorySkewBps?: number;
13
+ executionCostBps?: number;
14
+ fundingHours?: number;
15
+ };
16
+ export type BotPricing = {
17
+ book: HedgeBook;
18
+ externalPosition: bigint;
19
+ maxPriceAgeMs: number;
20
+ takerFeeBps: number;
21
+ hourlyFundingBps: number;
22
+ };
23
+ export type BotMarket = MarketState & {
24
+ oraclePriceE8: {
25
+ toString(): string;
26
+ };
27
+ fundingIndex: {
28
+ toString(): string;
29
+ };
30
+ incident: Record<string, unknown>;
31
+ lastFundingTimestamp: {
32
+ toNumber(): number;
33
+ };
34
+ config: MarketState["config"] & {
35
+ maxQuoteDeviationBps: number;
36
+ fundingIntervalSeconds: number;
37
+ };
38
+ };
39
+ export declare function validateBotPolicy(policy: BotPolicy): void;
40
+ export declare function quoteHealth(market: BotMarket, now: number): string | undefined;
41
+ export declare function botQuote(policy: BotPolicy, market: BotMarket, position: PositionSnapshot, nonce: bigint, now: number, pricing?: BotPricing): QuoteInput | undefined;
@@ -0,0 +1,32 @@
1
+ import type { QuoteInput } from "../client/types.js";
2
+ import type { HedgeState } from "../hedge/types.js";
3
+ export type BotState = {
4
+ genesis: string;
5
+ maker: string;
6
+ operator: string;
7
+ cursor?: string;
8
+ quote?: string;
9
+ request?: QuoteInput;
10
+ referencePrice?: bigint;
11
+ replacement?: {
12
+ prior: string;
13
+ nonce: bigint;
14
+ };
15
+ fills: Record<string, {
16
+ signature: string;
17
+ slot: number;
18
+ }>;
19
+ hedge?: HedgeState;
20
+ };
21
+ export declare class BotStore {
22
+ readonly genesis: string;
23
+ readonly maker: string;
24
+ readonly operator: string;
25
+ readonly path: string;
26
+ private lock?;
27
+ constructor(genesis: string, maker: string, operator: string, directory: string);
28
+ acquire(): Promise<void>;
29
+ release(): Promise<void>;
30
+ load(): Promise<BotState>;
31
+ save(state: BotState): Promise<void>;
32
+ }
@@ -4,6 +4,8 @@ import { DepthView } from "@depthhq/sdk/views";
4
4
  import { DepthRecovery } from "@depthhq/sdk/recovery";
5
5
  import type { FillSnapshot } from "@depthhq/sdk/views";
6
6
  import { PublicKey } from "@solana/web3.js";
7
+ import { MakerAccess } from "../hedge/access.js";
8
+ import { MakerAutomation } from "../automation/automation.js";
7
9
  import { DepthClient, FundingClient } from "@depthhq/sdk";
8
10
  import type { AmountSelector, CloseInput, ReductionInput, ReverseInput, TradeInput } from "@depthhq/sdk";
9
11
  import { BackstopHandle } from "../backstop/backstop.js";
@@ -11,8 +13,11 @@ import { FillHistory } from "../fill/history.js";
11
13
  import { QuoteHandle } from "../quote/quote.js";
12
14
  import { QuoteReplacement } from "../quote/replacement.js";
13
15
  import type { GrantState, BackstopInput, MakerOptions, ResolvedMakerOptions, QuoteRequest, QuoteState } from "./types.js";
16
+ export declare function retryQuote<T>(action: () => Promise<T>, deadline: number): Promise<T>;
14
17
  export declare class MakerClient {
15
18
  readonly options: ResolvedMakerOptions;
19
+ readonly hedges: MakerAccess;
20
+ readonly automation: MakerAutomation;
16
21
  readonly provider: anchor.AnchorProvider;
17
22
  readonly program: anchor.Program;
18
23
  readonly position: ReturnType<MakerClient["positionActions"]>;
@@ -99,7 +104,7 @@ export declare class MakerClient {
99
104
  };
100
105
  marketAccount(): PublicKey;
101
106
  grantAddress(operator?: anchor.web3.PublicKey): PublicKey;
102
- read<T>(name: string, address: PublicKey): Promise<T>;
107
+ read<T>(name: string, address: PublicKey, commitment?: "confirmed" | "finalized"): Promise<T>;
103
108
  quoteState(id: PublicKey): Promise<QuoteState>;
104
109
  queue(name: string, computationOffset: anchor.BN): Promise<{
105
110
  computationAccount: anchor.web3.PublicKey;
@@ -3,7 +3,9 @@ import type * as anchor from "@anchor-lang/core";
3
3
  import type { PublicKey } from "@solana/web3.js";
4
4
  import { SOL_USD_MARKET_ID } from "@depthhq/bindings";
5
5
  export type MakerOptions = ConnectionOptions & {
6
- wallet: DepthWallet;
6
+ wallet: DepthWallet & {
7
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
8
+ };
7
9
  maker?: PublicKey;
8
10
  makerOwner?: PublicKey;
9
11
  appId?: PublicKey | string;
@@ -0,0 +1,40 @@
1
+ import type { PublicKey } from "@solana/web3.js";
2
+ type Wire<T> = T extends bigint ? string : T extends Array<infer U> ? Wire<U>[] : T extends object ? {
3
+ [K in keyof T]: Wire<T[K]>;
4
+ } : T;
5
+ export type MakerHedgeView = {
6
+ enabled: boolean;
7
+ maker: string;
8
+ snapshot: Wire<import("./types.js").HedgeSnapshot> | null;
9
+ };
10
+ export declare const accessMessage: (wallet: string, nonce: string, expiresAt: number, scope?: string) => string;
11
+ export declare class WalletSession {
12
+ protected readonly options: {
13
+ serviceUrl?: string;
14
+ wallet: {
15
+ publicKey: PublicKey;
16
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
17
+ };
18
+ };
19
+ private readonly scope;
20
+ private readonly prefix;
21
+ protected token?: {
22
+ value: string;
23
+ expiresAt: number;
24
+ };
25
+ constructor(options: {
26
+ serviceUrl?: string;
27
+ wallet: {
28
+ publicKey: PublicKey;
29
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
30
+ };
31
+ }, scope?: string, prefix?: string);
32
+ protected request(path: string, init?: RequestInit): Promise<any>;
33
+ authorize(): Promise<void>;
34
+ protected authorizedRequest(path: string, body?: unknown): Promise<any>;
35
+ disconnect(): void;
36
+ }
37
+ export declare class MakerAccess extends WalletSession {
38
+ summary(): Promise<MakerHedgeView>;
39
+ }
40
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function units(value: string, decimals: number, exact?: boolean): bigint;
2
+ export declare function decimal(value: bigint, decimals: number): string;
@@ -0,0 +1,9 @@
1
+ import { type HedgeAdapter, type HedgePolicy, type HedgeSnapshot, type HedgeState } from "./types.js";
2
+ export declare class HedgeEngine {
3
+ readonly adapter: HedgeAdapter;
4
+ readonly policy: HedgePolicy;
5
+ snapshot?: HedgeSnapshot;
6
+ private busy;
7
+ constructor(adapter: HedgeAdapter, policy: HedgePolicy);
8
+ tick(state: HedgeState, save: () => Promise<void>, depthPosition: bigint | undefined, timestamp?: number, reconcileOnly?: boolean): Promise<HedgeSnapshot>;
9
+ }
@@ -0,0 +1,35 @@
1
+ import { type AbstractWallet } from "@nktkas/hyperliquid/signing";
2
+ import type { HedgeAccount, HedgeAdapter, HedgeBook, HedgeOrder, HedgeReceipt } from "./types.js";
3
+ export { units, decimal } from "./amount.js";
4
+ export declare class HyperliquidAdapter implements HedgeAdapter {
5
+ readonly network: "testnet" | "mainnet";
6
+ readonly address: `0x${string}`;
7
+ private readonly wallet;
8
+ private readonly transport;
9
+ private readonly info;
10
+ private readonly asset;
11
+ private readonly sizeDecimals;
12
+ readonly minNotional = 10000000n;
13
+ readonly identity: string;
14
+ readonly sizeStep: bigint;
15
+ private readonly cache;
16
+ private cached;
17
+ private constructor();
18
+ static create(options: {
19
+ wallet?: AbstractWallet;
20
+ agentKey?: `0x${string}`;
21
+ account: `0x${string}`;
22
+ network?: "testnet" | "mainnet";
23
+ }): Promise<HyperliquidAdapter>;
24
+ book(): Promise<HedgeBook>;
25
+ account(): Promise<HedgeAccount>;
26
+ costs(): Promise<{
27
+ takerFeeBps: number;
28
+ hourlyFundingBps: number;
29
+ }>;
30
+ price(value: bigint, buy: boolean): bigint;
31
+ submit(order: HedgeOrder): Promise<HedgeReceipt>;
32
+ receipt(order: HedgeOrder): Promise<HedgeReceipt>;
33
+ cancel(order: HedgeOrder, nonce?: number): Promise<void>;
34
+ }
35
+ export declare const create_hyperliquid: typeof HyperliquidAdapter.create;
@@ -0,0 +1,4 @@
1
+ import type { HedgeBook, HedgePolicy } from "./types.js";
2
+ export declare function validateHedgePolicy(policy: HedgePolicy): void;
3
+ export declare function validateBook(book: HedgeBook, now: number, maxAge: number): void;
4
+ export declare function executionPrice(levels: HedgeBook["bids"], size: bigint): bigint;
@@ -0,0 +1,2 @@
1
+ import type { MakerHedgeView } from "./access.js";
2
+ export declare function hedgeView(value: unknown, owner: string): MakerHedgeView;
@@ -0,0 +1,22 @@
1
+ import { type AbstractWallet } from "@nktkas/hyperliquid/signing";
2
+ export declare function verify_hyperliquid(options: {
3
+ account: `0x${string}`;
4
+ agent: `0x${string}`;
5
+ network: "testnet" | "mainnet";
6
+ maxLeverage: number;
7
+ }): Promise<void>;
8
+ export declare function setup_hyperliquid(options: {
9
+ wallet?: AbstractWallet;
10
+ accountKey?: `0x${string}`;
11
+ account?: `0x${string}`;
12
+ agent?: `0x${string}`;
13
+ agentKey?: `0x${string}`;
14
+ network?: "testnet" | "mainnet";
15
+ leverage: number;
16
+ agentName?: string;
17
+ }): Promise<{
18
+ account: `0x${string}`;
19
+ agent: `0x${string}`;
20
+ network: "testnet" | "mainnet";
21
+ leverage: number;
22
+ }>;
@@ -0,0 +1,89 @@
1
+ export type HedgePolicy = {
2
+ ratioBps: number;
3
+ thresholdNotional: bigint;
4
+ maxUnhedgedNotional: bigint;
5
+ maxOrderNotional: bigint;
6
+ batchMs: number;
7
+ maxUnhedgedMs: number;
8
+ maxSlippageBps: number;
9
+ maxPriceAgeMs: number;
10
+ orderTtlMs: number;
11
+ maxLeverage: number;
12
+ };
13
+ export type HedgeLevel = {
14
+ priceE8: bigint;
15
+ size: bigint;
16
+ };
17
+ export type HedgeBook = {
18
+ timestamp: number;
19
+ bids: HedgeLevel[];
20
+ asks: HedgeLevel[];
21
+ };
22
+ export type HedgeAccount = {
23
+ timestamp: number;
24
+ position: bigint;
25
+ availableMargin: bigint;
26
+ leverage: number;
27
+ openOrders: string[];
28
+ };
29
+ export type HedgeOrder = {
30
+ cloid: string;
31
+ nonce: number;
32
+ expiresAt: number;
33
+ buy: boolean;
34
+ size: bigint;
35
+ limitPriceE8: bigint;
36
+ reduceOnly: boolean;
37
+ };
38
+ export type HedgeReceipt = {
39
+ status: "filled" | "cancelled" | "rejected" | "open" | "unknown";
40
+ orderId?: number;
41
+ filledSize: bigint;
42
+ averagePriceE8?: bigint;
43
+ fee?: bigint;
44
+ hashes?: string[];
45
+ reason?: string;
46
+ };
47
+ export type HedgeRecord = HedgeOrder & HedgeReceipt & {
48
+ completedAt: number;
49
+ };
50
+ export type HedgeState = {
51
+ identity: string;
52
+ depthAccount?: string;
53
+ nonce: number;
54
+ unhedgedSince?: number;
55
+ pending?: HedgeOrder;
56
+ history: HedgeRecord[];
57
+ };
58
+ export type HedgeSnapshot = {
59
+ venue: "hyperliquid";
60
+ network: "testnet" | "mainnet";
61
+ account: string;
62
+ updatedAt: number;
63
+ phase: "balanced" | "waiting" | "pending" | "blocked";
64
+ reason?: string;
65
+ depthPosition?: bigint;
66
+ externalPosition?: bigint;
67
+ unhedgedPosition?: bigint;
68
+ pending?: HedgeOrder;
69
+ history: HedgeRecord[];
70
+ };
71
+ export interface HedgeAdapter {
72
+ readonly identity: string;
73
+ readonly network: "testnet" | "mainnet";
74
+ readonly address: string;
75
+ readonly sizeStep: bigint;
76
+ readonly minNotional: bigint;
77
+ book(): Promise<HedgeBook>;
78
+ costs(): Promise<{
79
+ takerFeeBps: number;
80
+ hourlyFundingBps: number;
81
+ }>;
82
+ account(): Promise<HedgeAccount>;
83
+ price(value: bigint, buy: boolean): bigint;
84
+ submit(order: HedgeOrder): Promise<HedgeReceipt>;
85
+ receipt(order: HedgeOrder): Promise<HedgeReceipt>;
86
+ cancel(order: HedgeOrder, nonce: number): Promise<void>;
87
+ }
88
+ export declare const abs: (value: bigint) => bigint;
89
+ export declare const notional: (size: bigint, priceE8: bigint) => bigint;
@@ -0,0 +1,8 @@
1
+ import type { AbstractViemJsonRpcAccount } from "@nktkas/hyperliquid/signing";
2
+ export type EthereumProvider = {
3
+ request(input: {
4
+ method: string;
5
+ params?: unknown[];
6
+ }): Promise<unknown>;
7
+ };
8
+ export declare function connect_hyperliquid(provider: EthereumProvider): Promise<AbstractViemJsonRpcAccount>;
package/dist/index.d.ts CHANGED
@@ -7,3 +7,11 @@ export type { BackstopSnapshot } from "./backstop/backstop.js";
7
7
  export type { QuoteSnapshot } from "./quote/quote.js";
8
8
  export type { FlatQuoteInput, BackstopInput, MakerOptions, QuoteInput, QuoteRequest, QuoteTier, } from "./client/types.js";
9
9
  export type { FillPage } from "./fill/history.js";
10
+ export { MakerAccess } from "./hedge/access.js";
11
+ export type { MakerHedgeView } from "./hedge/access.js";
12
+ export { MakerAutomation } from "./automation/automation.js";
13
+ export { automationConfig, automationWire, automationView, } from "./automation/types.js";
14
+ export type { AutomationConfig, AutomationView } from "./automation/types.js";
15
+ export { setup_hyperliquid } from "./hedge/setup.js";
16
+ export { connect_hyperliquid } from "./hedge/wallet.js";
17
+ export type { EthereumProvider } from "./hedge/wallet.js";