Skip to content

Commit 77efa1c

Browse files
committed
refactor: refine decorated client API
1 parent a276370 commit 77efa1c

20 files changed

Lines changed: 1607 additions & 458 deletions

packages/client/src/actions/account.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export type FetchClosedOnlyModeError =
5555
* Fetches whether the account is restricted to closed-only trading.
5656
*
5757
* @throws {@link FetchClosedOnlyModeError}
58+
*
59+
* @example
60+
* ```ts
61+
* const closedOnly = await fetchClosedOnlyMode(client);
62+
* ```
5863
*/
5964
export async function fetchClosedOnlyMode(
6065
client: SecureClient,
@@ -164,6 +169,13 @@ export type FetchOrderError =
164169
* Fetches a single order for the authenticated account.
165170
*
166171
* @throws {@link FetchOrderError}
172+
*
173+
* @example
174+
* ```ts
175+
* const order = await fetchOrder(client, {
176+
* orderId: '123',
177+
* });
178+
* ```
167179
*/
168180
export async function fetchOrder(
169181
client: SecureClient,
@@ -283,6 +295,11 @@ export type DropNotificationsRequest = z.input<
283295
* Fetches notifications for the authenticated account.
284296
*
285297
* @throws {@link FetchNotificationsError}
298+
*
299+
* @example
300+
* ```ts
301+
* const notifications = await fetchNotifications(client);
302+
* ```
286303
*/
287304
export async function fetchNotifications(
288305
client: SecureClient,
@@ -470,6 +487,13 @@ export type FetchOrderScoringError =
470487
* Fetches whether a single order is currently scoring.
471488
*
472489
* @throws {@link FetchOrderScoringError}
490+
*
491+
* @example
492+
* ```ts
493+
* const scoring = await fetchOrderScoring(client, {
494+
* orderId: '123',
495+
* });
496+
* ```
473497
*/
474498
export async function fetchOrderScoring(
475499
client: SecureClient,
@@ -506,6 +530,13 @@ export type FetchOrdersScoringError =
506530
* Fetches scoring state for multiple orders.
507531
*
508532
* @throws {@link FetchOrdersScoringError}
533+
*
534+
* @example
535+
* ```ts
536+
* const scoring = await fetchOrdersScoring(client, {
537+
* orderIds: ['1', '2'],
538+
* });
539+
* ```
509540
*/
510541
export async function fetchOrdersScoring(
511542
client: SecureClient,
@@ -623,6 +654,13 @@ export type FetchTotalEarningsForUserForDayError =
623654
* Fetches total earnings for the authenticated account on a given day.
624655
*
625656
* @throws {@link FetchTotalEarningsForUserForDayError}
657+
*
658+
* @example
659+
* ```ts
660+
* const earnings = await fetchTotalEarningsForUserForDay(client, {
661+
* date: '2026-04-16',
662+
* });
663+
* ```
626664
*/
627665
export async function fetchTotalEarningsForUserForDay(
628666
client: SecureClient,
@@ -746,6 +784,11 @@ export type FetchRewardPercentagesError =
746784
* Fetches reward percentages for the authenticated account.
747785
*
748786
* @throws {@link FetchRewardPercentagesError}
787+
*
788+
* @example
789+
* ```ts
790+
* const percentages = await fetchRewardPercentages(client);
791+
* ```
749792
*/
750793
export async function fetchRewardPercentages(
751794
client: SecureClient,

packages/client/src/actions/approvals.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ export type PrepareErc20ApprovalError = UserInputError;
5454
*
5555
* @example
5656
* ```ts
57-
* const result = await prepareErc20Approval(client, {
57+
* const handle = await prepareErc20Approval(client, {
5858
* amount: 'max',
5959
* spenderAddress: '0x1234…',
6060
* tokenAddress: '0x5678…',
61-
* }).then(completeWith(walletClient));
61+
* }).then(completeWith(wallet));
62+
*
63+
* const outcome = await handle.wait();
64+
*
65+
* // outcome.transactionHash: TxHash
6266
* ```
6367
*
6468
* @throws {@link PrepareErc20ApprovalError}
@@ -124,10 +128,14 @@ export type PrepareErc1155ApprovalForAllError = UserInputError;
124128
*
125129
* @example
126130
* ```ts
127-
* const result = await prepareErc1155ApprovalForAll(client, {
131+
* const handle = await prepareErc1155ApprovalForAll(client, {
128132
* operatorAddress: '0x1234…',
129133
* tokenAddress: '0x5678…',
130-
* }).then(completeWith(walletClient));
134+
* }).then(completeWith(wallet));
135+
*
136+
* const outcome = await handle.wait();
137+
*
138+
* // outcome.transactionHash: TxHash
131139
* ```
132140
*
133141
* @throws {@link PrepareErc1155ApprovalForAllError}
@@ -193,7 +201,11 @@ export type PrepareTradingApprovalsError = UserInputError;
193201
*
194202
* @example
195203
* ```ts
196-
* const result = await prepareTradingApprovals(client).then(completeWith(walletClient));
204+
* const handle = await prepareTradingApprovals(client).then(completeWith(wallet));
205+
*
206+
* const outcome = await handle.wait();
207+
*
208+
* // outcome.transactionHash: TxHash
197209
* ```
198210
*
199211
* @throws {@link PrepareTradingApprovalsError}

packages/client/src/actions/clob.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import {
1313
fetchOrderBook,
1414
fetchOrderBooks,
1515
fetchPrice,
16+
fetchPriceHistory,
1617
fetchPrices,
1718
fetchSpread,
1819
fetchSpreads,
1920
fetchTickSize,
2021
listCurrentRewards,
2122
listMarketRewards,
22-
listPriceHistory,
2323
} from './clob';
2424
import { listMarkets } from './markets';
2525

@@ -201,11 +201,11 @@ describe('CLOB', () => {
201201
});
202202
});
203203

204-
describe('listPriceHistory', () => {
204+
describe('fetchPriceHistory', () => {
205205
it('lists historical price points for a token', async () => {
206206
const tokenId = await selectLiquidClobTokenId();
207207

208-
const result = await listPriceHistory(publicClient, {
208+
const result = await fetchPriceHistory(publicClient, {
209209
tokenId,
210210
interval: PriceHistoryInterval.ONE_DAY,
211211
fidelity: 60,

packages/client/src/actions/clob.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,39 +690,39 @@ const ListPriceHistoryRequestSchema = z.object({
690690
interval: PriceHistoryIntervalSchema.optional(),
691691
});
692692

693-
export type ListPriceHistoryRequest = z.input<
693+
export type FetchPriceHistoryRequest = z.input<
694694
typeof ListPriceHistoryRequestSchema
695695
>;
696696

697-
export type ListPriceHistoryError =
697+
export type FetchPriceHistoryError =
698698
| RateLimitError
699699
| RequestRejectedError
700700
| TransportError
701701
| UnexpectedResponseError
702702
| UserInputError;
703703

704704
/**
705-
* Lists historical price points for a token.
705+
* Fetches historical price points for a token.
706706
*
707-
* @throws {@link ListPriceHistoryError}
707+
* @throws {@link FetchPriceHistoryError}
708708
* Thrown on failure.
709709
*
710710
* @example
711711
* ```ts
712-
* const history = await listPriceHistory(client, {
712+
* const history = await fetchPriceHistory(client, {
713713
* tokenId:
714714
* '8501497159083948713316135768103773293754490207922884688769443031624417212426',
715715
* interval: PriceHistoryInterval.ONE_DAY,
716716
* fidelity: 60,
717717
* });
718718
*
719-
* // history[0] === { t: 1775653225, p: 0.535 }
719+
* // history === PriceHistoryPoint[]
720720
* ```
721721
*
722722
*/
723-
export async function listPriceHistory(
723+
export async function fetchPriceHistory(
724724
client: Client,
725-
request: ListPriceHistoryRequest,
725+
request: FetchPriceHistoryRequest,
726726
): Promise<PriceHistoryPoint[]> {
727727
const params = parseUserInput(request, ListPriceHistoryRequestSchema);
728728
const response = await unwrap(

packages/client/src/actions/gasless.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ export type IsGaslessReadyError =
148148
*
149149
* @throws {@link IsGaslessReadyError}
150150
* Thrown on failure.
151+
*
152+
* @example
153+
* ```ts
154+
* const ready = await isGaslessReady(client, {
155+
* wallet: '0x1234...',
156+
* });
157+
* ```
151158
*/
152159
export async function isGaslessReady(
153160
client: Client,
@@ -192,6 +199,15 @@ export type PrepareGaslessWalletError =
192199
*
193200
* @throws {@link PrepareGaslessWalletError}
194201
* Thrown on failure.
202+
*
203+
* @example
204+
* ```ts
205+
* const handle = await prepareGaslessWallet(client).then(completeWith(wallet));
206+
*
207+
* const outcome = await handle.wait();
208+
*
209+
* // outcome.transactionHash: TxHash
210+
* ```
195211
*/
196212
export async function prepareGaslessWallet(
197213
client: Client,

packages/client/src/actions/orders/cancel.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ export type CancelOrderError =
5252
*
5353
* @throws {@link CancelOrderError}
5454
* Thrown on failure.
55+
*
56+
* @example
57+
* ```ts
58+
* const response = await cancelOrder(client, {
59+
* orderId: '123',
60+
* });
61+
*
62+
* // response.canceled: string[]
63+
* ```
5564
*/
5665
export async function cancelOrder(
5766
client: SecureClient,
@@ -78,6 +87,15 @@ export type CancelOrdersError =
7887
*
7988
* @throws {@link CancelOrdersError}
8089
* Thrown on failure.
90+
*
91+
* @example
92+
* ```ts
93+
* const response = await cancelOrders(client, {
94+
* orderIds: ['1', '2'],
95+
* });
96+
*
97+
* // response.canceled: string[]
98+
* ```
8199
*/
82100
export async function cancelOrders(
83101
client: SecureClient,
@@ -100,6 +118,13 @@ export type CancelAllError =
100118
*
101119
* @throws {@link CancelAllError}
102120
* Thrown on failure.
121+
*
122+
* @example
123+
* ```ts
124+
* const response = await cancelAll(client);
125+
*
126+
* // response.canceled: string[]
127+
* ```
103128
*/
104129
export async function cancelAll(
105130
client: SecureClient,
@@ -124,6 +149,15 @@ export type CancelMarketOrdersError =
124149
*
125150
* @throws {@link CancelMarketOrdersError}
126151
* Thrown on failure.
152+
*
153+
* @example
154+
* ```ts
155+
* const response = await cancelMarketOrders(client, {
156+
* market: '0x0000000000000000000000000000000000000000000000000000000000000001',
157+
* });
158+
*
159+
* // response.canceled: string[]
160+
* ```
127161
*/
128162
export async function cancelMarketOrders(
129163
client: SecureClient,

packages/client/src/actions/orders/prepare.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ export type PrepareMarketOrderError =
5353
*
5454
* @throws {@link PrepareMarketOrderError}
5555
* Thrown on failure.
56+
*
57+
* @example
58+
* ```ts
59+
* const order = await prepareMarketOrder(client, {
60+
* amount: 10,
61+
* side: OrderSide.BUY,
62+
* tokenId: '123',
63+
* }).then(completeWith(wallet));
64+
*
65+
* const response = await postOrder(client, order);
66+
*
67+
* // response: OrderResponse
68+
* ```
5669
*/
5770
export async function prepareMarketOrder(
5871
client: SecureClient,
@@ -88,6 +101,20 @@ export type PrepareLimitOrderError =
88101
*
89102
* @throws {@link PrepareLimitOrderError}
90103
* Thrown on failure.
104+
*
105+
* @example
106+
* ```ts
107+
* const order = await prepareLimitOrder(client, {
108+
* price: 0.52,
109+
* side: OrderSide.BUY,
110+
* size: 10,
111+
* tokenId: '123',
112+
* }).then(completeWith(wallet));
113+
*
114+
* const response = await postOrder(client, order);
115+
*
116+
* // response: OrderResponse
117+
* ```
91118
*/
92119
export async function prepareLimitOrder(
93120
client: SecureClient,

0 commit comments

Comments
 (0)