From f1724456a3e6d9b1107b4792caa8055afb237178 Mon Sep 17 00:00:00 2001
From: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com>
Date: Wed, 8 May 2024 10:02:46 -0700
Subject: [PATCH] [GraphQL] (#17577)
## Description
Deprecates the ` exchange_rates` and `staking_pool` resolvers on
validator type, and adds a `staking_pool_id` and `exchange_rates_table`
resolver to correctly return the staking pool id and the wrapped
exchange rates object.
## Test plan
Existing tests:
```
cd sui-graphql-e2e-tests && cargo nextest run --features pg_integration
```
---
## Release notes
Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.
For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.
- [ ] Protocol:
- [ ] Nodes (Validators and Full nodes):
- [ ] Indexer:
- [ ] JSON-RPC:
- [x] GraphQL: Deprecated the ` exchange_rates` and `staking_pool`
resolvers on validator type, and added a `staking_pool_id` and
`exchange_rates_table` resolver to correctly return the staking pool id
and the wrapped exchange rates object.
- [ ] CLI:
- [ ] Rust SDK:
---
.../schema/current_progress_schema.graphql | 14 +++++-
crates/sui-graphql-rpc/src/types/validator.rs | 50 +++++++++++--------
.../snapshot_tests__schema_sdl_export.snap | 14 +++++-
3 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/crates/sui-graphql-rpc/schema/current_progress_schema.graphql b/crates/sui-graphql-rpc/schema/current_progress_schema.graphql
index 53231289fb429..6224a32e3be5c 100644
--- a/crates/sui-graphql-rpc/schema/current_progress_schema.graphql
+++ b/crates/sui-graphql-rpc/schema/current_progress_schema.graphql
@@ -3979,12 +3979,22 @@ type Validator {
The validator's current staking pool object, used to track the amount of stake
and to compound staking rewards.
"""
- stakingPool: MoveObject
+ stakingPool: MoveObject @deprecated(reason: "The staking pool is a wrapped object. Access its fields directly on the `Validator` type.")
+ """
+ The ID of this validator's `0x3::staking_pool::StakingPool`.
+ """
+ stakingPoolId: SuiAddress!
"""
The validator's current exchange object. The exchange rate is used to determine
the amount of SUI tokens that each past SUI staker can withdraw in the future.
"""
- exchangeRates: MoveObject
+ exchangeRates: MoveObject @deprecated(reason: "The exchange object is a wrapped object. Access its dynamic fields through the `exchangeRatesTable` query.")
+ """
+ A wrapped object containing the validator's exchange rates. This is a table from epoch
+ number to `PoolTokenExchangeRate` value. The exchange rate is used to determine the amount
+ of SUI tokens that each past SUI staker can withdraw in the future.
+ """
+ exchangeRatesTable: Owner
"""
Number of exchange rates in the table.
"""
diff --git a/crates/sui-graphql-rpc/src/types/validator.rs b/crates/sui-graphql-rpc/src/types/validator.rs
index de01a9bb10bf2..d3b7584ae23c6 100644
--- a/crates/sui-graphql-rpc/src/types/validator.rs
+++ b/crates/sui-graphql-rpc/src/types/validator.rs
@@ -9,6 +9,7 @@ use async_graphql::connection::{Connection, CursorType, Edge};
use super::big_int::BigInt;
use super::move_object::MoveObject;
use super::object::Object;
+use super::owner::Owner;
use super::sui_address::SuiAddress;
use super::validator_credentials::ValidatorCredentials;
use super::{address::Address, base64::Base64};
@@ -106,26 +107,37 @@ impl Validator {
/// The validator's current staking pool object, used to track the amount of stake
/// and to compound staking rewards.
- async fn staking_pool(&self, ctx: &Context<'_>) -> Result