Skip to content

Commit 3b49e8a

Browse files
authored
refactor(experimental): tighten up types (#1540)
1 parent 2a5c909 commit 3b49e8a

File tree

6 files changed

+10
-60
lines changed

6 files changed

+10
-60
lines changed

packages/rpc-core/src/rpc-methods/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export type AccountInfoWithPubkey<TAccount extends AccountInfoBase> = Readonly<{
9393
pubkey: Base58EncodedAddress;
9494
}>;
9595

96-
type TokenAmount = Readonly<{
96+
export type TokenAmount = Readonly<{
9797
amount: StringifiedBigInt;
9898
decimals: number;
9999
uiAmount: number | null;

packages/rpc-core/src/rpc-methods/getTokenAccountBalance.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import { Base58EncodedAddress } from '@solana/addresses';
22

3-
import { Commitment, RpcResponse } from './common';
3+
import { Commitment, RpcResponse, TokenAmount } from './common';
44

5-
type GetTokenAccountBalanceApiResponse = RpcResponse<{
6-
/** The raw balance without decimals, a string representation of u64 */
7-
amount: string;
8-
/** Number of base 10 digits to the right of the decimal place */
9-
decimals: number;
10-
/** @deprecated The balance, using mint-prescribed decimals */
11-
uiAmount: number | null;
12-
/** The balance as a string, using mint-prescribed decimals */
13-
uiAmountString: string;
14-
}>;
5+
type GetTokenAccountBalanceApiResponse = RpcResponse<TokenAmount>;
156

167
export interface GetTokenAccountBalanceApi {
178
/**

packages/rpc-core/src/rpc-methods/getTokenLargestAccounts.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import { Base58EncodedAddress } from '@solana/addresses';
22

3-
import { StringifiedBigInt } from '../stringified-bigint';
4-
import { Commitment, RpcResponse } from './common';
3+
import { Commitment, RpcResponse, TokenAmount } from './common';
54

6-
type GetTokenLargestAccountsApiResponse = RpcResponse<
7-
{
8-
/** the address of the token account */
9-
address: Base58EncodedAddress;
10-
/** the raw token account balance without decimals, a string representation of u64 */
11-
amount: StringifiedBigInt;
12-
/** number of base 10 digits to the right of the decimal place */
13-
decimals: number;
14-
/**
15-
* the token account balance, using mint-prescribed decimals
16-
* @deprecated
17-
*/
18-
uiAmount: number | null;
19-
/** the token account balance as a string, using mint-prescribed decimals */
20-
uiAmountString: string;
21-
}[]
22-
>;
5+
type GetTokenLargestAccountsApiResponse = RpcResponse<TokenAmount & { address: Base58EncodedAddress }[]>;
236

247
export interface GetTokenLargestAccountsApi {
258
/**

packages/rpc-core/src/rpc-methods/getTokenSupply.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import { Base58EncodedAddress } from '@solana/addresses';
22

3-
import { Commitment, RpcResponse } from './common';
3+
import { Commitment, RpcResponse, TokenAmount } from './common';
44

5-
type GetTokenSupplyApiResponse = RpcResponse<{
6-
/**
7-
* The raw total token supply without decimals,
8-
* a string representation of u64
9-
*/
10-
amount: string;
11-
/** Number of base 10 digits to the right of the decimal place */
12-
decimals: number;
13-
/** @deprecated The total token supply, using mint-prescribed decimals */
14-
uiAmount: number | null;
15-
/** The total token supply as a string, using mint-prescribed decimals */
16-
uiAmountString: string;
17-
}>;
5+
type GetTokenSupplyApiResponse = RpcResponse<TokenAmount>;
186

197
export interface GetTokenSupplyApi {
208
/**

packages/rpc-core/src/rpc-methods/getTransaction.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Base58EncodedAddress } from '@solana/addresses';
22
import { Blockhash, TransactionVersion } from '@solana/transactions';
33

4-
import { StringifiedBigInt } from '../stringified-bigint';
54
import { TransactionError } from '../transaction-error';
65
import { UnixTimestamp } from '../unix-timestamp';
76
import {
@@ -11,6 +10,7 @@ import {
1110
Commitment,
1211
LamportsUnsafeBeyond2Pow53Minus1,
1312
Slot,
13+
TokenAmount,
1414
U64UnsafeBeyond2Pow53Minus1,
1515
} from './common';
1616

@@ -23,19 +23,7 @@ type TokenBalance = Readonly<{
2323
owner?: Base58EncodedAddress;
2424
/** Pubkey of the Token program that owns the account. */
2525
programId?: Base58EncodedAddress;
26-
uiTokenAmount: {
27-
/** Raw amount of tokens as a string, ignoring decimals. */
28-
amount: StringifiedBigInt;
29-
/** Number of decimals configured for token's mint. */
30-
decimals: number;
31-
/**
32-
* Token amount as a float, accounting for decimals.
33-
* @deprecated
34-
*/
35-
uiAmount: number | null;
36-
/** Token amount as a string, accounting for decimals. */
37-
uiAmountString: string;
38-
};
26+
uiTokenAmount: TokenAmount;
3927
}>;
4028

4129
type TransactionRewardBase = Readonly<{

packages/rpc-core/src/rpc-methods/getVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type GetVersionApiResponse = Readonly<{
22
/** Unique identifier of the current software's feature set */
3-
'feature-set': number;
3+
'feature-set': number; // `u32`
44
/** Software version of `solana-core` */
55
'solana-core': string;
66
}>;

0 commit comments

Comments
 (0)