From 509a7e9164b2219d11a972a7ac1d5e753ccda125 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 15 Jul 2020 16:25:13 +0200 Subject: [PATCH] sdk38: Add distribution module to LCD --- packages/sdk38/src/lcdapi/distribution.ts | 99 +++++++++++++++++++ packages/sdk38/types/lcdapi/distribution.d.ts | 68 +++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 packages/sdk38/src/lcdapi/distribution.ts create mode 100644 packages/sdk38/types/lcdapi/distribution.d.ts diff --git a/packages/sdk38/src/lcdapi/distribution.ts b/packages/sdk38/src/lcdapi/distribution.ts new file mode 100644 index 00000000..36efd792 --- /dev/null +++ b/packages/sdk38/src/lcdapi/distribution.ts @@ -0,0 +1,99 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { Coin } from "../coins"; +import { LcdClient } from "./lcdclient"; + +export interface RewardContainer { + readonly validator_address: string; + readonly reward: readonly Coin[] | null; +} + +export interface DistributionDelegatorRewardsResponse { + readonly height: string; + readonly result: { + readonly rewards: readonly RewardContainer[] | null; + readonly total: readonly Coin[] | null; + }; +} + +export interface DistributionDelegatorRewardResponse { + readonly height: string; + readonly result: readonly Coin[]; +} + +export interface DistributionWithdrawAddressResponse { + readonly height: string; + readonly result: string; +} + +export interface DistributionValidatorResponse { + readonly height: string; + readonly result: { + readonly operator_address: string; + readonly self_bond_rewards: readonly Coin[]; + readonly val_commission: readonly Coin[]; + }; +} + +export interface DistributionValidatorRewardsResponse { + readonly height: string; + readonly result: readonly Coin[]; +} + +export interface DistributionValidatorOutstandingRewardsResponse { + readonly height: string; + readonly result: readonly Coin[]; +} + +export interface DistributionParametersResponse { + readonly height: string; + readonly result: { + readonly community_tax: string; + readonly base_proposer_reward: string; + readonly bonus_proposer_reward: string; + readonly withdraw_addr_enabled: boolean; + }; +} + +export interface DistributionCommunityPoolResponse { + readonly height: string; + readonly result: readonly Coin[]; +} + +export interface DistributionExtension { + readonly distribution: { + readonly delegatorRewards: (delegatorAddress: string) => Promise; + readonly delegatorReward: ( + delegatorAddress: string, + validatorAddress: string, + ) => Promise; + readonly withdrawAddress: (delegatorAddress: string) => Promise; + readonly validator: (validatorAddress: string) => Promise; + readonly validatorRewards: (validatorAddress: string) => Promise; + readonly validatorOutstandingRewards: ( + validatorAddress: string, + ) => Promise; + + readonly parameters: () => Promise; + readonly communityPool: () => Promise; + }; +} + +export function setupDistributionExtension(base: LcdClient): DistributionExtension { + return { + distribution: { + delegatorRewards: async (delegatorAddress: string) => + base.get(`/distribution/delegators/${delegatorAddress}/rewards`), + delegatorReward: async (delegatorAddress: string, validatorAddress: string) => + base.get(`/distribution/delegators/${delegatorAddress}/rewards/${validatorAddress}`), + withdrawAddress: async (delegatorAddress: string) => + base.get(`/distribution/delegators/${delegatorAddress}/withdraw_address`), + validator: async (validatorAddress: string) => base.get(`/distribution/validators/${validatorAddress}`), + validatorRewards: async (validatorAddress: string) => + base.get(`/distribution/validators/${validatorAddress}/rewards`), + validatorOutstandingRewards: async (validatorAddress: string) => + base.get(`/distribution/validators/${validatorAddress}/outstanding_rewards`), + parameters: async () => base.get(`/distribution/parameters`), + communityPool: async () => base.get(`/distribution/community_pool`), + }, + }; +} diff --git a/packages/sdk38/types/lcdapi/distribution.d.ts b/packages/sdk38/types/lcdapi/distribution.d.ts new file mode 100644 index 00000000..59789b17 --- /dev/null +++ b/packages/sdk38/types/lcdapi/distribution.d.ts @@ -0,0 +1,68 @@ +import { Coin } from "../coins"; +import { LcdClient } from "./lcdclient"; +export interface RewardContainer { + readonly validator_address: string; + readonly reward: readonly Coin[] | null; +} +export interface DistributionDelegatorRewardsResponse { + readonly height: string; + readonly result: { + readonly rewards: readonly RewardContainer[] | null; + readonly total: readonly Coin[] | null; + }; +} +export interface DistributionDelegatorRewardResponse { + readonly height: string; + readonly result: readonly Coin[]; +} +export interface DistributionWithdrawAddressResponse { + readonly height: string; + readonly result: string; +} +export interface DistributionValidatorResponse { + readonly height: string; + readonly result: { + readonly operator_address: string; + readonly self_bond_rewards: readonly Coin[]; + readonly val_commission: readonly Coin[]; + }; +} +export interface DistributionValidatorRewardsResponse { + readonly height: string; + readonly result: readonly Coin[]; +} +export interface DistributionValidatorOutstandingRewardsResponse { + readonly height: string; + readonly result: readonly Coin[]; +} +export interface DistributionParametersResponse { + readonly height: string; + readonly result: { + readonly community_tax: string; + readonly base_proposer_reward: string; + readonly bonus_proposer_reward: string; + readonly withdraw_addr_enabled: boolean; + }; +} +export interface DistributionCommunityPoolResponse { + readonly height: string; + readonly result: readonly Coin[]; +} +export interface DistributionExtension { + readonly distribution: { + readonly delegatorRewards: (delegatorAddress: string) => Promise; + readonly delegatorReward: ( + delegatorAddress: string, + validatorAddress: string, + ) => Promise; + readonly withdrawAddress: (delegatorAddress: string) => Promise; + readonly validator: (validatorAddress: string) => Promise; + readonly validatorRewards: (validatorAddress: string) => Promise; + readonly validatorOutstandingRewards: ( + validatorAddress: string, + ) => Promise; + readonly parameters: () => Promise; + readonly communityPool: () => Promise; + }; +} +export declare function setupDistributionExtension(base: LcdClient): DistributionExtension;