@totalis/hip4-client 0.0.0-stage → 0.65.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +1541 -0
  2. package/LICENSE +202 -0
  3. package/README.md +143 -2
  4. package/dist/api-keys.d.ts +118 -0
  5. package/dist/api-keys.js +104 -0
  6. package/dist/audience-contract.d.ts +52 -0
  7. package/dist/audience-contract.js +1 -0
  8. package/dist/base.d.ts +41 -0
  9. package/dist/base.js +60 -0
  10. package/dist/client.d.ts +16 -0
  11. package/dist/client.js +15 -0
  12. package/dist/controller.d.ts +50 -0
  13. package/dist/controller.js +60 -0
  14. package/dist/errors.d.ts +3 -0
  15. package/dist/errors.js +3 -0
  16. package/dist/flow-errors.d.ts +61 -0
  17. package/dist/flow-errors.js +70 -0
  18. package/dist/generated/account-read.d.ts +2009 -0
  19. package/dist/generated/account-read.js +1 -0
  20. package/dist/generated/api-keys.d.ts +1303 -0
  21. package/dist/generated/api-keys.js +1 -0
  22. package/dist/generated/browse.d.ts +938 -0
  23. package/dist/generated/browse.js +1 -0
  24. package/dist/generated/client.d.ts +73 -0
  25. package/dist/generated/client.js +1 -0
  26. package/dist/generated/errors.d.ts +404 -0
  27. package/dist/generated/errors.js +1342 -0
  28. package/dist/generated/maker.d.ts +47 -0
  29. package/dist/generated/maker.js +1 -0
  30. package/dist/generated/openapi.d.ts +8044 -0
  31. package/dist/generated/openapi.js +1 -0
  32. package/dist/generated/operator.d.ts +7 -0
  33. package/dist/generated/operator.js +1 -0
  34. package/dist/generated/realtime.d.ts +1416 -0
  35. package/dist/generated/realtime.js +1 -0
  36. package/dist/generated/vault-abi.d.ts +39 -0
  37. package/dist/generated/vault-abi.js +56 -0
  38. package/dist/generated/version.d.ts +23 -0
  39. package/dist/generated/version.js +143 -0
  40. package/dist/hypercore.d.ts +111 -0
  41. package/dist/hypercore.js +132 -0
  42. package/dist/maker.d.ts +205 -0
  43. package/dist/maker.js +608 -0
  44. package/dist/money.d.ts +59 -0
  45. package/dist/money.js +66 -0
  46. package/dist/operator.d.ts +4 -0
  47. package/dist/operator.js +4 -0
  48. package/dist/pagination.d.ts +20 -0
  49. package/dist/pagination.js +27 -0
  50. package/dist/partner.d.ts +59 -0
  51. package/dist/partner.js +57 -0
  52. package/dist/realtime.d.ts +19 -0
  53. package/dist/realtime.js +10 -0
  54. package/dist/request.d.ts +112 -0
  55. package/dist/request.js +187 -0
  56. package/dist/signer.d.ts +51 -0
  57. package/dist/signer.js +90 -0
  58. package/dist/stream.d.ts +133 -0
  59. package/dist/stream.js +318 -0
  60. package/dist/totalis.d.ts +656 -0
  61. package/dist/totalis.js +1160 -0
  62. package/dist/typed-data.d.ts +330 -0
  63. package/dist/typed-data.js +340 -0
  64. package/dist/ui.d.ts +54 -0
  65. package/dist/ui.js +77 -0
  66. package/dist/wallet-session.d.ts +45 -0
  67. package/dist/wallet-session.js +61 -0
  68. package/examples/browser-wallet.html +69 -0
  69. package/examples/browser-wallet.mjs +57 -0
  70. package/examples/node-bot.mjs +57 -0
  71. package/examples/onboard.mjs +132 -0
  72. package/examples/partner-frontend.mjs +44 -0
  73. package/examples/partner-server.mjs +22 -0
  74. package/package.json +104 -4
