Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat: agave v2 rpc: replace getStakeActivation with rpc-client-exte…
Browse files Browse the repository at this point in the history
…nsion
  • Loading branch information
buffalojoec committed Nov 18, 2024
1 parent f6255b3 commit a6ad79a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"test:unit": "cross-env NODE_ENV=test NODE_OPTIONS='--import tsx' mocha './test/**/*.test.ts'"
},
"dependencies": {
"@anza-xyz/solana-rpc-get-stake-activation": "^1.0.1",
"@babel/runtime": "^7.25.0",
"@noble/curves": "^1.4.2",
"@noble/hashes": "^1.4.0",
Expand Down Expand Up @@ -122,9 +123,9 @@
"sinon": "^19.0.2",
"sinon-chai": "^4.0.0",
"start-server-and-test": "^2.0.4",
"typescript": "^5.5.4",
"tslib": "^2.6.3",
"tsx": "^4.16.2",
"typedoc": "^0.26.5"
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
40 changes: 39 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 15 additions & 33 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import type {Struct} from 'superstruct';
import RpcClient from 'jayson/lib/client/browser';
import {JSONRPCError} from 'jayson';
import {getStakeActivation} from '@anza-xyz/solana-rpc-get-stake-activation';

import {EpochSchedule} from './epoch-schedule';
import {SendTransactionError, SolanaJSONRPCError} from './errors';
Expand Down Expand Up @@ -1968,20 +1969,6 @@ const KeyedParsedAccountInfoResult = pick({
account: ParsedAccountInfoResult,
});

/**
* @internal
*/
const StakeActivationResult = pick({
state: union([
literal('active'),
literal('inactive'),
literal('activating'),
literal('deactivating'),
]),
active: number(),
inactive: number(),
});

/**
* Expected JSON RPC response for the "getConfirmedSignaturesForAddress2" message
*/
Expand Down Expand Up @@ -3692,27 +3679,22 @@ export class Connection {
commitmentOrConfig?: Commitment | GetStakeActivationConfig,
epoch?: number,
): Promise<StakeActivationData> {
const {commitment, config} =
extractCommitmentFromConfig(commitmentOrConfig);
const args = this._buildArgs(
[publicKey.toBase58()],
commitment,
undefined /* encoding */,
{
...config,
epoch: epoch != null ? epoch : config?.epoch,
},
);

const unsafeRes = await this._rpcRequest('getStakeActivation', args);
const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
if ('error' in res) {
throw new SolanaJSONRPCError(
res.error,
`failed to get Stake Activation ${publicKey.toBase58()}`,
if (epoch) {
throw new Error(
'The capability to fetch stake activation for a specific `epoch` is not longer offered by the network.',
);
}
return res.result;

const {status, active, inactive} = await getStakeActivation(
this,
publicKey,
);

return {
state: status as StakeActivationData['state'],
active: Number(active),
inactive: Number(inactive),
};
}

/**
Expand Down

0 comments on commit a6ad79a

Please sign in to comment.