-
Notifications
You must be signed in to change notification settings - Fork 208
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
10016 StakingAccountQueries #10069
10016 StakingAccountQueries #10069
Conversation
Deploying agoric-sdk with Cloudflare Pages
|
81a8fec
to
cc949e6
Compare
await osmoAccount.undelegate( | ||
delegations.map(d => ({ | ||
validator: { | ||
chainId: 'osmosis-1', | ||
value: /** @type {`${string}valoper${string}`} */ ( | ||
d.delegation.validatorAddress | ||
), | ||
encoding: 'bech32', | ||
}, | ||
amount: { denom: 'uosmo', value: BigInt(d.balance.amount) }, | ||
})), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the mismatch between the return of getDelegations
and the param of undelegate
is clunky. I'll see about cleaning that up before calling this R4R.
Other feedback welcomed though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 6420537 we moved away from using the Delegation: { validatorAddress, delegatorAddress, shares }
type with undelegate
to better align with the .delegate()
and .redelegate()
.
I think this was the correct decision to better align the API, so I would support seeing us massage to getDelegations: () => { validator: CosmosValidatorAddress, amount: DenomAmount[] }
if that's what you're aiming for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, only critical feedback item is ensure toDenomAmount
doesn't throw when we give it a decimal.
I also assume your view is that LocalOrchAccount
queries are out of scope for this task. I'm fine with this as we don't have any stories that require it, but think we should make a note or task item on #10048
await osmoAccount.undelegate( | ||
delegations.map(d => ({ | ||
validator: { | ||
chainId: 'osmosis-1', | ||
value: /** @type {`${string}valoper${string}`} */ ( | ||
d.delegation.validatorAddress | ||
), | ||
encoding: 'bech32', | ||
}, | ||
amount: { denom: 'uosmo', value: BigInt(d.balance.amount) }, | ||
})), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 6420537 we moved away from using the Delegation: { validatorAddress, delegatorAddress, shares }
type with undelegate
to better align with the .delegate()
and .redelegate()
.
I think this was the correct decision to better align the API, so I would support seeing us massage to getDelegations: () => { validator: CosmosValidatorAddress, amount: DenomAmount[] }
if that's what you're aiming for.
return harden({ | ||
rewards: rewards.map(reward => ({ | ||
validatorAddress: reward.validatorAddress, | ||
reward: reward.reward.map(toDenomAmount), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we need to add logic to toDenomAmount
to round down to the nearest whole integer? I see that this query returns DecCoin
instead of the typical Coin
.
Alternatively, accounting for decimals with ratios is an option, but I'm not sure it's worth the cost here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I've added tests and helpers for this
@@ -97,6 +100,12 @@ export type CosmosChainInfo = Readonly<{ | |||
stakingTokens?: Readonly<Array<{ denom: string }>>; | |||
}>; | |||
|
|||
/** @see {QueryDelegationTotalRewardsResponse} */ | |||
export interface OrchestrationQueryDelegationTotalRewardsResponse { | |||
rewards: { validatorAddress: string; reward: DenomAmount[] }[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nb: Consider
rewards: { validatorAddress: string; reward: DenomAmount[] }[]; | |
rewards: { validator: CosmosValidatorAddress; amount: DenomAmount[] }[]; |
for consistency, although we don't need this response for withdrawReward
or withdrawRewards
|
||
/** | ||
* 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>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what OrchestrationQueryDelegationTotalRewardsResponse
computes to, but consider a shorter name. I recognize something like DelegationTotalRewards
or DelegationRewards
might look too much like a cosmic-proto
type, but I would prefer the brevity at this expense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gonna try CosmosGetRewardsResponse
. Pattern being: "Cosmos" to convey that it's part of cosmos-api and it's clearly not part one of the protobuf types because they don't need to say that. Middle is the method name ("getRewards") and "Response" is because it's the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, all the queries start with get
and Response
implies a query so maybe CosmosRewardsResponse
.
balance: { denom: 'uatom', amount: '1000000' }, | ||
}, | ||
], | ||
pagination: { nextKey: new Uint8Array(), total: 1n }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we handle/support pagination? Not sure it's worth the cost atm, but curious what it looks like. Maybe it's as simple as exposing a nextKey
as an optional param in getDelegations()
and the other interfaces that support it.
@@ -0,0 +1,153 @@ | |||
/* eslint-env node */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! (entire file 🙂)
There's no query that returns a single Redelegation
886fb0a
to
c006436
Compare
closes: #10016
Description
Implements the
StakingAccountQueries
. Except forgetRedelegation
because there is no query that's guaranteed to return one. It's a strict subset of what's returned bygetRedelegations
. If there are ever use cases in which that payload is too large we can optimize then.This also massages the return types in cosmos-api.ts to more closely match what is returned by the Cosmos query endpoints. (No longer dropping data.)
Security Considerations
The queries are read-only. Like any query there is a risk of resource exhaustion. These aren't rate limited but since they run in a vat the malicious code would exhaust itself. The risks of exhausting the RPC server are no greater than any off-chain query.
Scaling Considerations
May benefit from some load testing in production-ish environment to see what the service can handle.
Documentation Considerations
The interface is already documented. This implements it so nothing changes (other than the return types, as mentioned above)
Testing Considerations
New tests
Upgrade Considerations
No vats yet use this code.