@depthhq/sdk 0.1.2 → 0.1.4
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/funding.d.ts +2 -1
- package/dist/account/funding.js +4 -2
- package/dist/chain/provider.d.ts +4 -1
- package/dist/client/client.d.ts +12 -1
- package/dist/client/types.d.ts +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +617 -127
- package/dist/view/cache.d.ts +40 -0
- package/dist/view/session.d.ts +28 -0
- package/dist/view/view.d.ts +7 -1
- package/dist/view/view.js +31 -3
- package/package.json +6 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BalanceSnapshot, PositionSnapshot } from "./view.js";
|
|
2
|
+
type Snapshot = BalanceSnapshot | PositionSnapshot;
|
|
3
|
+
type Kind = "balance" | "market";
|
|
4
|
+
type Envelope = {
|
|
5
|
+
iv: Uint8Array;
|
|
6
|
+
data: ArrayBuffer;
|
|
7
|
+
};
|
|
8
|
+
export interface ViewStorage {
|
|
9
|
+
key(scope: string, proposed: CryptoKey): Promise<CryptoKey>;
|
|
10
|
+
read(id: string): Promise<Envelope | undefined>;
|
|
11
|
+
write(id: string, value: Envelope): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare class DeviceViews implements ViewStorage {
|
|
14
|
+
private database?;
|
|
15
|
+
private open;
|
|
16
|
+
key(scope: string, proposed: CryptoKey): Promise<CryptoKey>;
|
|
17
|
+
read(id: string): Promise<Envelope | undefined>;
|
|
18
|
+
write(id: string, value: Envelope): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class EncryptedViews {
|
|
21
|
+
private readonly scope;
|
|
22
|
+
private readonly storage;
|
|
23
|
+
private key?;
|
|
24
|
+
constructor(scope: string, storage: ViewStorage);
|
|
25
|
+
private encryptionKey;
|
|
26
|
+
read<T>(name: string): Promise<T | undefined>;
|
|
27
|
+
write(name: string, value: unknown): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare class ViewCache {
|
|
30
|
+
private readonly scope;
|
|
31
|
+
private readonly storage?;
|
|
32
|
+
private readonly memory;
|
|
33
|
+
private key?;
|
|
34
|
+
constructor(scope: string, storage?: ViewStorage | undefined);
|
|
35
|
+
private encryptionKey;
|
|
36
|
+
private id;
|
|
37
|
+
get<T extends Snapshot>(kind: Kind, account: string, version: bigint): Promise<T | undefined>;
|
|
38
|
+
set(kind: Kind, account: string, snapshot: Snapshot): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as anchor from "@anchor-lang/core";
|
|
2
|
+
import { type ViewKind } from "@depthhq/schema";
|
|
3
|
+
import { PublicKey, type Connection } from "@solana/web3.js";
|
|
4
|
+
import { type ViewStorage } from "./cache.js";
|
|
5
|
+
import { DepthView } from "./view.js";
|
|
6
|
+
export declare class ViewSession {
|
|
7
|
+
private readonly program;
|
|
8
|
+
private readonly connection;
|
|
9
|
+
private readonly owner;
|
|
10
|
+
private readonly serviceUrl;
|
|
11
|
+
private readonly scope;
|
|
12
|
+
private readonly storage?;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
constructor(program: anchor.Program, connection: Connection, owner: PublicKey, serviceUrl: string | undefined, scope: string, storage?: ViewStorage);
|
|
15
|
+
private identity;
|
|
16
|
+
private keys;
|
|
17
|
+
status(): Promise<{
|
|
18
|
+
active: boolean;
|
|
19
|
+
expiresAt?: number;
|
|
20
|
+
id: string;
|
|
21
|
+
}>;
|
|
22
|
+
private capability;
|
|
23
|
+
authorize(): Promise<void>;
|
|
24
|
+
revoke(): Promise<string>;
|
|
25
|
+
private post;
|
|
26
|
+
request(kind: ViewKind, source: PublicKey): Promise<DepthView>;
|
|
27
|
+
private read;
|
|
28
|
+
}
|
package/dist/view/view.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type BalanceSnapshot = {
|
|
|
4
4
|
status: "uninitialized" | "pending" | "ready" | "stale";
|
|
5
5
|
id: string;
|
|
6
6
|
version: bigint;
|
|
7
|
+
readAt?: number;
|
|
7
8
|
slot: number;
|
|
8
9
|
amount?: bigint;
|
|
9
10
|
};
|
|
@@ -11,6 +12,7 @@ export type PositionSnapshot = {
|
|
|
11
12
|
status: "pending" | "ready" | "stale";
|
|
12
13
|
id: string;
|
|
13
14
|
version: bigint;
|
|
15
|
+
readAt?: number;
|
|
14
16
|
slot: number;
|
|
15
17
|
collateral?: bigint;
|
|
16
18
|
reserved?: bigint;
|
|
@@ -49,11 +51,15 @@ export declare class DepthView {
|
|
|
49
51
|
private readonly mxePublicKey;
|
|
50
52
|
private readonly program;
|
|
51
53
|
private readonly connection;
|
|
52
|
-
|
|
54
|
+
private readonly source?;
|
|
55
|
+
private readonly release?;
|
|
56
|
+
constructor(id: PublicKey, signature: string, kind: "balance" | "market" | "fill" | "quote", owner: PublicKey, secret: Uint8Array, publicKey: Uint8Array, mxePublicKey: Uint8Array, program: anchor.Program, connection: Connection, source?: PublicKey | undefined, release?: (() => Promise<string>) | undefined);
|
|
53
57
|
status(): Promise<BalanceSnapshot | PositionSnapshot | FillSnapshot | QuoteBalanceSnapshot>;
|
|
54
58
|
wait(options: {
|
|
55
59
|
timeoutMs: number;
|
|
56
60
|
pollMs?: number;
|
|
57
61
|
}): Promise<BalanceSnapshot | PositionSnapshot | FillSnapshot | QuoteBalanceSnapshot>;
|
|
62
|
+
deferClose(): Promise<void>;
|
|
63
|
+
private closeBuilder;
|
|
58
64
|
close(): Promise<string>;
|
|
59
65
|
}
|
package/dist/view/view.js
CHANGED
|
@@ -26583,7 +26583,9 @@ class DepthView {
|
|
|
26583
26583
|
mxePublicKey;
|
|
26584
26584
|
program;
|
|
26585
26585
|
connection;
|
|
26586
|
-
|
|
26586
|
+
source;
|
|
26587
|
+
release;
|
|
26588
|
+
constructor(id, signature, kind, owner, secret, publicKey, mxePublicKey, program, connection, source, release) {
|
|
26587
26589
|
this.id = id;
|
|
26588
26590
|
this.signature = signature;
|
|
26589
26591
|
this.kind = kind;
|
|
@@ -26593,6 +26595,8 @@ class DepthView {
|
|
|
26593
26595
|
this.mxePublicKey = mxePublicKey;
|
|
26594
26596
|
this.program = program;
|
|
26595
26597
|
this.connection = connection;
|
|
26598
|
+
this.source = source;
|
|
26599
|
+
this.release = release;
|
|
26596
26600
|
}
|
|
26597
26601
|
async status() {
|
|
26598
26602
|
const response = await this.connection.getAccountInfoAndContext(this.id, "confirmed");
|
|
@@ -26603,6 +26607,9 @@ class DepthView {
|
|
|
26603
26607
|
if (!state.owner.equals(this.owner) || !Buffer.from(state.viewKey).equals(Buffer.from(this.publicKey))) {
|
|
26604
26608
|
throw new Error("Private view authorization does not match this request");
|
|
26605
26609
|
}
|
|
26610
|
+
const source = this.kind === "balance" ? state.balance : this.kind === "market" ? state.marketAccount : this.kind === "fill" ? state.order : state.quote;
|
|
26611
|
+
if (this.source && !source?.equals(this.source))
|
|
26612
|
+
throw new Error("Private view source does not match this request");
|
|
26606
26613
|
const current = Object.keys(state.status)[0];
|
|
26607
26614
|
if (current !== "pending" && current !== "ready" && current !== "stale") {
|
|
26608
26615
|
throw new Error("Private view has an unknown status");
|
|
@@ -26667,13 +26674,34 @@ class DepthView {
|
|
|
26667
26674
|
await new Promise((resolve) => setTimeout(resolve, Math.min(pollMs, deadline - Date.now())));
|
|
26668
26675
|
}
|
|
26669
26676
|
}
|
|
26677
|
+
async deferClose() {
|
|
26678
|
+
if (this.release) {
|
|
26679
|
+
await this.close();
|
|
26680
|
+
return;
|
|
26681
|
+
}
|
|
26682
|
+
const provider = this.program.provider;
|
|
26683
|
+
if (typeof provider.deferClose !== "function") {
|
|
26684
|
+
await this.close();
|
|
26685
|
+
return;
|
|
26686
|
+
}
|
|
26687
|
+
const snapshot = await this.status();
|
|
26688
|
+
if (snapshot.status === "pending")
|
|
26689
|
+
throw new Error("Private view computation is still pending");
|
|
26690
|
+
const instruction = await this.closeBuilder().instruction();
|
|
26691
|
+
provider.deferClose(this.id, instruction);
|
|
26692
|
+
}
|
|
26693
|
+
closeBuilder() {
|
|
26694
|
+
const builder = this.kind === "balance" ? this.program.methods.closeBalanceView() : this.kind === "market" ? this.program.methods.closeMarketView() : this.kind === "fill" ? this.program.methods.closeFillView() : this.program.methods.closeQuoteView();
|
|
26695
|
+
return builder.accountsPartial({ owner: this.owner, view: this.id });
|
|
26696
|
+
}
|
|
26670
26697
|
async close() {
|
|
26671
26698
|
const snapshot = await this.status();
|
|
26672
26699
|
if (snapshot.status === "pending") {
|
|
26673
26700
|
throw new Error("Private view computation is still pending");
|
|
26674
26701
|
}
|
|
26675
|
-
|
|
26676
|
-
|
|
26702
|
+
if (this.release)
|
|
26703
|
+
return this.release();
|
|
26704
|
+
return this.closeBuilder().rpc({ commitment: "confirmed" });
|
|
26677
26705
|
}
|
|
26678
26706
|
}
|
|
26679
26707
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depthhq/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -44,8 +44,11 @@
|
|
|
44
44
|
"@noble/hashes": "1.8.0",
|
|
45
45
|
"@solana/web3.js": "1.99.0",
|
|
46
46
|
"buffer": "6.0.3",
|
|
47
|
-
"@depthhq/bindings": "0.1.
|
|
48
|
-
"@depthhq/schema": "0.1.
|
|
47
|
+
"@depthhq/bindings": "0.1.2",
|
|
48
|
+
"@depthhq/schema": "0.1.2"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"fake-indexeddb": "6.2.4"
|
|
49
52
|
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"build": "node ../../scripts/build-package.mjs sdk",
|