Skip to content

Commit

Permalink
Add Access Protocol TVL functionality and refactor code (DefiLlama#12652
Browse files Browse the repository at this point in the history
)

Co-authored-by: Vladislav Matus <[email protected]>
  • Loading branch information
2 people authored and twothirtyfive committed Dec 11, 2024
1 parent 1bd7a4f commit e0d9675
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
24 changes: 24 additions & 0 deletions projects/access-protocol/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { getMultipleAccounts, decodeAccount } = require("../helper/solana");
const { PublicKey } = require("@solana/web3.js");

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 = {
timetravel: false,
methodology:
"Uses the Access Protocol SDK to fetch the total supply of staked ACS tokens",
solana: {
tvl: async () => ({}),
staking,
},
};
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 e0d9675

Please sign in to comment.