Skip to content

Commit

Permalink
[CLOB-795] Update js client with equity tier limit configuration acce…
Browse files Browse the repository at this point in the history
…ssor. (#3)

* [CLOB-795] Update js client with equity tier limit configuration accessor.
  • Loading branch information
lcwik authored Aug 16, 2023
1 parent b551537 commit 424f349
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ describe('Validator Client', () => {
expect(prices.marketPrices).not.toBeUndefined();
expect(prices.marketPrices[0].id).toBe(0);
});

it('Equity tier limit configuration', async () => {
const response = await client.get.getEquityTierLimitConfiguration();
expect(response.equityTierLimitConfig).not.toBeUndefined();
expect(response.equityTierLimitConfig?.shortTermOrderEquityTiers[0].limit).toBe(0);
});
});
});
8 changes: 8 additions & 0 deletions v4-client-js/examples/validator_get_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ async function test(): Promise<void> {
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const equityTierLimitConfiguration = await client.get.getEquityTierLimitConfiguration();
console.log('Equity Tier Limit Configuration');
console.log(JSON.stringify(equityTierLimitConfiguration));
} catch (error) {
console.log(JSON.stringify(error.message));
}
}

test().then(() => {
Expand Down
18 changes: 9 additions & 9 deletions v4-client-js/package-lock.json

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

4 changes: 2 additions & 2 deletions v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client",
"version": "0.27.18",
"version": "0.28.0",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@cosmjs/tendermint-rpc": "^0.30.1",
"@dydxprotocol/dydxjs": "^0.2.0",
"@dydxprotocol/dydxjs": "^0.3.0",
"@osmonauts/lcd": "^0.6.0",
"@scure/bip32": "^1.1.5",
"@scure/bip39": "^1.1.1",
Expand Down
15 changes: 15 additions & 0 deletions v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@ import { BroadcastOptions } from './types';
export * from '../lib/constants';

// Chain ID
export const DEV_CHAIN_ID = 'dydxprotocol-testnet';
export const STAGING_CHAIN_ID = 'dydxprotocol-testnet';
export const TESTNET_CHAIN_ID = 'dydx-testnet-2';

// ------------ API URLs ------------
export enum IndexerApiHost {
DEV = 'https://indexer.v4dev.dydx.exchange',
STAGING = 'https://indexer.v4staging.dydx.exchange',
TESTNET = 'https://indexer.v4testnet2.dydx.exchange',
// TODO: Add MAINNET
}

export enum IndexerWSHost {
DEV = 'wss://indexer.v4dev.dydx.exchange/v4/ws',
STAGING = 'wss://indexer.v4staging.dydx.exchange/v4/ws',
TESTNET = 'wss://indexer.v4testnet2.dydx.exchange/v4/ws',
// TODO: Add MAINNET
}

export enum FaucetApiHost {
DEV = 'https://faucet.v4dev.expotrading.com',
STAGING = 'https://faucet.v4staging.dydx.exchange',
TESTNET = 'https://faucet.v4testnet2.dydx.exchange',
}

export enum ValidatorApiHost {
DEV = 'https://validator.v4dev.dydx.exchange',
STAGING = 'https://validator.v4staging.dydx.exchange',
TESTNET = 'https://validator.v4testnet2.dydx.exchange',
// TODO: Add MAINNET
Expand All @@ -36,6 +41,7 @@ export enum ValidatorApiHost {
// ------------ Network IDs ------------

export enum NetworkId {
DEV = 'dydxprotocol-testnet',
STAGING = 'dydxprotocol-testnet',
TESTNET = 'dydx-testnet-2',
// TODO: Add MAINNET
Expand Down Expand Up @@ -163,6 +169,15 @@ export class Network {
public validatorConfig: ValidatorConfig,
) {}

static dev(): Network {
const indexerConfig = new IndexerConfig(
IndexerApiHost.DEV,
IndexerWSHost.DEV,
);
const validatorConfig = new ValidatorConfig(ValidatorApiHost.DEV, DEV_CHAIN_ID);
return new Network('dev', indexerConfig, validatorConfig);
}

static staging(): Network {
const indexerConfig = new IndexerConfig(
IndexerApiHost.STAGING,
Expand Down
18 changes: 18 additions & 0 deletions v4-client-js/src/clients/modules/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ export class Get {
return accountFromAny(rawAccount);
}

/**
* @description Get equity tier limit configuration.
*
* @returns Information on all equity tiers that are configured.
*/
async getEquityTierLimitConfiguration(
): Promise<ClobModule.QueryEquityTierLimitConfigurationResponse> {
const requestData: Uint8Array = Uint8Array.from(
ClobModule.QueryEquityTierLimitConfigurationRequest.encode({}).finish(),
);

const data: Uint8Array = await this.sendQuery(
'/dydxprotocol.clob.Query/EquityTierLimitConfiguration',
requestData,
);
return ClobModule.QueryEquityTierLimitConfigurationResponse.decode(data);
}

private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
return this.stargateQueryClient.queryUnverified(requestUrl, requestData);
}
Expand Down

0 comments on commit 424f349

Please sign in to comment.