@carrot-protocol/boost-http-client 0.4.8 → 0.5.0-bank-token-apy-timeseries-dev-4a1c04c
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/charting/bank/index.d.ts +4 -5
- package/dist/charting/bank/index.js +19 -9
- package/dist/index.d.ts +6 -2
- package/dist/index.js +27 -2
- package/dist/types.d.ts +37 -0
- package/package.json +1 -1
- package/src/charting/bank/index.ts +34 -15
- package/src/index.ts +44 -2
- package/src/types.ts +47 -0
- package/dist/charting/bank/types.d.ts +0 -5
- package/dist/charting/bank/types.js +0 -2
- package/src/charting/bank/types.ts +0 -5
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import {
|
|
3
|
-
import { DateRangeOptions } from "../../types";
|
|
2
|
+
import { ChartingOptions, GetBankApysResponse } from "../../types";
|
|
4
3
|
import { ApiClient } from "../../api";
|
|
5
4
|
export declare class BankChartingExtension extends ApiClient {
|
|
6
|
-
private readonly
|
|
7
|
-
constructor(baseUrl: string,
|
|
8
|
-
getApy(options?:
|
|
5
|
+
private readonly banks;
|
|
6
|
+
constructor(baseUrl: string, banks: web3.PublicKey[]);
|
|
7
|
+
getApy(options?: ChartingOptions): Promise<GetBankApysResponse>;
|
|
9
8
|
}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BankChartingExtension = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
4
5
|
const api_1 = require("../../api");
|
|
5
6
|
class BankChartingExtension extends api_1.ApiClient {
|
|
6
|
-
constructor(baseUrl,
|
|
7
|
+
constructor(baseUrl, banks) {
|
|
7
8
|
super(baseUrl);
|
|
8
|
-
this.
|
|
9
|
+
this.banks = banks;
|
|
9
10
|
}
|
|
10
11
|
async getApy(options = {}) {
|
|
11
|
-
const { fromTime, toTime } = options;
|
|
12
|
+
const { fromTime, toTime, aggregationMethod } = options;
|
|
12
13
|
const body = await this.handleApiCall(() => this.http.get(`/bank/apys`, {
|
|
13
14
|
params: {
|
|
14
|
-
|
|
15
|
+
banks: this.banks.map((b) => b.toString()).join(","),
|
|
15
16
|
fromTime: fromTime?.toISOString(),
|
|
16
17
|
toTime: toTime?.toISOString(),
|
|
18
|
+
aggregationMethod,
|
|
17
19
|
},
|
|
18
20
|
}));
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const jsonResponse = JSON.parse(body);
|
|
22
|
+
const response = {
|
|
23
|
+
banks: jsonResponse.banks.map((bankData) => ({
|
|
24
|
+
bank: new anchor_1.web3.PublicKey(bankData.bank),
|
|
25
|
+
mint: new anchor_1.web3.PublicKey(bankData.mint),
|
|
26
|
+
timeseries: bankData.timeseries.map((ts) => ({
|
|
27
|
+
time: new Date(ts.time),
|
|
28
|
+
supplyApy: Number(ts.supplyApy),
|
|
29
|
+
borrowApy: Number(ts.borrowApy),
|
|
30
|
+
utilizationRate: Number(ts.utilizationRate),
|
|
31
|
+
})),
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
24
34
|
return response;
|
|
25
35
|
}
|
|
26
36
|
}
|
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, GetWalletBalancesRequest, GetWalletBalancesResponse } from "./types";
|
|
2
|
+
import { GetBankResponse, GetUserResponse, GetGroupResponse, GetUserRequest, GetGroupsResponse, GetAccountResponse, GetAccountRequest, GetWalletBalancesRequest, GetWalletBalancesResponse, GetTokenApysRequest, GetTokenApysResponse } from "./types";
|
|
3
3
|
import { ApiClient } from "./api";
|
|
4
4
|
import { PositionChartingExtension } from "./charting/position";
|
|
5
5
|
import { BankChartingExtension } from "./charting/bank";
|
|
@@ -87,8 +87,12 @@ export declare class Client extends ApiClient {
|
|
|
87
87
|
* @returns Wallet balances grouped by group with timeseries data
|
|
88
88
|
*/
|
|
89
89
|
getWalletBalances(request?: GetWalletBalancesRequest): Promise<GetWalletBalancesResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Get token yield APY timeseries for one or more mints
|
|
92
|
+
*/
|
|
93
|
+
getTokenApys(request: GetTokenApysRequest): Promise<GetTokenApysResponse>;
|
|
90
94
|
getPerformanceChartingExtension(clendAccount: web3.PublicKey): Promise<PositionChartingExtension>;
|
|
91
95
|
getGroupChartingExtension(group: web3.PublicKey): Promise<GroupChartingExtension>;
|
|
92
96
|
getWalletChartingExtension(address?: web3.PublicKey): Promise<WalletChartingExtension>;
|
|
93
|
-
getBankChartingExtension(
|
|
97
|
+
getBankChartingExtension(banks: web3.PublicKey[]): Promise<BankChartingExtension>;
|
|
94
98
|
}
|
package/dist/index.js
CHANGED
|
@@ -507,6 +507,31 @@ class Client extends api_1.ApiClient {
|
|
|
507
507
|
};
|
|
508
508
|
return response;
|
|
509
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* Get token yield APY timeseries for one or more mints
|
|
512
|
+
*/
|
|
513
|
+
async getTokenApys(request) {
|
|
514
|
+
const { mints, fromTime, toTime, aggregationMethod } = request;
|
|
515
|
+
const body = await this.handleApiCall(() => this.http.get(`/token/apys`, {
|
|
516
|
+
params: {
|
|
517
|
+
mints: mints.map((m) => m.toString()).join(","),
|
|
518
|
+
fromTime: fromTime?.toISOString(),
|
|
519
|
+
toTime: toTime?.toISOString(),
|
|
520
|
+
aggregationMethod,
|
|
521
|
+
},
|
|
522
|
+
}));
|
|
523
|
+
const jsonResponse = JSON.parse(body);
|
|
524
|
+
const response = {
|
|
525
|
+
tokens: jsonResponse.tokens.map((tokenData) => ({
|
|
526
|
+
mint: new anchor_1.web3.PublicKey(tokenData.mint),
|
|
527
|
+
timeseries: tokenData.timeseries.map((ts) => ({
|
|
528
|
+
time: new Date(ts.time),
|
|
529
|
+
apy: Number(ts.apy),
|
|
530
|
+
})),
|
|
531
|
+
})),
|
|
532
|
+
};
|
|
533
|
+
return response;
|
|
534
|
+
}
|
|
510
535
|
async getPerformanceChartingExtension(clendAccount) {
|
|
511
536
|
return new position_1.PositionChartingExtension(this.baseUrl, clendAccount);
|
|
512
537
|
}
|
|
@@ -516,8 +541,8 @@ class Client extends api_1.ApiClient {
|
|
|
516
541
|
async getWalletChartingExtension(address) {
|
|
517
542
|
return new wallet_1.WalletChartingExtension(this.baseUrl, address ?? this.address());
|
|
518
543
|
}
|
|
519
|
-
async getBankChartingExtension(
|
|
520
|
-
return new bank_1.BankChartingExtension(this.baseUrl,
|
|
544
|
+
async getBankChartingExtension(banks) {
|
|
545
|
+
return new bank_1.BankChartingExtension(this.baseUrl, banks);
|
|
521
546
|
}
|
|
522
547
|
}
|
|
523
548
|
exports.Client = Client;
|
package/dist/types.d.ts
CHANGED
|
@@ -321,3 +321,40 @@ export interface GroupWalletBalances {
|
|
|
321
321
|
export interface GetWalletBalancesResponse {
|
|
322
322
|
groups: GroupWalletBalances[];
|
|
323
323
|
}
|
|
324
|
+
export interface GetBankApysRequest {
|
|
325
|
+
banks: web3.PublicKey[];
|
|
326
|
+
fromTime?: Date;
|
|
327
|
+
toTime?: Date;
|
|
328
|
+
aggregationMethod?: AggregationMethod;
|
|
329
|
+
}
|
|
330
|
+
export interface BankApyTimeseries {
|
|
331
|
+
time: Date;
|
|
332
|
+
supplyApy: number;
|
|
333
|
+
borrowApy: number;
|
|
334
|
+
utilizationRate: number;
|
|
335
|
+
}
|
|
336
|
+
export interface BankApysEntry {
|
|
337
|
+
bank: web3.PublicKey;
|
|
338
|
+
mint: web3.PublicKey;
|
|
339
|
+
timeseries: BankApyTimeseries[];
|
|
340
|
+
}
|
|
341
|
+
export interface GetBankApysResponse {
|
|
342
|
+
banks: BankApysEntry[];
|
|
343
|
+
}
|
|
344
|
+
export interface GetTokenApysRequest {
|
|
345
|
+
mints: web3.PublicKey[];
|
|
346
|
+
fromTime?: Date;
|
|
347
|
+
toTime?: Date;
|
|
348
|
+
aggregationMethod?: AggregationMethod;
|
|
349
|
+
}
|
|
350
|
+
export interface TokenApyTimeseries {
|
|
351
|
+
time: Date;
|
|
352
|
+
apy: number;
|
|
353
|
+
}
|
|
354
|
+
export interface TokenApysEntry {
|
|
355
|
+
mint: web3.PublicKey;
|
|
356
|
+
timeseries: TokenApyTimeseries[];
|
|
357
|
+
}
|
|
358
|
+
export interface GetTokenApysResponse {
|
|
359
|
+
tokens: TokenApysEntry[];
|
|
360
|
+
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,54 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
ChartingOptions,
|
|
4
|
+
GetBankApysResponse,
|
|
5
|
+
BankApysEntry,
|
|
6
|
+
BankApyTimeseries,
|
|
7
|
+
} from "../../types";
|
|
4
8
|
import { ApiClient } from "../../api";
|
|
5
9
|
|
|
6
10
|
export class BankChartingExtension extends ApiClient {
|
|
7
|
-
private readonly
|
|
11
|
+
private readonly banks: web3.PublicKey[];
|
|
8
12
|
|
|
9
|
-
constructor(baseUrl: string,
|
|
13
|
+
constructor(baseUrl: string, banks: web3.PublicKey[]) {
|
|
10
14
|
super(baseUrl);
|
|
11
|
-
this.
|
|
15
|
+
this.banks = banks;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
public async getApy(
|
|
15
|
-
|
|
18
|
+
public async getApy(
|
|
19
|
+
options: ChartingOptions = {},
|
|
20
|
+
): Promise<GetBankApysResponse> {
|
|
21
|
+
const { fromTime, toTime, aggregationMethod } = options;
|
|
16
22
|
const body = await this.handleApiCall(() =>
|
|
17
23
|
this.http.get(`/bank/apys`, {
|
|
18
24
|
params: {
|
|
19
|
-
|
|
25
|
+
banks: this.banks.map((b) => b.toString()).join(","),
|
|
20
26
|
fromTime: fromTime?.toISOString(),
|
|
21
27
|
toTime: toTime?.toISOString(),
|
|
28
|
+
aggregationMethod,
|
|
22
29
|
},
|
|
23
30
|
}),
|
|
24
31
|
);
|
|
25
32
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const jsonResponse: any = JSON.parse(body);
|
|
34
|
+
|
|
35
|
+
const response: GetBankApysResponse = {
|
|
36
|
+
banks: jsonResponse.banks.map(
|
|
37
|
+
(bankData: any): BankApysEntry => ({
|
|
38
|
+
bank: new web3.PublicKey(bankData.bank),
|
|
39
|
+
mint: new web3.PublicKey(bankData.mint),
|
|
40
|
+
timeseries: bankData.timeseries.map(
|
|
41
|
+
(ts: any): BankApyTimeseries => ({
|
|
42
|
+
time: new Date(ts.time),
|
|
43
|
+
supplyApy: Number(ts.supplyApy),
|
|
44
|
+
borrowApy: Number(ts.borrowApy),
|
|
45
|
+
utilizationRate: Number(ts.utilizationRate),
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
};
|
|
51
|
+
|
|
33
52
|
return response;
|
|
34
53
|
}
|
|
35
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,10 @@ import {
|
|
|
41
41
|
GroupWalletBalances,
|
|
42
42
|
WalletBalances,
|
|
43
43
|
WalletBalancesTimeseries,
|
|
44
|
+
GetTokenApysRequest,
|
|
45
|
+
GetTokenApysResponse,
|
|
46
|
+
TokenApysEntry,
|
|
47
|
+
TokenApyTimeseries,
|
|
44
48
|
} from "./types";
|
|
45
49
|
import encode from "bs58";
|
|
46
50
|
import { ApiClient } from "./api";
|
|
@@ -756,6 +760,44 @@ export class Client extends ApiClient {
|
|
|
756
760
|
return response;
|
|
757
761
|
}
|
|
758
762
|
|
|
763
|
+
/**
|
|
764
|
+
* Get token yield APY timeseries for one or more mints
|
|
765
|
+
*/
|
|
766
|
+
async getTokenApys(
|
|
767
|
+
request: GetTokenApysRequest,
|
|
768
|
+
): Promise<GetTokenApysResponse> {
|
|
769
|
+
const { mints, fromTime, toTime, aggregationMethod } = request;
|
|
770
|
+
|
|
771
|
+
const body = await this.handleApiCall(() =>
|
|
772
|
+
this.http.get(`/token/apys`, {
|
|
773
|
+
params: {
|
|
774
|
+
mints: mints.map((m) => m.toString()).join(","),
|
|
775
|
+
fromTime: fromTime?.toISOString(),
|
|
776
|
+
toTime: toTime?.toISOString(),
|
|
777
|
+
aggregationMethod,
|
|
778
|
+
},
|
|
779
|
+
}),
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
const jsonResponse: any = JSON.parse(body);
|
|
783
|
+
|
|
784
|
+
const response: GetTokenApysResponse = {
|
|
785
|
+
tokens: jsonResponse.tokens.map(
|
|
786
|
+
(tokenData: any): TokenApysEntry => ({
|
|
787
|
+
mint: new web3.PublicKey(tokenData.mint),
|
|
788
|
+
timeseries: tokenData.timeseries.map(
|
|
789
|
+
(ts: any): TokenApyTimeseries => ({
|
|
790
|
+
time: new Date(ts.time),
|
|
791
|
+
apy: Number(ts.apy),
|
|
792
|
+
}),
|
|
793
|
+
),
|
|
794
|
+
}),
|
|
795
|
+
),
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
return response;
|
|
799
|
+
}
|
|
800
|
+
|
|
759
801
|
public async getPerformanceChartingExtension(
|
|
760
802
|
clendAccount: web3.PublicKey,
|
|
761
803
|
): Promise<PositionChartingExtension> {
|
|
@@ -775,9 +817,9 @@ export class Client extends ApiClient {
|
|
|
775
817
|
}
|
|
776
818
|
|
|
777
819
|
public async getBankChartingExtension(
|
|
778
|
-
|
|
820
|
+
banks: web3.PublicKey[],
|
|
779
821
|
): Promise<BankChartingExtension> {
|
|
780
|
-
return new BankChartingExtension(this.baseUrl,
|
|
822
|
+
return new BankChartingExtension(this.baseUrl, banks);
|
|
781
823
|
}
|
|
782
824
|
}
|
|
783
825
|
|
package/src/types.ts
CHANGED
|
@@ -380,3 +380,50 @@ export interface GroupWalletBalances {
|
|
|
380
380
|
export interface GetWalletBalancesResponse {
|
|
381
381
|
groups: GroupWalletBalances[];
|
|
382
382
|
}
|
|
383
|
+
|
|
384
|
+
// Bank APY time-series
|
|
385
|
+
export interface GetBankApysRequest {
|
|
386
|
+
banks: web3.PublicKey[];
|
|
387
|
+
fromTime?: Date;
|
|
388
|
+
toTime?: Date;
|
|
389
|
+
aggregationMethod?: AggregationMethod;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface BankApyTimeseries {
|
|
393
|
+
time: Date;
|
|
394
|
+
supplyApy: number;
|
|
395
|
+
borrowApy: number;
|
|
396
|
+
utilizationRate: number;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface BankApysEntry {
|
|
400
|
+
bank: web3.PublicKey;
|
|
401
|
+
mint: web3.PublicKey;
|
|
402
|
+
timeseries: BankApyTimeseries[];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export interface GetBankApysResponse {
|
|
406
|
+
banks: BankApysEntry[];
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Token yield APY time-series
|
|
410
|
+
export interface GetTokenApysRequest {
|
|
411
|
+
mints: web3.PublicKey[];
|
|
412
|
+
fromTime?: Date;
|
|
413
|
+
toTime?: Date;
|
|
414
|
+
aggregationMethod?: AggregationMethod;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export interface TokenApyTimeseries {
|
|
418
|
+
time: Date;
|
|
419
|
+
apy: number;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export interface TokenApysEntry {
|
|
423
|
+
mint: web3.PublicKey;
|
|
424
|
+
timeseries: TokenApyTimeseries[];
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export interface GetTokenApysResponse {
|
|
428
|
+
tokens: TokenApysEntry[];
|
|
429
|
+
}
|