@carrot-protocol/boost-http-client 0.4.0-stub-position-endpoints-dev-666335f → 0.4.0-stub-position-endpoints-dev-f996c8b

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.
@@ -1,11 +1,9 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { ApyResponse } from "./types";
3
+ import { DateRangeOptions } from "../../types";
3
4
  import { ApiClient } from "../../api";
4
5
  export declare class BankChartingExtension extends ApiClient {
5
6
  private readonly bank;
6
7
  constructor(baseUrl: string, bank: web3.PublicKey);
7
- getApy(options?: {
8
- fromTime?: Date;
9
- toTime?: Date;
10
- }): Promise<ApyResponse[]>;
8
+ getApy(options?: DateRangeOptions): Promise<ApyResponse[]>;
11
9
  }
@@ -8,11 +8,12 @@ class BankChartingExtension extends api_1.ApiClient {
8
8
  this.bank = bank;
9
9
  }
10
10
  async getApy(options = {}) {
11
+ const { fromTime, toTime } = options;
11
12
  const body = await this.handleApiCall(() => this.http.get(`/bank/apys`, {
12
13
  params: {
13
14
  bank: this.bank.toString(),
14
- fromTime: options.fromTime?.toISOString(),
15
- toTime: options.toTime?.toISOString(),
15
+ fromTime: fromTime?.toISOString(),
16
+ toTime: toTime?.toISOString(),
16
17
  },
17
18
  }));
18
19
  const response = JSON.parse(body).map((apy) => ({
@@ -1,11 +1,9 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { PerformanceResponse } from "./types";
3
3
  import { ApiClient } from "../../api";
4
+ import { DateRangeOptions } from "../../types";
4
5
  export declare class GroupChartingExtension extends ApiClient {
5
6
  private readonly group;
6
7
  constructor(baseUrl: string, group: web3.PublicKey);
7
- getPerformance(options?: {
8
- fromTime?: Date;
9
- toTime?: Date;
10
- }): Promise<PerformanceResponse[]>;
8
+ getPerformance(options?: DateRangeOptions): Promise<PerformanceResponse[]>;
11
9
  }
@@ -8,11 +8,12 @@ class GroupChartingExtension extends api_1.ApiClient {
8
8
  this.group = group;
9
9
  }
10
10
  async getPerformance(options = {}) {
11
+ const { fromTime, toTime } = options;
11
12
  const body = await this.handleApiCall(() => this.http.get(`/group/pnls`, {
12
13
  params: {
13
14
  group: this.group.toString(),
14
- fromTime: options.fromTime?.toISOString(),
15
- toTime: options.toTime?.toISOString(),
15
+ fromTime: fromTime?.toISOString(),
16
+ toTime: toTime?.toISOString(),
16
17
  },
17
18
  }));
18
19
  const response = JSON.parse(body).map((performance) => ({
@@ -1,5 +1,6 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { ApyResponse, LoanBalanceResponse, PerformanceResponse } from "./types";
3
+ import { ChartingOptions } from "../../types";
3
4
  import { ApiClient } from "../../api";
4
5
  export declare class PositionChartingExtension extends ApiClient {
5
6
  private readonly clendAccount;
@@ -8,12 +9,6 @@ export declare class PositionChartingExtension extends ApiClient {
8
9
  fromTime?: Date;
9
10
  toTime?: Date;
10
11
  }): Promise<LoanBalanceResponse[]>;
11
- getPerformance(options?: {
12
- fromTime?: Date;
13
- toTime?: Date;
14
- }): Promise<PerformanceResponse[]>;
15
- getApy(options?: {
16
- fromTime?: Date;
17
- toTime?: Date;
18
- }): Promise<ApyResponse[]>;
12
+ getPerformance(options?: ChartingOptions): Promise<PerformanceResponse[]>;
13
+ getApy(options?: ChartingOptions): Promise<ApyResponse[]>;
19
14
  }
@@ -25,11 +25,13 @@ class PositionChartingExtension extends api_1.ApiClient {
25
25
  return response;
26
26
  }
27
27
  async getPerformance(options = {}) {
28
+ const { fromTime, toTime, aggregationMethod } = options;
28
29
  const body = await this.handleApiCall(() => this.http.get(`/account/performance`, {
29
30
  params: {
30
31
  account: this.clendAccount.toString(),
31
- fromTime: options.fromTime?.toISOString(),
32
- toTime: options.toTime?.toISOString(),
32
+ fromTime: fromTime?.toISOString(),
33
+ toTime: toTime?.toISOString(),
34
+ aggregationMethod,
33
35
  },
34
36
  }));
35
37
  const response = JSON.parse(body).map((performance) => ({
@@ -41,11 +43,13 @@ class PositionChartingExtension extends api_1.ApiClient {
41
43
  return response;
42
44
  }
43
45
  async getApy(options = {}) {
46
+ const { fromTime, toTime, aggregationMethod } = options;
44
47
  const body = await this.handleApiCall(() => this.http.get(`/account/apys`, {
45
48
  params: {
46
49
  account: this.clendAccount.toString(),
47
- fromTime: options.fromTime?.toISOString(),
48
- toTime: options.toTime?.toISOString(),
50
+ fromTime: fromTime?.toISOString(),
51
+ toTime: toTime?.toISOString(),
52
+ aggregationMethod,
49
53
  },
50
54
  }));
51
55
  const response = JSON.parse(body).map((apy) => ({
@@ -1,11 +1,9 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { PerformanceResponse } from "./types";
3
3
  import { ApiClient } from "../../api";
4
+ import { DateRangeOptions } from "../../types";
4
5
  export declare class WalletChartingExtension extends ApiClient {
5
6
  private readonly address;
6
7
  constructor(baseUrl: string, address: web3.PublicKey);
7
- getPerformance(options?: {
8
- fromTime?: Date;
9
- toTime?: Date;
10
- }): Promise<PerformanceResponse[]>;
8
+ getPerformance(options?: DateRangeOptions): Promise<PerformanceResponse[]>;
11
9
  }
@@ -8,11 +8,12 @@ class WalletChartingExtension extends api_1.ApiClient {
8
8
  this.address = address;
9
9
  }
10
10
  async getPerformance(options = {}) {
11
+ const { fromTime, toTime } = options;
11
12
  const body = await this.handleApiCall(() => this.http.get(`/user/pnls`, {
12
13
  params: {
13
14
  authority: this.address.toString(),
14
- fromTime: options.fromTime?.toISOString(),
15
- toTime: options.toTime?.toISOString(),
15
+ fromTime: fromTime?.toISOString(),
16
+ toTime: toTime?.toISOString(),
16
17
  },
17
18
  }));
18
19
  const response = JSON.parse(body).map((performance) => ({
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AnchorProvider, web3 } from "@coral-xyz/anchor";
2
- import { GetBankResponse, GetUserResponse, GetGroupResponse, GetUserRequest, GetGroupsResponse, GetAccountResponse, GetAccountRequest, ExtensionKey } from "./types";
2
+ import { GetBankResponse, GetUserResponse, GetGroupResponse, GetUserRequest, GetGroupsResponse, GetAccountResponse, GetAccountRequest } from "./types";
3
3
  import { ApiClient } from "./api";
4
4
  import { PositionChartingExtension } from "./charting/position";
5
5
  import { BankChartingExtension } from "./charting/bank";
@@ -79,5 +79,8 @@ export declare class Client extends ApiClient {
79
79
  * @returns Withdraw emissions operation result
80
80
  */
81
81
  withdrawEmissions(clendAccount: web3.PublicKey): Promise<string>;
82
- getExtension(extension: ExtensionKey): Promise<((clendAccount: web3.PublicKey) => PositionChartingExtension) | ((group: web3.PublicKey) => GroupChartingExtension) | ((address?: web3.PublicKey) => WalletChartingExtension) | ((bank: web3.PublicKey) => BankChartingExtension)>;
82
+ getPerformanceChartingExtension(clendAccount: web3.PublicKey): Promise<PositionChartingExtension>;
83
+ getGroupChartingExtension(group: web3.PublicKey): Promise<GroupChartingExtension>;
84
+ getWalletChartingExtension(address?: web3.PublicKey): Promise<WalletChartingExtension>;
85
+ getBankChartingExtension(bank: web3.PublicKey): Promise<BankChartingExtension>;
83
86
  }
package/dist/index.js CHANGED
@@ -428,19 +428,17 @@ class Client extends api_1.ApiClient {
428
428
  const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId);
429
429
  return txSig;
430
430
  }
431
- async getExtension(extension) {
432
- switch (extension) {
433
- case "positionCharting":
434
- return (clendAccount) => new position_1.PositionChartingExtension(this.baseUrl, clendAccount);
435
- case "groupCharting":
436
- return (group) => new group_1.GroupChartingExtension(this.baseUrl, group);
437
- case "walletCharting":
438
- return (address) => new wallet_1.WalletChartingExtension(this.baseUrl, address ?? this.address());
439
- case "bankCharting":
440
- return (bank) => new bank_1.BankChartingExtension(this.baseUrl, bank);
441
- default:
442
- throw new Error(`Unknown extension: ${extension}`);
443
- }
431
+ async getPerformanceChartingExtension(clendAccount) {
432
+ return new position_1.PositionChartingExtension(this.baseUrl, clendAccount);
433
+ }
434
+ async getGroupChartingExtension(group) {
435
+ return new group_1.GroupChartingExtension(this.baseUrl, group);
436
+ }
437
+ async getWalletChartingExtension(address) {
438
+ return new wallet_1.WalletChartingExtension(this.baseUrl, address ?? this.address());
439
+ }
440
+ async getBankChartingExtension(bank) {
441
+ return new bank_1.BankChartingExtension(this.baseUrl, bank);
444
442
  }
445
443
  }
446
444
  exports.Client = Client;
package/dist/types.d.ts CHANGED
@@ -251,5 +251,13 @@ export interface UserRequest {
251
251
  openPosition: boolean | null;
252
252
  closePosition: boolean | null;
253
253
  }
254
+ export type DateRangeOptions = {
255
+ fromTime?: Date;
256
+ toTime?: Date;
257
+ };
258
+ export type AggregationMethod = "average" | "endOfDay" | "startOfDay";
259
+ export type ChartingOptions = DateRangeOptions & {
260
+ aggregationMethod?: AggregationMethod;
261
+ };
254
262
  export type ExtensionKey = "positionCharting" | "groupCharting" | "walletCharting" | "bankCharting";
255
263
  export type Extension = InstanceType<typeof PositionChartingExtension> | InstanceType<typeof GroupChartingExtension> | InstanceType<typeof WalletChartingExtension> | InstanceType<typeof BankChartingExtension>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.4.0-stub-position-endpoints-dev-666335f",
3
+ "version": "0.4.0-stub-position-endpoints-dev-f996c8b",
4
4
  "description": "HTTP client for Carrot Boost",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { ApyResponse } from "./types";
3
+ import { DateRangeOptions } from "../../types";
3
4
  import { ApiClient } from "../../api";
4
5
 
5
6
  export class BankChartingExtension extends ApiClient {
@@ -10,15 +11,14 @@ export class BankChartingExtension extends ApiClient {
10
11
  this.bank = bank;
11
12
  }
12
13
 
13
- public async getApy(
14
- options: { fromTime?: Date; toTime?: Date } = {},
15
- ): Promise<ApyResponse[]> {
14
+ public async getApy(options: DateRangeOptions = {}): Promise<ApyResponse[]> {
15
+ const { fromTime, toTime } = options;
16
16
  const body = await this.handleApiCall(() =>
17
17
  this.http.get(`/bank/apys`, {
18
18
  params: {
19
19
  bank: this.bank.toString(),
20
- fromTime: options.fromTime?.toISOString(),
21
- toTime: options.toTime?.toISOString(),
20
+ fromTime: fromTime?.toISOString(),
21
+ toTime: toTime?.toISOString(),
22
22
  },
23
23
  }),
24
24
  );
@@ -1,6 +1,7 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { PerformanceResponse } from "./types";
3
3
  import { ApiClient } from "../../api";
4
+ import { DateRangeOptions } from "../../types";
4
5
 
5
6
  export class GroupChartingExtension extends ApiClient {
6
7
  private readonly group: web3.PublicKey;
@@ -11,14 +12,15 @@ export class GroupChartingExtension extends ApiClient {
11
12
  }
12
13
 
13
14
  public async getPerformance(
14
- options: { fromTime?: Date; toTime?: Date } = {},
15
+ options: DateRangeOptions = {},
15
16
  ): Promise<PerformanceResponse[]> {
17
+ const { fromTime, toTime } = options;
16
18
  const body = await this.handleApiCall(() =>
17
19
  this.http.get(`/group/pnls`, {
18
20
  params: {
19
21
  group: this.group.toString(),
20
- fromTime: options.fromTime?.toISOString(),
21
- toTime: options.toTime?.toISOString(),
22
+ fromTime: fromTime?.toISOString(),
23
+ toTime: toTime?.toISOString(),
22
24
  },
23
25
  }),
24
26
  );
@@ -1,5 +1,6 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { ApyResponse, LoanBalanceResponse, PerformanceResponse } from "./types";
3
+ import { ChartingOptions } from "../../types";
3
4
  import { ApiClient } from "../../api";
4
5
 
5
6
  export class PositionChartingExtension extends ApiClient {
@@ -42,14 +43,16 @@ export class PositionChartingExtension extends ApiClient {
42
43
  }
43
44
 
44
45
  public async getPerformance(
45
- options: { fromTime?: Date; toTime?: Date } = {},
46
+ options: ChartingOptions = {},
46
47
  ): Promise<PerformanceResponse[]> {
48
+ const { fromTime, toTime, aggregationMethod } = options;
47
49
  const body = await this.handleApiCall(() =>
48
50
  this.http.get(`/account/performance`, {
49
51
  params: {
50
52
  account: this.clendAccount.toString(),
51
- fromTime: options.fromTime?.toISOString(),
52
- toTime: options.toTime?.toISOString(),
53
+ fromTime: fromTime?.toISOString(),
54
+ toTime: toTime?.toISOString(),
55
+ aggregationMethod,
53
56
  },
54
57
  }),
55
58
  );
@@ -70,15 +73,15 @@ export class PositionChartingExtension extends ApiClient {
70
73
  return response;
71
74
  }
72
75
 
73
- public async getApy(
74
- options: { fromTime?: Date; toTime?: Date } = {},
75
- ): Promise<ApyResponse[]> {
76
+ public async getApy(options: ChartingOptions = {}): Promise<ApyResponse[]> {
77
+ const { fromTime, toTime, aggregationMethod } = options;
76
78
  const body = await this.handleApiCall(() =>
77
79
  this.http.get(`/account/apys`, {
78
80
  params: {
79
81
  account: this.clendAccount.toString(),
80
- fromTime: options.fromTime?.toISOString(),
81
- toTime: options.toTime?.toISOString(),
82
+ fromTime: fromTime?.toISOString(),
83
+ toTime: toTime?.toISOString(),
84
+ aggregationMethod,
82
85
  },
83
86
  }),
84
87
  );
@@ -1,6 +1,7 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { PerformanceResponse } from "./types";
3
3
  import { ApiClient } from "../../api";
4
+ import { DateRangeOptions } from "../../types";
4
5
 
5
6
  export class WalletChartingExtension extends ApiClient {
6
7
  private readonly address: web3.PublicKey;
@@ -11,14 +12,15 @@ export class WalletChartingExtension extends ApiClient {
11
12
  }
12
13
 
13
14
  public async getPerformance(
14
- options: { fromTime?: Date; toTime?: Date } = {},
15
+ options: DateRangeOptions = {},
15
16
  ): Promise<PerformanceResponse[]> {
17
+ const { fromTime, toTime } = options;
16
18
  const body = await this.handleApiCall(() =>
17
19
  this.http.get(`/user/pnls`, {
18
20
  params: {
19
21
  authority: this.address.toString(),
20
- fromTime: options.fromTime?.toISOString(),
21
- toTime: options.toTime?.toISOString(),
22
+ fromTime: fromTime?.toISOString(),
23
+ toTime: toTime?.toISOString(),
22
24
  },
23
25
  }),
24
26
  );
package/src/index.ts CHANGED
@@ -606,23 +606,28 @@ export class Client extends ApiClient {
606
606
  return txSig;
607
607
  }
608
608
 
609
- public async getExtension(extension: ExtensionKey) {
610
- switch (extension) {
611
- case "positionCharting":
612
- return (clendAccount: web3.PublicKey) =>
613
- new PositionChartingExtension(this.baseUrl, clendAccount);
614
- case "groupCharting":
615
- return (group: web3.PublicKey) =>
616
- new GroupChartingExtension(this.baseUrl, group);
617
- case "walletCharting":
618
- return (address?: web3.PublicKey) =>
619
- new WalletChartingExtension(this.baseUrl, address ?? this.address());
620
- case "bankCharting":
621
- return (bank: web3.PublicKey) =>
622
- new BankChartingExtension(this.baseUrl, bank);
623
- default:
624
- throw new Error(`Unknown extension: ${extension}`);
625
- }
609
+ public async getPerformanceChartingExtension(
610
+ clendAccount: web3.PublicKey,
611
+ ): Promise<PositionChartingExtension> {
612
+ return new PositionChartingExtension(this.baseUrl, clendAccount);
613
+ }
614
+
615
+ public async getGroupChartingExtension(
616
+ group: web3.PublicKey,
617
+ ): Promise<GroupChartingExtension> {
618
+ return new GroupChartingExtension(this.baseUrl, group);
619
+ }
620
+
621
+ public async getWalletChartingExtension(
622
+ address?: web3.PublicKey,
623
+ ): Promise<WalletChartingExtension> {
624
+ return new WalletChartingExtension(this.baseUrl, address ?? this.address());
625
+ }
626
+
627
+ public async getBankChartingExtension(
628
+ bank: web3.PublicKey,
629
+ ): Promise<BankChartingExtension> {
630
+ return new BankChartingExtension(this.baseUrl, bank);
626
631
  }
627
632
  }
628
633
 
package/src/types.ts CHANGED
@@ -288,6 +288,17 @@ export interface UserRequest {
288
288
  closePosition: boolean | null;
289
289
  }
290
290
 
291
+ export type DateRangeOptions = {
292
+ fromTime?: Date;
293
+ toTime?: Date;
294
+ };
295
+
296
+ export type AggregationMethod = "average" | "endOfDay" | "startOfDay";
297
+
298
+ export type ChartingOptions = DateRangeOptions & {
299
+ aggregationMethod?: AggregationMethod;
300
+ };
301
+
291
302
  export type ExtensionKey =
292
303
  | "positionCharting"
293
304
  | "groupCharting"