@carrot-protocol/boost-http-client 0.4.0-stub-position-endpoints-dev-be5af0a → 0.4.0-stub-position-endpoints-dev-32fcd57

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,19 +1,11 @@
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;
6
7
  constructor(baseUrl: string, clendAccount: web3.PublicKey);
7
- getLoanBalance(options?: {
8
- fromTime?: Date;
9
- toTime?: Date;
10
- }): 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[]>;
8
+ getLoanBalance(options?: ChartingOptions): Promise<LoanBalanceResponse[]>;
9
+ getPerformance(options?: ChartingOptions): Promise<PerformanceResponse[]>;
10
+ getApy(options?: ChartingOptions): Promise<ApyResponse[]>;
19
11
  }
@@ -8,11 +8,13 @@ class PositionChartingExtension extends api_1.ApiClient {
8
8
  this.clendAccount = clendAccount;
9
9
  }
10
10
  async getLoanBalance(options = {}) {
11
+ const { fromTime, toTime, aggregationMethod } = options;
11
12
  const body = await this.handleApiCall(() => this.http.get(`/account/balances`, {
12
13
  params: {
13
14
  account: this.clendAccount.toString(),
14
- fromTime: options.fromTime?.toISOString(),
15
- toTime: options.toTime?.toISOString(),
15
+ fromTime: fromTime?.toISOString(),
16
+ toTime: toTime?.toISOString(),
17
+ aggregationMethod,
16
18
  },
17
19
  }));
18
20
  const response = JSON.parse(body).map((balance) => ({
@@ -25,11 +27,13 @@ class PositionChartingExtension extends api_1.ApiClient {
25
27
  return response;
26
28
  }
27
29
  async getPerformance(options = {}) {
30
+ const { fromTime, toTime, aggregationMethod } = options;
28
31
  const body = await this.handleApiCall(() => this.http.get(`/account/performance`, {
29
32
  params: {
30
33
  account: this.clendAccount.toString(),
31
- fromTime: options.fromTime?.toISOString(),
32
- toTime: options.toTime?.toISOString(),
34
+ fromTime: fromTime?.toISOString(),
35
+ toTime: toTime?.toISOString(),
36
+ aggregationMethod,
33
37
  },
34
38
  }));
35
39
  const response = JSON.parse(body).map((performance) => ({
@@ -41,11 +45,13 @@ class PositionChartingExtension extends api_1.ApiClient {
41
45
  return response;
42
46
  }
43
47
  async getApy(options = {}) {
48
+ const { fromTime, toTime, aggregationMethod } = options;
44
49
  const body = await this.handleApiCall(() => this.http.get(`/account/apys`, {
45
50
  params: {
46
51
  account: this.clendAccount.toString(),
47
- fromTime: options.fromTime?.toISOString(),
48
- toTime: options.toTime?.toISOString(),
52
+ fromTime: fromTime?.toISOString(),
53
+ toTime: toTime?.toISOString(),
54
+ aggregationMethod,
49
55
  },
50
56
  }));
51
57
  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/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-be5af0a",
3
+ "version": "0.4.0-stub-position-endpoints-dev-32fcd57",
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 {
@@ -11,14 +12,16 @@ export class PositionChartingExtension extends ApiClient {
11
12
  }
12
13
 
13
14
  public async getLoanBalance(
14
- options: { fromTime?: Date; toTime?: Date } = {},
15
+ options: ChartingOptions = {},
15
16
  ): Promise<LoanBalanceResponse[]> {
17
+ const { fromTime, toTime, aggregationMethod } = options;
16
18
  const body = await this.handleApiCall(() =>
17
19
  this.http.get(`/account/balances`, {
18
20
  params: {
19
21
  account: this.clendAccount.toString(),
20
- fromTime: options.fromTime?.toISOString(),
21
- toTime: options.toTime?.toISOString(),
22
+ fromTime: fromTime?.toISOString(),
23
+ toTime: toTime?.toISOString(),
24
+ aggregationMethod,
22
25
  },
23
26
  }),
24
27
  );
@@ -42,14 +45,16 @@ export class PositionChartingExtension extends ApiClient {
42
45
  }
43
46
 
44
47
  public async getPerformance(
45
- options: { fromTime?: Date; toTime?: Date } = {},
48
+ options: ChartingOptions = {},
46
49
  ): Promise<PerformanceResponse[]> {
50
+ const { fromTime, toTime, aggregationMethod } = options;
47
51
  const body = await this.handleApiCall(() =>
48
52
  this.http.get(`/account/performance`, {
49
53
  params: {
50
54
  account: this.clendAccount.toString(),
51
- fromTime: options.fromTime?.toISOString(),
52
- toTime: options.toTime?.toISOString(),
55
+ fromTime: fromTime?.toISOString(),
56
+ toTime: toTime?.toISOString(),
57
+ aggregationMethod,
53
58
  },
54
59
  }),
55
60
  );
@@ -70,15 +75,15 @@ export class PositionChartingExtension extends ApiClient {
70
75
  return response;
71
76
  }
72
77
 
73
- public async getApy(
74
- options: { fromTime?: Date; toTime?: Date } = {},
75
- ): Promise<ApyResponse[]> {
78
+ public async getApy(options: ChartingOptions = {}): Promise<ApyResponse[]> {
79
+ const { fromTime, toTime, aggregationMethod } = options;
76
80
  const body = await this.handleApiCall(() =>
77
81
  this.http.get(`/account/apys`, {
78
82
  params: {
79
83
  account: this.clendAccount.toString(),
80
- fromTime: options.fromTime?.toISOString(),
81
- toTime: options.toTime?.toISOString(),
84
+ fromTime: fromTime?.toISOString(),
85
+ toTime: toTime?.toISOString(),
86
+ aggregationMethod,
82
87
  },
83
88
  }),
84
89
  );
@@ -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/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"