@@ -0,0 +1,205 @@
1
+ import { audienceClient, type AccessToken, type ApiClientOptions, type PublicEnvironment } from "./base.js";
2
+ import type { paths } from "./generated/maker.js";
3
+ import type { paths as ClientPaths } from "./generated/client.js";
4
+ import { type SignerInput } from "./signer.js";
5
+ import { TotalisStream, type StreamEventOf, type StreamOptions, type StreamSubscription } from "./stream.js";
6
+ import { type ResponseOf } from "./totalis.js";
7
+ import { type TransactionCall } from "./controller.js";
8
+ export type { components, operations, paths } from "./generated/maker.js";
9
+ export { controllerTransactions, encodeCall, openMakerVaultTransaction, type ControllerTransactions, type TransactionCall } from "./controller.js";
10
+ export declare function createMakerClient(environment: PublicEnvironment, options?: ApiClientOptions): import("openapi-fetch").Client<paths, `${string}/${string}`>;
11
+ type Ok<P extends keyof paths, M extends keyof paths[P], S extends number = 200> = ResponseOf<paths, P, M, S>;
12
+ export type Rfq = Ok<"/v1/rfqs/{rfq_id}", "get">;
13
+ export type EntryRfq = Extract<Rfq, {
14
+ readonly kind: "ENTRY";
15
+ }>;
16
+ export type CashoutRfq = Extract<Rfq, {
17
+ readonly kind: "CASHOUT";
18
+ }>;
19
+ /** An acceptance awaiting this maker's confirm, as QUOTE_ACCEPTED, the maker snapshot's `acceptances` and GET /v1/makers/{maker_id}/acceptances carry it. */
20
+ export type MakerAcceptance = StreamEventOf<"QUOTE_ACCEPTED">["payload"];
21
+ /** The acceptance after this maker's confirm or decline. */
22
+ export type Acceptance = Ok<"/v1/quotes/{quote_id}/confirm", "post">;
23
+ export type CollateralReduction = Ok<"/v1/makers/{maker_id}/collateral-reductions/{job_id}", "get">;
24
+ export type MakerWithdrawal = Ok<"/v1/makers/{maker_id}/withdrawal", "get">;
25
+ export type SelfFundedAccepted = Ok<"/v1/makers/{maker_id}/operations/{operation_id}/self-funded-transaction", "post", 202>;
26
+ export type Decision = "CONFIRM" | "DECLINE";
27
+ /** An RFQ as `onRfq` delivers it: open, as `GET /v1/rfqs/{rfq_id}` reads it. */
28
+ export type OpenedRfq = Rfq;
29
+ /**
30
+ * `quote` or `bid` on an RFQ where a taker's acceptance of this maker's quote
31
+ * awaits its answer. Publishing would replace that quote, which the venue
32
+ * refuses with 409 `STATE_CONFLICT`. Nothing was published: answer the
33
+ * acceptance (`confirm`, or `onAcceptance`) first, or let its deadline pass.
34
+ */
35
+ export declare class AcceptancePendingError extends Error {
36
+ readonly rfqId: string;
37
+ readonly quoteId: string;
38
+ readonly deadline: string;
39
+ readonly name = "AcceptancePendingError";
40
+ readonly code = "ACCEPTANCE_PENDING";
41
+ constructor(rfqId: string, quoteId: string, deadline: string);
42
+ }
43
+ export type MakerOptions = Omit<ApiClientOptions, "accessToken"> & {
44
+ readonly environment: PublicEnvironment;
45
+ /** The WebSocket origin for the stream. Defaults to `baseUrl` if set, else the environment's stream host (`wss://hip4-ws.totalis.trade` in production). */
46
+ readonly streamBaseUrl?: string;
47
+ /** The maker's scoped `ttk_` key. */
48
+ readonly apiKey: AccessToken;
49
+ readonly makerId: string;
50
+ /** The maker's current quote signer (`signer` in GET /v1/makers/{maker_id}/capital). Never stored. */
51
+ readonly signer: SignerInput;
52
+ /**
53
+ * Where this maker records the digests it publishes: the only terms its quote
54
+ * signer will sign. Defaults to memory; pass a durable store so a restarted or
55
+ * separate confirming process can answer quotes published elsewhere.
56
+ */
57
+ readonly published?: PublishedStore;
58
+ /** Resume the maker stream after this cursor: the stream replays the events after it. Persist `stream.cursor` to use it. */
59
+ readonly stream?: Omit<StreamOptions, "subscription" | "accessToken" | "environment" | "baseUrl" | "streamBaseUrl"> & {
60
+ readonly subscription?: Omit<Extract<StreamSubscription, {
61
+ readonly type: "maker";
62
+ }>, "type" | "maker_id">;
63
+ };
64
+ };
65
+ /** The maker-owned record of published digests and their expiry (unix seconds). */
66
+ export type PublishedStore = {
67
+ record(digest: string, expiry: number): void | Promise<void>;
68
+ forget(digest: string): void | Promise<void>;
69
+ expiry(digest: string): number | undefined | Promise<number | undefined>;
70
+ };
71
+ /** An in-memory store that drops entries a minute after they expire. */
72
+ export declare function memoryPublished(): PublishedStore;
73
+ /**
74
+ * The maker SDK over the public maker surface (the one Totalis MM uses):
75
+ * publish unsigned entry and cash-out quotes on one route, then confirm the
76
+ * exact terms a taker accepted when QUOTE_ACCEPTED arrives.
77
+ */
78
+ export declare function createMaker(options: MakerOptions): {
79
+ client: import("openapi-fetch").Client<paths, `${string}/${string}`>;
80
+ stream: TotalisStream;
81
+ deployment: () => Promise<{
82
+ readonly chain_id: import("./generated/openapi.js").components["schemas"]["UInt64String"];
83
+ readonly vault_address: import("./generated/openapi.js").components["schemas"]["LowercaseNonZeroAddress"];
84
+ readonly source_revision: string;
85
+ readonly audit_status: "PRE_AUDIT" | "AUDITED";
86
+ readonly fee_bps: number | null;
87
+ readonly taker_fee_bps: number | null;
88
+ readonly usdc: {
89
+ readonly address: import("./generated/openapi.js").components["schemas"]["LowercaseNonZeroAddress"];
90
+ readonly eip712_domain: {
91
+ readonly name: "USDC";
92
+ readonly version: "2";
93
+ readonly chain_id: import("./generated/openapi.js").components["schemas"]["UInt64String"];
94
+ readonly verifying_contract: import("./generated/openapi.js").components["schemas"]["LowercaseNonZeroAddress"];
95
+ };
96
+ };
97
+ }>;
98
+ quote: (rfq: Pick<EntryRfq, "rfq_id" | "taker" | "stake" | "legs">, terms: {
99
+ readonly payout: bigint | string;
100
+ readonly lifetimeSeconds?: number;
101
+ readonly salt?: string;
102
+ }) => Promise<{
103
+ quoteId: `0x${string}`;
104
+ entry: {
105
+ maker_id: string;
106
+ legs: {
107
+ readonly outcome_id: import("./generated/openapi.js").components["schemas"]["UInt32String"];
108
+ readonly side: import("./generated/openapi.js").components["schemas"]["Side"];
109
+ }[];
110
+ stake: string;
111
+ payout: string;
112
+ fee_bps: number;
113
+ taker_fee_bps: number;
114
+ taker: string;
115
+ expiry: string;
116
+ salt: string;
117
+ };
118
+ }>;
119
+ bid: (rfq: Pick<CashoutRfq, "rfq_id" | "position_id" | "owner" | "leg_state" | "maker_id">, terms: {
120
+ readonly price: bigint | string;
121
+ readonly lifetimeSeconds?: number;
122
+ readonly salt?: string;
123
+ }) => Promise<{
124
+ quote_id: import("./generated/openapi.js").components["schemas"]["Bytes32"];
125
+ sell_back: import("./generated/openapi.js").components["schemas"]["schemas-SellBackTerms"];
126
+ quoteId: string;
127
+ } | {
128
+ quote_id: import("./generated/openapi.js").components["schemas"]["Bytes32"];
129
+ transfer: import("./generated/openapi.js").components["schemas"]["schemas-TransferTerms"];
130
+ quoteId: string;
131
+ }>;
132
+ cancelQuote: (quoteId: string) => Promise<{
133
+ readonly status: "CANCELLED" | "REPLACED" | "ACCEPTED";
134
+ }>;
135
+ renewQuoteLease: (leaseMs: number) => Promise<{
136
+ readonly lease_ms: number;
137
+ readonly expires_at: import("./generated/openapi.js").components["schemas"]["$defs-Timestamp"];
138
+ }>;
139
+ releaseQuoteLease: () => Promise<{
140
+ readonly released: boolean;
141
+ }>;
142
+ keepQuoteLease: (leaseMs: number, onError?: (error: unknown) => void) => () => void;
143
+ confirm: (acceptance: MakerAcceptance, decision?: Decision) => Promise<Acceptance>;
144
+ onAcceptance: (handler: (acceptance: MakerAcceptance) => Decision | Promise<Decision>, onError?: (error: unknown, acceptance?: MakerAcceptance) => void) => () => void;
145
+ onRfq: (handler: (rfq: OpenedRfq) => unknown, onError?: (error: unknown) => void) => () => void;
146
+ controller: () => Promise<{
147
+ approveUsdc: (amount: string | bigint) => TransactionCall;
148
+ deposit: (amount: string | bigint) => TransactionCall;
149
+ requestWithdraw: (amount: string | bigint, to: string) => TransactionCall;
150
+ executeWithdraw: () => TransactionCall;
151
+ cancelWithdraw: () => TransactionCall;
152
+ resetDiscount: () => TransactionCall;
153
+ }>;
154
+ withdrawal: () => Promise<MakerWithdrawal>;
155
+ reduceCollateral: (request?: {
156
+ readonly signTransaction?: (call: TransactionCall) => Promise<string>;
157
+ readonly signal?: AbortSignal;
158
+ }) => Promise<{
159
+ readonly job: CollateralReduction;
160
+ readonly idempotencyKey: string;
161
+ readonly submitted?: SelfFundedAccepted;
162
+ }>;
163
+ close: () => void;
164
+ };
165
+ export type Maker = ReturnType<typeof createMaker>;
166
+ /** `GET /v1/me/maker`'s `ownership`: the account's maker as the venue has indexed it. */
167
+ export type MakerOwnership = ResponseOf<ClientPaths, "/v1/me/maker", "get", 200>["ownership"];
168
+ /**
169
+ * Where an account's maker stands in onboarding:
170
+ * - `READY`: admitted; issue its maker key and start quoting. `PENDING` after
171
+ * admission and `RESTRICTED` await or carry an operator decision.
172
+ * - `NOT_INDEXED`: no maker of the account's wallet is indexed yet. Right
173
+ * after `openMakerVaultTransaction` lands this lasts a few blocks; read
174
+ * again (`waitForMaker`). It also stays here if the transaction never landed,
175
+ * or if the maker's quote signer is not its controller.
176
+ * - `SETUP_REQUIRED`: indexed but not admitted, when `admit: false`.
177
+ * - `WALLET_REQUIRED`, `OWNERSHIP_CONFLICT`: the account has no single wallet
178
+ * that controls the maker; reading again will not change it.
179
+ */
180
+ export type MakerReadiness = {
181
+ readonly state: "READY" | "PENDING" | "RESTRICTED";
182
+ readonly makerId: string;
183
+ readonly ownership: MakerOwnership;
184
+ } | {
185
+ readonly state: "NOT_INDEXED" | "SETUP_REQUIRED" | "WALLET_REQUIRED" | "OWNERSHIP_CONFLICT";
186
+ readonly ownership: MakerOwnership;
187
+ };
188
+ /** The account's typed client (`createClient`, or `totalis.client`) under the session of the wallet that opened the maker. */
189
+ export type MakerOnboardingClient = ReturnType<typeof audienceClient<ClientPaths>>;
190
+ /**
191
+ * Read the account's maker (`GET /v1/me/maker`) and, once indexed or
192
+ * `PENDING`, admit it (`POST /v1/me/maker`, unless `admit: false`). Admission needs no signature
193
+ * and repeats safely. The POST's 404 (no maker indexed yet) is `NOT_INDEXED`,
194
+ * not an error.
195
+ */
196
+ export declare function makerReadiness(client: MakerOnboardingClient, options?: {
197
+ readonly admit?: boolean;
198
+ readonly signal?: AbortSignal;
199
+ }): Promise<MakerReadiness>;
200
+ /** `makerReadiness` again every `intervalMs` (default 3000) while `NOT_INDEXED`; resolves with the first other state. */
201
+ export declare function waitForMaker(client: MakerOnboardingClient, options?: {
202
+ readonly admit?: boolean;
203
+ readonly signal?: AbortSignal;
204
+ readonly intervalMs?: number;
205
+ }): Promise<MakerReadiness>;