Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 26, 2024
1 parent ecb9fa7 commit 18c9c71
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions staking/app/scripts/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import * as fs from "fs";
import Papa from "papaparse";
import dotenv from "dotenv";
import BN from "bn.js";
dotenv.config();

const RPC_URL = process.env.ENDPOINT!;
Expand All @@ -20,7 +21,7 @@ const RPC_URL = process.env.ENDPOINT!;
// We get around this by using the base64+ztsd encoding instead of base64 that @solana/web3.js uses
async function getAllStakeAccounts(
url: string
): Promise<{ publicKey: PublicKey; data: string }> {
): Promise<{ publicKey: PublicKey; data: string }[]> {
const response = await axios({
method: "post",
url: url,
Expand Down Expand Up @@ -104,15 +105,17 @@ async function main() {
const stakeAccounts = await getAllStakeAccounts(RPC_URL);
const profileAccounts = await getAllProfileAccounts(RPC_URL);

const stakers: { owner: PublicKey; stakedAmount: string }[] =
stakeAccounts.map((x, index) => {
const stakers: { owner: PublicKey; stakedAmount: BN }[] = stakeAccounts.map(
(x, index) => {
console.log("Processing staker :", index);
const buffer = Buffer.from(x.data, "base64");
const accountData = ZstdStream.decompress(new Uint8Array(buffer));
const accountData = ZstdStream.decompress(
new Uint8Array(Buffer.from(x.data, "base64"))
);
return stakeConnection.getStakerAndAmountFromPositionAccountData(
Buffer.from(accountData)
);
});
}
);

const stakersWithProfile = stakers.map(({ owner, stakedAmount }, index) => {
console.log("Processing profile :", index);
Expand All @@ -127,9 +130,12 @@ async function main() {
identity = profileConnection.getIdentityFromProfileAccountData(
Buffer.from(accountData)
);
return { solana: owner, stakedAmount, evm: identity };
}
return { solana: owner, stakedAmount, evm: "" };
return {
solana: owner,
stakedAmount: stakedAmount.toString(),
evm: identity,
};
});

fs.writeFileSync(
Expand Down

0 comments on commit 18c9c71

Please sign in to comment.