Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vaults indexer endpoints #252

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 71 additions & 10 deletions v4-client-js/__native__/__ios__/v4-native-client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v4-client-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export enum TimePeriod {
SEVEN_DAYS = 'SEVEN_DAYS',
}

export enum PnlTickInterval {
HOUR = "hour",
day = "day",
}

// ------------ API Defaults ------------
export const DEFAULT_API_TIMEOUT: number = 3_000;

Expand Down
12 changes: 12 additions & 0 deletions v4-client-js/src/clients/indexer-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IndexerConfig, DEFAULT_API_TIMEOUT } from './constants';
import AccountClient from './modules/account';
import MarketsClient from './modules/markets';
import UtilityClient from './modules/utility';
import VaultClient from './modules/vault';

/**
* @description Client for Indexer
Expand All @@ -12,6 +13,7 @@ export class IndexerClient {
readonly _markets: MarketsClient;
readonly _account: AccountClient;
readonly _utility: UtilityClient;
readonly _vault: VaultClient;

constructor(config: IndexerConfig, apiTimeout?: number) {
this.config = config;
Expand All @@ -20,6 +22,7 @@ export class IndexerClient {
this._markets = new MarketsClient(config.restEndpoint);
this._account = new AccountClient(config.restEndpoint);
this._utility = new UtilityClient(config.restEndpoint);
this._vault = new VaultClient(config.restEndpoint);
}

/**
Expand All @@ -46,4 +49,13 @@ export class IndexerClient {
get utility(): UtilityClient {
return this._utility;
}

/**
* @description Get the vault module, used for interacting with vault endpoints.
*
* @returns The vault module
*/
get vault(): VaultClient {
return this._vault;
}
}
19 changes: 19 additions & 0 deletions v4-client-js/src/clients/modules/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,23 @@ export default class AccountClient extends RestClient {
page,
});
}

async getTransfersBetween(
sourceAddress: string,
sourceSubaccountNumber: string,
recipientAddress: string,
recipientSubaccountNumber: string,
createdBeforeOrAtHeight?: number | null,
createdBeforeOrAt?: string | null
): Promise<Data> {
const uri = '/v4/transfers/between';
return this.get(uri, {
sourceAddress,
sourceSubaccountNumber,
recipientAddress,
recipientSubaccountNumber,
createdBeforeOrAtHeight,
createdBeforeOrAt,
});
}
}
23 changes: 23 additions & 0 deletions v4-client-js/src/clients/modules/vault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PnlTickInterval } from '../constants';
import { Data } from '../types';
import RestClient from './rest';

/**
* @description REST endpoints for data unrelated to a particular address.
*/
export default class VaultClient extends RestClient {
async getMegavaultHistoricalPnl(resolution?: PnlTickInterval | null): Promise<Data> {
const uri = '/v4/vault/v1/megavault/historicalPnl';
return this.get(uri, { resolution });
}

async getVaultsHistoricalPnl(resolution?: PnlTickInterval | null): Promise<Data> {
const uri = '/v4/vault/v1/vaults/historicalPnl';
return this.get(uri, { resolution });
}

async getMegavaultPositions(): Promise<Data> {
const uri = '/v4/vault/v1/megavault/positions';
return this.get(uri);
}
}
Loading