Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Dec 10, 2024
1 parent be28d4b commit b66d561
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
21 changes: 12 additions & 9 deletions projects/access-protocol/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const { CentralStateV2, ACCESS_PROGRAM_ID } = require("@accessprotocol/js");
const { getConnection } = require("../helper/solana");
const { getMultipleAccounts, decodeAccount } = require("../helper/solana");
const { PublicKey } = require("@solana/web3.js");

async function staking() {
const connection = getConnection();
const [centralKey] = CentralStateV2.getKey(ACCESS_PROGRAM_ID);
const centralState = await CentralStateV2.retrieve(connection, centralKey);
return {
[`solana:${centralState.tokenMint.toString()}`]: Number(centralState.totalStaked.toString())
}
async function staking(api) {
const programId = new PublicKey('6HW8dXjtiTGkD4jzXs7igdFmZExPpmwUrRN5195xGup')
const accountKey = getKey(programId);
const [account] = await getMultipleAccounts([accountKey]);
const decoded = decodeAccount('access', account);
api.add(decoded.tokenMint.toBase58(), decoded.totalStaked);
}

const getKey = (address) => {
return PublicKey.findProgramAddressSync([address.toBuffer()], address)[0].toBase58();
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion projects/helper/utils/solana/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { parsePhoenix } = require('./layouts/phoenix-dex')
const { RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM, RAYDIUM_STABLE_STATE_LAYOUT_V1, } = require('./layouts/raydium-layout')
const { INVESTIN_FUND_DATA, } = require('./layouts/investin-layout')
const { MARKET_STATE_LAYOUT_V3, OPEN_ORDERS_LAYOUT_V2, MARKET_STATE_LAYOUT_V3_MINIMAL } = require('./layouts/openbook-layout')
const { ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout, PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, } = require('./layouts/mixed-layout');
const { ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout, PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, ACCESS_LAYOUT, } = require('./layouts/mixed-layout');
const { SCN_STAKE_POOL, TOKEN_LAYOUT, } = require("./layouts/scnSOL");
const { SANCTUM_INFINITY } = require("./layouts/sanctum-infinity-layout");
const { parseSanctumLstStateList } = require("./layouts/sanctum-validators-lsts-layout");
Expand Down Expand Up @@ -65,6 +65,7 @@ const customDecoders = {
stakePool: defaultParseLayout(STAKE_POOL_LAYOUT),
hhParlay: defaultParseLayout(PARLAY_LAYOUT_PARTIAL),
hhPari: defaultParseLayout(HH_PARI_LAYOUT_PARTIAL),
access: defaultParseLayout(ACCESS_LAYOUT),
}

function decodeAccount(layout, accountInfo) {
Expand Down
28 changes: 27 additions & 1 deletion projects/helper/utils/solana/layouts/mixed-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,34 @@ const HH_PARI_LAYOUT_PARTIAL = BufferLayout.struct([
BufferLayout.seq(u64(), u8().span, 'amounts'),
]);

const ACCESS_LAYOUT = BufferLayout.struct([
BufferLayout.u8('tag'),
BufferLayout.u8('bumpSeed'),
uint64('dailyInflation'),
publicKey('tokenMint'),
publicKey('authority'),
uint64('creationTime'),
uint64('totalStaked'),
uint64('totalStakedSnapshot'),
uint64('lastSnapshotOffset'),
uint128('ixGate'),
publicKey('freezeAuthority'),
uint128('adminIxGate'),
BufferLayout.u16('feeBasisPoints'),
uint64('lastFeeDistributionTime'),
BufferLayout.u32('feeRecipientsCount'),
BufferLayout.seq(
BufferLayout.struct([
publicKey('owner'),
uint64('percentage'),
]),
10,
'recipients'
),
]);

module.exports = {
ReserveLayout, ReserveLayoutLarix, MintLayout, AccountLayout, TokenSwapLayout, ESOLStakePoolLayout,
PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL,
PARLAY_LAYOUT_PARTIAL, HH_PARI_LAYOUT_PARTIAL, ACCESS_LAYOUT
}

0 comments on commit b66d561

Please sign in to comment.