Skip to content

Commit

Permalink
chore(types): correct return types
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 16, 2024
1 parent 76acb19 commit cc949e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
19 changes: 15 additions & 4 deletions packages/orchestration/src/cosmos-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { AnyJson, TypedJson, JsonSafe } from '@agoric/cosmic-proto';
import type {
Delegation,
DelegationResponse,
Redelegation,
RedelegationResponse,
UnbondingDelegation,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
import type { TxBody } from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
Expand All @@ -26,6 +28,7 @@ import type {
LocalIbcAddress,
RemoteIbcAddress,
} from '@agoric/vats/tools/ibc-utils.js';
import type { QueryDelegationTotalRewardsResponse } from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/query.js';
import type { AmountArg, ChainAddress, Denom, DenomAmount } from './types.js';

/** An address for a validator on some blockchain, e.g., cosmos, eth, etc. */
Expand Down Expand Up @@ -97,6 +100,12 @@ export type CosmosChainInfo = Readonly<{
stakingTokens?: Readonly<Array<{ denom: string }>>;
}>;

/** @see {QueryDelegationTotalRewardsResponse} */
export interface OrchestrationQueryDelegationTotalRewardsResponse {
rewards: { validatorAddress: string; reward: DenomAmount[] }[];
total: DenomAmount[];
}

/**
* Queries for the staking properties of an account.
*
Expand All @@ -107,13 +116,15 @@ export interface StakingAccountQueries {
/**
* @returns all active delegations from the account to any validator (or [] if none)
*/
getDelegations: () => Promise<Delegation[]>;
getDelegations: () => Promise<DelegationResponse[]>;

/**
* @returns the active delegation from the account to a specific validator. Return an
* empty Delegation if there is no delegation.
*/
getDelegation: (validator: CosmosValidatorAddress) => Promise<Delegation>;
getDelegation: (
validator: CosmosValidatorAddress,
) => Promise<DelegationResponse>;

/**
* @returns the unbonding delegations from the account to any validator (or [] if none)
Expand All @@ -127,13 +138,13 @@ export interface StakingAccountQueries {
validator: CosmosValidatorAddress,
) => Promise<UnbondingDelegation>;

getRedelegations: () => Promise<Redelegation[]>;
getRedelegations: () => Promise<RedelegationResponse[]>;

/**
* Get the pending rewards for the account.
* @returns the amounts of the account's rewards pending from all validators
*/
getRewards: () => Promise<DenomAmount[]>;
getRewards: () => Promise<OrchestrationQueryDelegationTotalRewardsResponse>;

/**
* Get the rewards pending with a specific validator.
Expand Down
44 changes: 23 additions & 21 deletions packages/orchestration/src/exos/cosmos-orchestration-account.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/** @file Use-object for the owner of a staking account */
import { toRequestQueryJson } from '@agoric/cosmic-proto';
import {
QueryBalanceRequest,
QueryBalanceResponse,
QueryAllBalancesRequest,
QueryAllBalancesResponse,
QueryBalanceRequest,
QueryBalanceResponse,
} from '@agoric/cosmic-proto/cosmos/bank/v1beta1/query.js';
import { MsgSend } from '@agoric/cosmic-proto/cosmos/bank/v1beta1/tx.js';
import {
QueryDelegationRewardsRequest,
QueryDelegationRewardsResponse,
QueryDelegationTotalRewardsRequest,
QueryDelegationTotalRewardsResponse,
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/query.js';
import {
MsgWithdrawDelegatorReward,
MsgWithdrawDelegatorRewardResponse,
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/tx.js';
import {
MsgBeginRedelegate,
MsgDelegate,
MsgUndelegate,
MsgUndelegateResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import {
QueryDelegationRequest,
QueryDelegatorDelegationsRequest,
QueryUnbondingDelegationRequest,
QueryDelegatorUnbondingDelegationsRequest,
QueryRedelegationsRequest,
QueryDelegationResponse,
QueryDelegatorDelegationsRequest,
QueryDelegatorDelegationsResponse,
QueryUnbondingDelegationResponse,
QueryDelegatorUnbondingDelegationsRequest,
QueryDelegatorUnbondingDelegationsResponse,
QueryRedelegationsRequest,
QueryRedelegationsResponse,
QueryUnbondingDelegationRequest,
QueryUnbondingDelegationResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/query.js';
import {
QueryDelegationRewardsRequest,
QueryDelegationTotalRewardsRequest,
QueryDelegationRewardsResponse,
QueryDelegationTotalRewardsResponse,
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/query.js';
MsgBeginRedelegate,
MsgDelegate,
MsgUndelegate,
MsgUndelegateResponse,
} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js';
import { MsgTransfer } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
import { makeTracer } from '@agoric/internal';
Expand All @@ -54,19 +54,19 @@ import {
import { coerceCoin, coerceDenom } from '../utils/amounts.js';
import {
maxClockSkew,
tryDecodeResponse,
toDenomAmount,
tryDecodeResponse,
} from '../utils/cosmos.js';
import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js';
import { makeTimestampHelper } from '../utils/time.js';

/**
* @import {HostOf} from '@agoric/async-flow';
* @import {AmountArg, IcaAccount, ChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, StakingAccountQueries, OrchestrationAccountI, IBCConnectionInfo, IBCMsgTransferOptions, ChainHub} from '../types.js';
* @import {AmountArg, IcaAccount, ChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, StakingAccountQueries, OrchestrationAccountI, OrchestrationQueryDelegationTotalRewardsResponse, IBCConnectionInfo, IBCMsgTransferOptions, ChainHub} from '../types.js';
* @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js';
* @import {Coin} from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js';
* @import {Delegation} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
* @import {Remote} from '@agoric/internal';
* @import {DelegationResponse} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
* @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js';
* @import {TimerService} from '@agoric/time';
* @import {Vow, VowTools} from '@agoric/vow';
Expand Down Expand Up @@ -365,6 +365,7 @@ export const prepareCosmosOrchestrationAccountKit = (
delegationsQueryWatcher: {
/**
* @param {JsonSafe<ResponseQuery>[]} results
* @returns {DelegationResponse[]}
*/
onFulfilled([result]) {
if (!result?.key) throw Fail`Error parsing result ${result}`;
Expand Down Expand Up @@ -447,6 +448,7 @@ export const prepareCosmosOrchestrationAccountKit = (
rewardsQueryWatcher: {
/**
* @param {JsonSafe<ResponseQuery>[]} results
* @returns {OrchestrationQueryDelegationTotalRewardsResponse}
*/
onFulfilled([result]) {
if (!result?.key) throw Fail`Error parsing result ${result}`;
Expand Down

0 comments on commit cc949e6

Please sign in to comment.