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

add function for get rewards params #24

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3,890 changes: 3,816 additions & 74 deletions v4-client-js/__native__/__ios__/v4-native-client.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions v4-client-js/__native__/__ios__/v4-native-client.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions v4-client-js/examples/validator_get_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ async function test(): Promise<void> {
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const rewardsParams = await client.get.getRewardsParams();
console.log('Rewards Params');
console.log(JSON.stringify(rewardsParams));
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const delegationsParams = await client.get.getDelegatorDelegations(DYDX_TEST_ADDRESS);
console.log('Rewards Params');
console.log(JSON.stringify(delegationsParams));
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const unbondingDelegationsParams = await client
.get.getDelegatorUnbondingDelegations(DYDX_TEST_ADDRESS);
console.log('Rewards Params');
console.log(JSON.stringify(unbondingDelegationsParams));
} catch (error) {
console.log(JSON.stringify(error.message));
}
}

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

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

2 changes: 1 addition & 1 deletion v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client-js",
"version": "0.33.1",
"version": "0.33.2",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export const MAX_MEMO_CHARACTERS: number = 256;
// Querying
export const PAGE_REQUEST: PageRequest = {
key: new Uint8Array(),
offset: new Long(0),
limit: new Long(-1),
offset: Long.UZERO,
limit: Long.MAX_UNSIGNED_VALUE,
countTotal: true,
reverse: false,
};
Expand Down
65 changes: 65 additions & 0 deletions v4-client-js/src/clients/modules/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
FeeTierModule,
PerpetualsModule,
PricesModule,
RewardsModule,
SubaccountsModule,
StakingModule,
StatsModule,
} from './proto-includes';
import { TendermintClient } from './tendermintClient';
Expand Down Expand Up @@ -194,6 +196,23 @@ export class Get {
return SubaccountsModule.QuerySubaccountResponse.decode(data);
}

/**
* @description Get the params for the rewards module.
*
* @returns Params for the rewards module.
*/
async getRewardsParams(): Promise<RewardsModule.QueryParamsResponse> {
const requestData = Uint8Array.from(
RewardsModule.QueryParamsRequest.encode({}).finish(),
);

const data: Uint8Array = await this.sendQuery(
'/dydxprotocol.rewards.Query/Params',
requestData,
);
return RewardsModule.QueryParamsResponse.decode(data);
}

/**
* @description Get all Clob Pairs.
*
Expand Down Expand Up @@ -341,6 +360,52 @@ export class Get {
return ClobModule.QueryEquityTierLimitConfigurationResponse.decode(data);
}

/**
*
* @description Get all delegations from a delegator.
*
* @returns All delegations from a delegator.
*/
async getDelegatorDelegations(
delegatorAddr: string,
): Promise<StakingModule.QueryDelegatorDelegationsResponse> {
const requestData = Uint8Array.from(
StakingModule.QueryDelegatorDelegationsRequest.encode({
delegatorAddr,
pagination: PAGE_REQUEST,
}).finish(),
);

const data: Uint8Array = await this.sendQuery(
'/cosmos.staking.v1beta1.Query/DelegatorDelegations',
requestData,
);
return StakingModule.QueryDelegatorDelegationsResponse.decode(data);
}

/**
*
* @description Get all unbonding delegations from a delegator.
*
* @returns All unbonding delegations from a delegator.
*/
async getDelegatorUnbondingDelegations(
delegatorAddr: string,
): Promise<StakingModule.QueryDelegatorUnbondingDelegationsResponse> {
const requestData = Uint8Array.from(
StakingModule.QueryDelegatorUnbondingDelegationsRequest.encode({
delegatorAddr,
pagination: PAGE_REQUEST,
}).finish(),
);

const data: Uint8Array = await this.sendQuery(
'/cosmos.staking.v1beta1.Query/DelegatorUnbondingDelegations',
requestData,
);
return StakingModule.QueryDelegatorUnbondingDelegationsResponse.decode(data);
}

private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
return this.stargateQueryClient.queryUnverified(requestUrl, requestData);
}
Expand Down
2 changes: 2 additions & 0 deletions v4-client-js/src/clients/modules/proto-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export * as SubaccountsModule
from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query';
export * as FeeTierModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/feetiers/query';
export * as StatsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query';
export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rewards/query';
export * as StakingModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/query';

export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
Expand Down
45 changes: 45 additions & 0 deletions v4-client-js/src/clients/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,48 @@ export async function getOptimalIndexer(endpointUrlsAsJson: string): Promise<str
return wrappedError(error);
}
}

export async function getRewardsParams(): Promise<string> {
try {
const client = globalThis.client;
if (client === undefined) {
throw new UserError('client is not connected. Call connectClient() first');
}
const rewardsParams = await globalThis.client?.validatorClient.get.getRewardsParams();
return encodeJson(rewardsParams);
} catch (e) {
return wrappedError(e);
}
}

export async function getDelegatorDelegations(
delegatorAddress: string,
): Promise<string> {
try {
const client = globalThis.client;
if (client === undefined) {
throw new UserError('client is not connected. Call connectClient() first');
}
const delegations = await globalThis
.client?.validatorClient.get.getDelegatorDelegations(delegatorAddress);
return encodeJson(delegations);
} catch (e) {
return wrappedError(e);
}
}

export async function getDelegatorUnbondingDelegations(
delegatorAddress: string,
): Promise<string> {
try {
const client = globalThis.client;
if (client === undefined) {
throw new UserError('client is not connected. Call connectClient() first');
}
const delegations = await globalThis
.client?.validatorClient.get.getDelegatorUnbondingDelegations(delegatorAddress);
return encodeJson(delegations);
} catch (e) {
return wrappedError(e);
}
}