Last active
January 9, 2025 10:11
-
-
Save ochaloup/9a89b42623069b4c8fee224f38eec875 to your computer and use it in GitHub Desktop.
Solana search for VoteAccount - by validator identity (node_pubkey) and StakeAcccount - by staker/withdrawer/voter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Changing name: | |
https://stackoverflow.com/questions/19896900/how-to-change-the-name-of-a-gist-in-github/62398008#62398008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solana stake accounts | |
# https://github.com/solana-labs/solana/blob/v1.17.15/sdk/program/src/stake/state.rs#L60 | |
# https://github.com/solana-labs/solana/blob/v1.17.15/sdk/program/src/stake/state.rs#L414 | |
# program id address | |
# https://github.com/solana-labs/solana-web3.js/blob/b533af38a46a409b79831c82874d954f11b71810/packages/library-legacy/src/programs/stake.ts#L597C6-L597C49 | |
STAKER_OFFSET=12 # 4 for enum, 8 rent exempt reserve | |
WITHDRAWER_OFFSET=44 # 4 + 8 + staker pubkey | |
VOTER_OFFSET=124 # 4 for enum + 120 for Meta | |
# STAKER=... | |
STAKER=7cgg6KhPd1G8oaoB48RyPDWu7uZs51jUpDYB3eq4VebH # bonds | |
# WITHDRAWER=... | |
WITHDRAWER=7cgg6KhPd1G8oaoB48RyPDWu7uZs51jUpDYB3eq4VebH # bonds | |
VOTER=... | |
# RPC_URL='...' | |
curl $RPC_URL -X POST -H "Content-Type: application/json" -d ' | |
{ | |
"jsonrpc": "2.0", | |
"id": 1, | |
"method": "getProgramAccounts", | |
"params": [ | |
"Stake11111111111111111111111111111111111111", | |
{ | |
"encoding": "base64", | |
"dataSlice": { | |
"offset": 0, | |
"length": 0 | |
}, | |
"filters": [ | |
{ | |
"memcmp": { | |
"offset": '$STAKER_OFFSET', | |
"bytes": "'$STAKER'" | |
} | |
}, | |
{ | |
"memcmp": { | |
"offset": '$WITHDRAWER_OFFSET', | |
"bytes": "'$WITHDRAWER'" | |
} | |
}, | |
{ | |
"memcmp": { | |
"offset": '$VOTER_OFFSET', | |
"bytes": "'$VOTER'" | |
} | |
} | |
] | |
} | |
] | |
}' | jq '.' | tee /tmp/stake-accounts.json | |
for I in `grep 'pubkey' /tmp/stake-accounts.json | sed 's/.*": "//' | sed 's/"//'`; do | |
solana -u$RPC_URL show-stake-account $I | |
done | |
# On note of the returned data and Rewards Season 2 of marinade | |
# ------------------------------------------------------------- | |
> | |
> {"jsonrpc":"2.0","result":[{"account":{"data":["","base64"],"executable":false,"lamports":16730547915,"owner":"Vote111111111111111111111111111111111111111","rentEpoch":18446744073709551615,"space":3762},"pubkey":"9esjPxaUdD7yg4yDrBkP3jLipcAGVjpLDXsddF89avzW"}],"id":1} | |
> | |
# Marinade Rewards season 2 (api works with VoteAccount, Claim records are provided to validator identity) | |
curl https://native-staking-referral.marinade.finance/v1/rewards/all/season-2?pubkey=9esjPxaUdD7yg4yDrBkP3jLipcAGVjpLDXsddF89avzW | |
> | |
> {"pubkey":"A4fxKaaNPBCaMwqKyhHxoWKJ5ybgvmmwTQmNmGtt2aoC","ratePerSecondPerSol":"64","updatedAt":"2024-04-10T07:41:24.191Z","staker":{"mSOLBalance":"0","mSOLRewards":"0","nativeStakeBalance":"0","nativeStakeRewards":"0"},"validator":{"algoScoreBalance":"0","algoScoreRewards":"0"},"governor":{"latestSolPerDirectedVemnde":"0.01269298154541449","pubkey":"A4fxKaaNPBCaMwqKyhHxoWKJ5ybgvmmwTQmNmGtt2aoC","vemndeDirectedStakeVotesBalance":"0","vemndeDirectedStakeVotesRewards":"0"}} | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STAKER_OFFSET=12 # 4 for enum, 8 rent exempt reserve | |
NATIVE="stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq" | |
# RPC_URL='...' | |
curl $RPC_URL -X POST -H "Content-Type: application/json" -d ' | |
{ | |
"jsonrpc": "2.0", | |
"id": 1, | |
"method": "getProgramAccounts", | |
"params": [ | |
"Stake11111111111111111111111111111111111111", | |
{ | |
"encoding": "base64", | |
"dataSlice": { | |
"offset": 0, | |
"length": 0 | |
}, | |
"filters": [ | |
{ | |
"memcmp": { | |
"offset": '$STAKER_OFFSET', | |
"bytes": "'$NATIVE'" | |
} | |
} | |
] | |
} | |
] | |
} | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solana VoteAccount state | |
# https://github.com/solana-labs/solana/blob/v1.17.10/sdk/program/src/vote/state/mod.rs#L285 | |
# export RPC_URL='...' | |
# first 4 bytes are of type | |
# https://github.com/marinade-finance/validator-bonds/blob/15a9b42a5feae4dd7c3d6b83ffbbabb122961a13/programs/validator-bonds/src/checks.rs#L32 | |
# node id, vote account node_id, validator pukey, validator identity | |
export VALIDATOR_IDENTITY="A4fxKaaNPBCaMwqKyhHxoWKJ5ybgvmmwTQmNmGtt2aoC" | |
curl $RPC_URL -X POST -H "Content-Type: application/json" -d ' | |
{ | |
"jsonrpc": "2.0", | |
"id": 1, | |
"method": "getProgramAccounts", | |
"params": [ | |
"Vote111111111111111111111111111111111111111", | |
{ | |
"encoding": "base64", | |
"dataSlice": { | |
"offset": 0, | |
"length": 0 | |
}, | |
"filters": [ | |
{ | |
"memcmp": { | |
"offset": 4, | |
"bytes": "'$VALIDATOR_IDENTITY'" | |
} | |
} | |
] | |
} | |
] | |
} | |
' | |
> | |
> {"jsonrpc":"2.0","result":[{"account":{"data":["","base64"],"executable":false,"lamports":16730547915,"owner":"Vote111111111111111111111111111111111111111","rentEpoch":18446744073709551615,"space":3762},"pubkey":"9esjPxaUdD7yg4yDrBkP3jLipcAGVjpLDXsddF89avzW"}],"id":1} | |
> | |
# Marinade Rewards season 2 (api works with VoteAccount, Claim records are provided to validator identity) | |
curl https://native-staking-referral.marinade.finance/v1/rewards/all/season-2?pubkey=9esjPxaUdD7yg4yDrBkP3jLipcAGVjpLDXsddF89avzW | |
> | |
> {"pubkey":"A4fxKaaNPBCaMwqKyhHxoWKJ5ybgvmmwTQmNmGtt2aoC","ratePerSecondPerSol":"64","updatedAt":"2024-04-10T07:41:24.191Z","staker":{"mSOLBalance":"0","mSOLRewards":"0","nativeStakeBalance":"0","nativeStakeRewards":"0"},"validator":{"algoScoreBalance":"0","algoScoreRewards":"0"},"governor":{"latestSolPerDirectedVemnde":"0.01269298154541449","pubkey":"A4fxKaaNPBCaMwqKyhHxoWKJ5ybgvmmwTQmNmGtt2aoC","vemndeDirectedStakeVotesBalance":"0","vemndeDirectedStakeVotesRewards":"0"}} | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment